Skip to content

Instantly share code, notes, and snippets.

@apivovarov
Created October 1, 2018 23:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apivovarov/72a0584f0a47133a96619c69c8a34e77 to your computer and use it in GitHub Desktop.
Save apivovarov/72a0584f0a47133a96619c69c8a34e77 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import nnvm
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
block = get_model('resnet18_v1', pretrained=True)
#block = get_model('squeezenet1.1', 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 = tvm.target.mali()
#target_host = "llvm -target=armv7l-linux-gnueabihf"
print('target:', target, ', opt_level:', opt_level, ', data_shape:', data_shape)
print("Compiling...")
with nnvm.compiler.build_config(opt_level=opt_level):
graph, lib, params = nnvm.compiler.build(sym, target, shape={"data": data_shape}, params=params)
print("Compilation done")
print("Saving files")
# save the graph, lib and params into separate files
path_lib = "model-cl.tar"
lib.export_library(path_lib)
with open("model-cl.json", "w") as fo:
fo.write(graph.json())
with open("model-cl.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