coreml - 如何将 Core ML 模型文件转换为其他格式,以便它可以在服务器上运行
问题描述
训练了一个 Core ML 模型 (.mlmodel),但我发现它只能在 MacOS 上运行。(但我想在 Linux 服务器上运行它)
我试图将其转换为 ONNX 格式,但失败了。
onnxmltools
并使用以下python代码进行转换:
import onnxmltools
import coremltools
# Load a Core ML model
coreml_model = coremltools.utils.load_spec('example.mlmodel')
# Convert the Core ML model into ONNX
onnx_model = onnxmltools.convert_coreml(coreml_model, 'Example Model')
# Save as protobuf
onnxmltools.utils.save_model(onnx_model, 'example.onnx')
但是运行上面的程序后显示以下错误消息
Traceback (most recent call last):
File "convertToOnnx.py", line 8, in <module>
onnx_model = onnxmltools.convert_coreml(coreml_model, 'Post Rating Model')
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/onnxmltools/convert/main.py", line 18, in convert_coreml
custom_conversion_functions, custom_shape_calculators)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/onnxmltools/convert/coreml/convert.py", line 60, in convert
topology = parse_coreml(spec, initial_types, target_opset, custom_conversion_functions, custom_shape_calculators)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/onnxmltools/convert/coreml/_parse.py", line 467, in parse_coreml
topology.compile()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/onnxconverter_common/topology.py", line 632, in compile
self._infer_all_types()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/onnxconverter_common/topology.py", line 508, in _infer_all_types
operator.infer_types()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/onnxconverter_common/topology.py", line 110, in infer_types
registration.get_shape_calculator(self.type)(self)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/onnxmltools/convert/coreml/shape_calculators/OneHotEncoder.py", line 36, in calculate_one_hot_encoder_output_shapes
raise ValueError('Categorical indexes are missing')
ValueError: Categorical indexes are missing
如何解决上述错误?或者如何在 Linux 服务器上使用 Core ML 模型?(任何其他的模型转换方式?)
解决方案
推荐阅读
- matrix - 关于 fortran 函数 MATMUL() 行为的问题
- java - 如何在 Java 数据模型类中具有动态数据类型变量?
- python - 如何在运行时检查每条指令后发生的情况?
- sql - 从返回值中过滤掉一行
- codeigniter - 尝试使用 codeigniter 的文件上传库作为 Helpers 的通用功能
- routes - 我的 AspNet Core 3.1 身份页面在 IdentityServer4 中给出 404。我怎样才能访问这些?这是路线问题吗?
- angular - Angular 6+ ngcc 无法在 ngx-monaco-editor 上运行
- r - 将日期和时间转换为以十进制小时为单位的经过时间
- python - 为什么这适用于我的字典片段?
- database-design - 将 Liquibase 与雪花一起使用