Hi, I’m working with the android_deploy sample app that uses the three artifact version of a compiled model (.so library, .json graph, .params weights) and the code to load this is available here. Attaching a minimal snippet below:
// load json graph
String modelGraph = null;
String graphFilename = 'modelGraph.json';
modelGraph = new String(getBytesFromFile(assetManager, graphFilename));
// upload tvm compiled function on application cache folder
String libCacheFilePath = null;
String libFilename = 'modelLib.so';
libCacheFilePath = getTempLibFilePath(libFilename);
byte[] modelLibByte = getBytesFromFile(assetManager, libFilename);
FileOutputStream fos = new FileOutputStream(libCacheFilePath);
fos.write(modelLibByte);
fos.close();
// load parameters
byte[] modelParams = null;
String paramFilename = 'modelParams.params';
modelParams = getBytesFromFile(assetManager, paramFilename);
// create java tvm device
Device tvmDev = Device.cpu();
// tvm module for compiled functions
Module modelLib = Module.load(libCacheFilePath);
// get global function module for graph executor
Function runtimeCreFun = Function.getFunction("tvm.graph_executor.create");
TVMValue runtimeCreFunRes = runtimeCreFun.pushArg(modelGraph)
.pushArg(modelLib)
.pushArg(tvmDev.deviceType)
.pushArg(tvmDev.deviceId)
.invoke();
graphExecutorModule = runtimeCreFunRes.asModule();
// get the function from the module(load parameters)
Function loadParamFunc = graphExecutorModule.getFunction("load_params");
loadParamFunc.pushArg(modelParams).invoke();
// release tvm local variables
modelLib.release();
loadParamFunc.release();
runtimeCreFun.release();
TVM is now deprecating this output structure in favor of a single .so
file which contains the graph and weights structures that can be loaded in python as follows:
lib = tvm.runtime.load_module(os.path.join(base, "modelLibrary.so"))
module = tvm.contrib.graph_executor.GraphModule(lib['default'](tvm.cpu()))
Is there an example available to load this kind of combined binary in Android?