将UIImage转换为适用于Keras模型的MLMultiArray [英] Converting UIImage to MLMultiArray for Keras Model
问题描述
在Python中,我使用keras训练了一个图像分类模型,以接收作为[224,224,3]数组的输入并输出预测(1或0)。当我加载保存模型并将其加载到xcode时,它声明输入必须是MLMultiArray格式。
In Python, I trained an image classification model with keras to receive input as a [224, 224, 3] array and output a prediction (1 or 0). When I load the save the model and load it into xcode, it states that the input has to be in MLMultiArray format.
我有没有办法转换UIImage进入MLMultiArray格式?或者有没有办法让我改变我的keras模型接受CVPixelBuffer类型对象作为输入。
Is there a way for me to convert a UIImage into MLMultiArray format? Or is there a way for me change my keras model to accept CVPixelBuffer type objects as an input.
推荐答案
在你的Core ML转换中脚本您可以提供参数 image_input_names ='data'
其中 data
是您输入的名称。
In your Core ML conversion script you can supply the parameter image_input_names='data'
where data
is the name of your input.
现在,Core ML会将此输入视为图像( CVPixelBuffer
),而不是多数组。
Now Core ML will treat this input as an image (CVPixelBuffer
) instead of a multi-array.
这篇关于将UIImage转换为适用于Keras模型的MLMultiArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!