模型编译:
#encoding:utf-8
import onnx
import numpy as np
import tvm
import tvm.relay as relay
import os
from tvm.contrib import ndk
onnx_model = onnx.load('mobilenet_v3_small.onnx')
x = np.ones([1,3,224,224])
input_name = 'input1'
shape_dict = {input_name: x.shape}
sym, params = relay.frontend.from_onnx(onnx_model, shape_dict)
target = "opencl -device=adreno"
target_host = "llvm -mtriple=arm64-linux-android"
with tvm.transform.PassContext(opt_level=3):
graph, lib, params = relay.build(sym, target=target, target_host=target_host, params=params)
lib.export_library("deploy.so", cc="/path_to_ndk/26.0.10792818/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android34-clang++")
graph_json_path = "deploy.json"
with open(graph_json_path, 'w') as fo:
fo.write(graph)
param_path = "deploy.params"
with open(param_path, 'wb') as fo:
fo.write(relay.save_param_dict(params))
------------------------------------------------------------