Create a model deployment file¶
The first step to deploy you models is to create a YAML model deployment file.
One deployment file describes a case of model deployment, each file will generate one static library (if more than one ABIs specified, there will be one static library for each). The deployment file can contains one or more models, for example, a smart camera application may contains face recognition, object recognition, and voice recognition models, which can be defined in one deployment file),
Example¶
Here is an deployment file example used by Android demo application.
TODO: change this example file to the demo deployment file (reuse the same file) and rename to a reasonable name.
# 库的名字
library_name: library_name
# 配置文件名会被用作生成库的名称:libmace-${library_name}.a
target_abis: [armeabi-v7a, arm64-v8a]
# 具体机型的soc编号,可以使用`adb shell getprop | grep ro.board.platform | cut -d [ -f3 | cut -d ] -f1`获取
target_socs: [msm8998]
embed_model_data: 1
build_type: code # 模型build类型。code表示将模型转为代码,proto表示将模型转为protobuf文件
models: # 一个配置文件可以包含多个模型的配置信息,最终生成的库中包含多个模型
model_name: # 模型的标签,在调度模型的时候,会用这个变量,必须唯一
platform: tensorflow
model_file_path: path/to/model64.pb # also support http:// and https://
model_sha256_checksum: 7f7462333406e7dea87222737590ebb7d94490194d2f21a7d72bafa87e64e9f9
subgraphs:
- input_tensors: input_node
input_shapes: 1,64,64,3
output_tensors: output_node
output_shapes: 1,64,64,2
runtime: gpu
data_type: fp16_fp32
limit_opencl_kernel_time: 0
nnlib_graph_mode: 0
obfuscate: 1
winograd: 0
input_files:
- path/to/input_files # support http://
second_net:
platform: caffe
model_file_path: path/to/model.prototxt
weight_file_path: path/to/weight.caffemodel
model_sha256_checksum: 05d92625809dc9edd6484882335c48c043397aed450a168d75eb8b538e86881a
weight_sha256_checksum: 05d92625809dc9edd6484882335c48c043397aed450a168d75eb8b538e86881a
subgraphs:
- input_tensors:
- input_node0
- input_node1
input_shapes:
- 1,256,256,3
- 1,128,128,3
output_tensors:
- output_node0
- output_node1
output_shapes:
- 1,256,256,2
- 1,1,1,2
runtime: cpu
limit_opencl_kernel_time: 1
nnlib_graph_mode: 0
obfuscate: 1
winograd: 0
input_files:
- path/to/input_files # support http://
Configurations¶
library_name | library name |
---|---|
target_abis | The target ABI to build, can be one or more of 'host', 'armeabi-v7a' or 'arm64-v8a' |
target_socs | build for specified socs if you just want use the model for that socs. |
embed_model_data | Whether embedding model weights as the code, default to 0 |
build_type | model build type, can be ['proto', 'code']. 'proto' for converting model to ProtoBuf file and 'code' for converting model to c++ code. |
model_name | model name. should be unique if there are multiple models. LIMIT: if build_type is code, model_name will used in c++ code so that model_name must fulfill c++ name specification. |
platform | The source framework, one of [tensorflow, caffe] |
model_file_path | The path of the model file, can be local or remote |
model_sha256_checksum | The SHA256 checksum of the model file |
weight_file_path | The path of the model weights file, used by Caffe model |
weight_sha256_checksum | The SHA256 checksum of the weight file, used by Caffe model |
subgraphs | subgraphs key. ** DO NOT EDIT ** |
input_tensors | The input tensor names (tensorflow), top name of inputs' layer (caffe). one or more strings |
output_tensors | The output tensor names (tensorflow), top name of outputs' layer (caffe). one or more strings |
input_shapes | The shapes of the input tensors, in NHWC order |
output_shapes | The shapes of the output tensors, in NHWC order |
runtime | The running device, one of [cpu, gpu, dsp, cpu_gpu]. cpu_gpu contains cpu and gpu model definition so you can run the model on both cpu and gpu. |
data_type | [optional] The data type used for specified runtime. [fp16_fp32, fp32_fp32] for gpu, default is fp16_fp32. [fp32] for cpu. [uint8] for dsp. |
limit_opencl_kernel_time | [optional] Whether splitting the OpenCL kernel within 1 ms to keep UI responsiveness, default to 0 |
nnlib_graph_mode | [optional] Control the DSP precision and performance, default to 0 usually works for most cases |
obfuscate | [optional] Whether to obfuscate the model operator name, default to 0 |
winograd | [optional] Whether to enable Winograd convolution, will increase memory consumption |
input_files | [optional] Specify Numpy validation inputs. When not provided, [-1, 1] random values will be used |