2

因为我正在学习 Apple 的 Vision 和 CoreML 框架,但被困在如何使用我自己重新训练的模型上。我尝试根据本教程使用 Keras 训练 VG16 模型。除了一些 Keras 版本警告外,一切看起来都不错。然后我尝试使用以下代码使用 CoreMLTools 转换结果模型

coremlModel = coremltools.converters.keras.convert(
    kmodel,
    input_names = 'image',
    image_input_names = 'image',
    output_names = 'classLabelProbs',
    class_labels = ['cats', 'dogs'],
)

在转换过程中,它给了我一些版本兼容的警告,但否则它是成功的:

WARNING:root:Keras version 2.0.6 detected. Last version known to be fully compatible of Keras is 2.0.4 .
WARNING:root:TensorFlow version 1.2.1 detected. Last version known to be fully compatible is 1.1.1 .

所以我将此模型加载到 Apple 的 Vision+ML 示例代码中,但每次我尝试对图像进行分类时都会失败并出现错误

Vision+ML Example[2090:2012481] Error: The VNCoreMLTransform request failed
Vision+ML Example[2090:2012481] Didn't get VNClassificationObservations 
Error Domain=com.apple.vis Code=3 "The VNCoreMLTransform request failed" UserInfo={NSLocalizedDescription=The VNCoreMLTransform request failed, NSUnderlyingError=0x1c025d130 {Error Domain=com.apple.CoreML Code=0 "Dimensions of layer 'classLabelProbs' is not the same size as the number of class labels." UserInfo={NSLocalizedDescription=Dimensions of layer 'classLabelProbs' is not the same size as the number of class labels.}}}

我猜这是因为预训练的 VGG16 模型已经有 1000 个类别,所以我尝试了 1000 个类别和 1000 + 2 个(猫和狗)类别,但仍然遇到同样的问题。

我错过了什么吗?我将不胜感激任何线索和帮助。

4

0 回答 0