Created
October 4, 2018 21:47
-
-
Save apivovarov/db3275344b013678fc1cb9e187aecfae to your computer and use it in GitHub Desktop.
TVM compile code for resnet50_v1 for ARMv7 Mali GPU
This file contains 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
#!/usr/bin/env python3 | |
import nnvm | |
import nnvm.testing | |
import tvm | |
import numpy as np | |
from mxnet.gluon.model_zoo.vision import get_model | |
batch_size = 1 | |
image_shape = (3, 224, 224) | |
data_shape = (batch_size,) + image_shape | |
output_file_name="model-cl" | |
model_name = 'resnet50_v1' | |
block = get_model(model_name, pretrained=True) | |
sym, params = nnvm.frontend.from_mxnet(block) | |
# we want a probability so add a softmax operator | |
sym = nnvm.sym.softmax(sym) | |
opt_level = 3 | |
#target = 'llvm' | |
#target = 'llvm -target=armv7l-linux-gnueabihf' | |
#target = tvm.target.intel_graphics() | |
#target = tvm.target.cuda() | |
#target = tvm.target.arm_cpu('rasp3b') | |
target = tvm.target.mali() | |
#target_host = None | |
target_host = 'llvm -target=armv7l-linux-gnueabihf' | |
print('model_name: ', model_name, ', target:', target, ', target_host: ', target_host, ', opt_level:', opt_level, ', data_shape:', data_shape) | |
print("Compiling...") | |
#from tvm.autotvm.measure.measure_methods import set_cuda_target_arch | |
#set_cuda_target_arch('sm_62') | |
with nnvm.compiler.build_config(opt_level=opt_level): | |
graph, lib, params = nnvm.compiler.build(sym, target=target, shape={"data": data_shape}, params=params, target_host=target_host) | |
print("Compilation done") | |
print("Saving files") | |
# save the graph, lib and params into separate files | |
path_lib = output_file_name + ".tar" | |
lib.export_library(path_lib) | |
with open(output_file_name + ".json", "w") as fo: | |
fo.write(graph.json()) | |
with open(output_file_name + ".params", "wb") as fo: | |
fo.write(nnvm.compiler.save_param_dict(params)) | |
print("Files saved") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment