【发布时间】:2020-01-02 11:59:50
【问题描述】:
我已经使用暗网训练了我的 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
有什么想法会出错吗? 非常感谢
【问题讨论】:
标签: tensorflow keras deep-learning yolo coremltools