-
-
Notifications
You must be signed in to change notification settings - Fork 522
Closed
Description
建议将ppocr_keys, rec_img_shape等信息直接存储到onnx模型
目前, ppocr_keys是单独存放在txt文件, 然后在config.yaml中配置文件路径; rec_img_shape是在config.yaml中配置
这两个参数是和onnx模型强相关的, 可以直接作为元数据存储到onnx模型内, 减少配置的需求.
尤其是ppocr_keys, 目前通过另一个文件来分发, 容易出现两边不一致的情况.
ONNX本身支持自定义元信息的存储. 使用这种方式, 部署相关的配置应该会更简单.
参考代码:
# 添加meta信息
import onnx
model = onnx.load_model('/path/to/model.onnx')
meta = model.metadata_props.add()
meta.key = 'dictionary'
meta.value = open('/path/to/ppocr_keys_v1.txt', 'r', -1, 'u8').read()
meta = model.metadata_props.add()
meta.key = 'shape'
meta.value = '[3,48,320]'
onnx.save_model(model, '/path/to/model.onnx')
# 获取meta信息
import json
import onnxruntime as ort
sess = ort.InferenceSession('/path/to/model.onnx')
metamap = sess.get_modelmeta().custom_metadata_map
chars = metamap['dictionary'].splitlines()
input_shape = json.loads(metamap['shape'])Metadata
Metadata
Assignees
Labels
No labels