tensorflow - ValueError:图像的输入形状无效。在 keras 模型中转换为 core ml
问题描述
我已经用暗网训练了我的 YOLOv3 网络来识别图像中的一些对象。一切正常。我想在 iOS 应用程序中使用权重文件,所以按照一些教程,我从暗网权重文件 ancd 获得了 keras h5 模型,我检查了 h5 模型是否也可以正常工作。好的。最后一步,使用 coremltools 我尝试将 h5 模型转换为可在 xcode 下使用的 coreml 模型。这里我有问题......最后一次转换是用这个小 py 脚本执行的:
import coremltools
....
coreml_model = coremltools.converters.keras.convert('yolorcgz.h5', input_names='image', class_labels=output_labels, image_input_names='image', input_name_shape_dict={'image': [1, 416, 416, 3]})
coreml_model.input_description['image'] = 'Takes a photo'
coreml_model.output_description['output'] = 'Prediction of obj in the photo'
coreml_model.author = 'SW Team'
coreml_model.license = 'Public Domain'
coreml_model.short_description = "YOLOv3 network trained for obj recognition"
coreml_model.save('yolorcgz.mlmodel')
当我运行脚本时,我总是遇到这个错误:
Traceback (most recent call last):
File "coreml.py", line 9, in <module>
coreml_model = coremltools.converters.keras.convert('yolorcgz.h5',input_name_shape_dict={'input1': [1, 416, 416, 3]})
File "/usr/local/lib/python2.7/dist-packages/coremltools/converters/keras/_keras_converter.py", line 760, in convert
custom_conversion_functions=custom_conversion_functions)
File "/usr/local/lib/python2.7/dist-packages/coremltools/converters/keras/_keras_converter.py", line 556, in convertToSpec
custom_objects=custom_objects)
File "/usr/local/lib/python2.7/dist-packages/coremltools/converters/keras/_keras2_converter.py", line 305, in _convert
raise ValueError(errMsg)
ValueError: Invalid input shape for image.
Please provide a finite height (H), width (W) & channel value (C) using input_name_shape_dict arg with key = 'image' and value = [None,H,W,C]
Converted .mlmodel can be modified to have flexible input shape using coremltools.models.neural_network.flexible_shape_utils
关于什么可能出错的任何想法?非常感谢
解决方案
我遇到了同样的问题。input_name_shape_dict={'image': [1, 416, 416, 3]}
我通过更改为来修复它input_name_shape_dict={'image': [None, 416, 416, 3]}
。
我正在使用 Keras 2.3.1 和 Tensorflow 1.14.0,这对我有用。
推荐阅读
- html - 如何在 cshtml 中进行输入验证?
- asp.net-mvc - 类库的实体框架迁移
- powershell - 如何将多个收件人添加到 xml 配置文件并从 PowerShell 脚本向这些收件人发送邮件
- r - Parameterized RMarkdown does not filter parameter in R
- azure - Azure Web 应用 Node.js 部署后返回 404
- regex - 通过 VSCode 中的“查找和替换”删除大括号
- vba - 在 VBA 中以管理员身份运行 Powershell 脚本
- flutter - 我如何纠正 pubspec.yaml 的这个错误?
- blazor-server-side - System.Net.Http.HttpRequestException:响应状态码不表示成功:401(未授权)
- sql - Rails & Postgres 选择 JSONB 列的子键