SavedModel模型转换.om模型
简介
本章节主要介绍如何使用saved_model2om.py工具将训练保存的SavedModel格式的模型重新构图,转换为基于NPU版本用于加载om模型的SavedModel模型,在部署TF Serving时使用转换后的SavedModel模型可以缩短编译时间从而提升TF Serving部署性能。

使用.om格式的模型进行在线推理时,不支持精度比对中Data Dump功能。
参数说明
参数 |
参数说明 |
取值示例 |
---|---|---|
--input_path |
|
/home/HwHiAiUser/inputpath/model |
--output_path |
|
/home/HwHiAiUser/outputpath/model |
--input_shape |
|
input:16,224,224,3 |
--soc_version |
|
Ascendxxx |
--profiling |
|
1 |
--method_name |
|
/tensorflow/serving/predict |
--new_input_nodes |
|
embedding:DT_FLOAT:bert/embedding/word_embeddings:0;add:DT_INT:bert/embedding/add:0 |
--new_output_nodes |
|
loss:loss/Softmax:0 |
--output_type |
node1:0:FP16 |
|
--input_fp16_nodes |
node_name1;node_name2 |

该工具同时支持ATC和AOE工具中的参数:
该工具暂不支持ATC和AOE工具中的--out_nodes、--is_input_adjust_hw_layout和--is_output_adjust_hw_layout参数,其中--out_nodes参数可使用表1 参数说明中的--new_output_nodes参数进行代替。
执行转换
- 下载转换工具“saved_model2om.py”至服务器的任一目录,例如上传到$HOME/tools/目录下,无需安装。
- 执行以下命令进行转换,具体参数请根据实际修改。
python3 saved_model2om.py --input_path "/home/HwHiAiUser/inputpath/model" --output_path "/home/HwHiAiUser/outputpath/model" --input_shape "input:16,224,224,3" --soc_version "Ascendxxx"
--soc_version的取值查询方式:- 在安装昇腾AI处理器的服务器执行npu-smi info命令进行查询,获取Chip Name信息。实际配置值为AscendChip Name,例如Chip Name取值为xxxyy,实际配置值为Ascendxxxyy。
如果在转换的过程中需要进行子图或者算子调优,请执行以下命令。
python3 saved_model2om.py --input_path "/home/HwHiAiUser/inputpath/model" --output_path "/home/HwHiAiUser/outputpath/model" --input_shape "input:16,224,224,3" --profiling "1"
- 转换成功后,会在指定的output_path下生成用于加载om模型的SavedModel模型文件,文件名格式为{om_name}_load_om_saved_model_{timestamp}。