<小米開源框架MACE> 創(chuàng)建模型部署文件

文章內(nèi)容翻譯自 MACE 官方手冊,記錄本人閱讀與開發(fā)過程,力求不失原意,但推薦閱讀原文。
https://media.readthedocs.org/pdf/mace/latest/mace.pdf
Github地址:https://github.com/xiaomi/mace

聲明:如有侵權(quán),請聯(lián)系作者刪除

創(chuàng)建模型部署文件

部署 MACE 模型的第一步是創(chuàng)建一個(gè) YAML 模型部署文件。

文件描述了模型的部署情況,每個(gè)文件會(huì)生成一個(gè)靜態(tài)庫(如果指定了多個(gè)ABI類型,則每一個(gè)均會(huì)生成對應(yīng)的靜態(tài)庫)。部署文件可以包含一個(gè)或多個(gè)模型,例如,一個(gè)智能相機(jī)應(yīng)用可能包含人臉識(shí)別、物體識(shí)別、語音識(shí)別模型,這些都可以定義在一個(gè)部署文件中。

范例

下面是一個(gè) Android 演示程序的部署文件例子。

# The name of library
library_name: mobilenet
target_abis: [arm64-v8a]
embed_model_data: 1
# The build mode for model(s).
# 'code' stand for transfer model(s) into cpp code, 'proto' for model(s) in protobuf file(s).
build_type: code
linkshared: 0
# One yaml config file can contain multi models' config message.
models:
  mobilenet_v1: # model tag, which will be used in model loading and must be specific.
    platform: tensorflow
    # support local path, http:// and https://
    model_file_path: https://cnbj1.fds.api.xiaomi.com/mace/miai-models/mobilenet-v1/mobilenet-v1-1.0.pb
    model_sha256_checksum: 71b10f540ece33c49a7b51f5d4095fc9bd78ce46ebf0300487b2ee23d71294e6
    subgraphs:
      - input_tensors: input
        input_shapes: 1,224,224,3
        output_tensors: MobilenetV1/Predictions/Reshape_1
        output_shapes: 1,1001
    runtime: cpu+gpu
    limit_opencl_kernel_time: 0
    nnlib_graph_mode: 0
    obfuscate: 0
    winograd: 0
  mobilenet_v2:
    platform: tensorflow
    model_file_path: https://cnbj1.fds.api.xiaomi.com/mace/miai-models/mobilenet-v2/mobilenet-v2-1.0.pb
    model_sha256_checksum: 369f9a5f38f3c15b4311c1c84c032ce868da9f371b5f78c13d3ea3c537389bb4
    subgraphs:
      - input_tensors: input
        input_shapes: 1,224,224,3
        output_tensors: MobilenetV2/Predictions/Reshape_1
        output_shapes: 1,1001
    runtime: cpu+gpu
    limit_opencl_kernel_time: 0
    nnlib_graph_mode: 0
    obfuscate: 0
    winograd: 0

配置

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 [optional] 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.
linkshared [optional] Use dynamic linking for libmace library when setting to 1, or static linking when setting to 0, default to 0.
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 [optional] The path of the model weights file, used by Caffe model.
weight_sha256_checksum [optional] 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.
input_ranges The numerical range of the input tensors, default [-1, 1]. It is only for test.
validation_inputs_data [optional] Specify Numpy validation inputs. When not provided, [-1, 1] random values will be used.
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.
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,554評(píng)論 19 139
  • 1、通過CocoaPods安裝項(xiàng)目名稱項(xiàng)目信息 AFNetworking網(wǎng)絡(luò)請求組件 FMDB本地?cái)?shù)據(jù)庫組件 SD...
    陽明AI閱讀 16,203評(píng)論 3 119
  • # Python 資源大全中文版 我想很多程序員應(yīng)該記得 GitHub 上有一個(gè) Awesome - XXX 系列...
    aimaile閱讀 26,835評(píng)論 6 427
  • # Python 資源大全中文版 我想很多程序員應(yīng)該記得 GitHub 上有一個(gè) Awesome - XXX 系列...
    小邁克閱讀 3,124評(píng)論 1 3
  • 文/踏雪尋梅 當(dāng)?shù)谝豢|晨曦穿過山坡上的濃密的林子,希望的曙光穿透灰蒙蒙的山谷時(shí),在山谷溫暖的懷抱里,沉睡一夜的村莊...
    a694fde23415閱讀 503評(píng)論 2 1

友情鏈接更多精彩內(nèi)容