Last active
August 14, 2022 11:38
-
-
Save Lyken17/b54c981717e6e76b79af6bb9e9425208 to your computer and use it in GitHub Desktop.
SNPE Profile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import torch | |
| import torch.nn as nn | |
| import torchvision | |
| from torchvision import models | |
| batch = 1 | |
| dim = 3 | |
| res = 224 | |
| model = models.resnet101(pretrained=False).eval() | |
| model_name = "resnet101_quant" | |
| def remove_bn(module): | |
| module_output = module | |
| if isinstance(module, (nn.BatchNorm2d, nn.Dropout, nn.LayerNorm, nn.Dropout, nn.ReLU, nn.ReLU6)): | |
| module_output = nn.Identity() | |
| for name, child in module.named_children(): | |
| module_output.add_module(name, remove_bn(child)) | |
| del module | |
| return module_output | |
| model = remove_bn(model) | |
| dummy_input = torch.randn(batch, dim, res, res) | |
| torch.onnx.export(model, dummy_input, f"onnx_zoos/{model_name}.onnx", ) | |
| import os | |
| os.system(f"snpe-onnx-to-dlc -i onnx_zoos/{model_name}.onnx -o dlc/{model_name}.dlc") | |
| os.system(f"snpe-dlc-quantize --input_dlc dlc/{model_name}.dlc --output_dlc dlc/{model_name}_quant.dlc --input_list random_inputs/random_raw_list.txt" ) | |
| json_info = { | |
| "Name": f"{model_name}", | |
| "HostRootPath": f"{model_name}", | |
| "HostResultsDir": f"{model_name}/results", | |
| "DevicePath":"/data/local/tmp/snpebm", | |
| "Devices":["LMG820QM89db118f"], | |
| "HostName": "localhost", | |
| "Runs":5, | |
| "Model": { | |
| "Name": f"{model_name}", | |
| "Dlc": f"./dlc/{model_name}_quant.dlc", | |
| "RandomInput": 1 | |
| }, | |
| "Runtimes":["CPU", "GPU", "DSP"], | |
| "Measurements": ["timing"] | |
| } | |
| import json | |
| with open("tmp.json", "w") as fp: | |
| json.dump(json_info, fp) | |
| # /home/<user>/snpe-<version>/benchmarks | |
| os.system("python snpe_bench.py -c tmp.json -json -l moderate") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment