我试图在iOS应用程序中使用Apple提供的Squeezenet ML模型 . 当我传递图像进行分类时,预测就会消失 . 我怀疑问题是由于提供给Squeezenet进行分类的图像的典型预处理尚未在iOS应用程序中实现 . 特别是,在Python中实现时,图像需要以下预处理步骤:
model = SqueezeNet()
img = image.load_img('cat.jpeg', target_size=(227, 227))
x = image.img_to_array(img) #Preprocess Step 1
x = np.expand_dims(x, axis=0) #Preprocess Step 2
x = preprocess_input(x) #Preprocess Step 3
preds = model.predict(x)
print('Predicted:', decode_predictions(preds))
有谁知道如何在iOS中重新创建这三个预处理步骤?
Update following comment from Matthijs:
Matthijs,我已经看过你的博客文章,并了解执行相同预处理的必要性 . 我已经对提交给模型的图像的代码进行了更改,并且获得了更好的结果 . 但是,我仍然不清楚我的博客文章是否正在由模型处理预处理,或者我传递给Apple Squeezenet模型的图像数据的格式是否不正确 .
例如,以下是Python中Squeezenet与我在应用程序中从Apple的Squeezenet模式获得的一些比较结果(除非另有说明,否则两个模型都正确地对图像进行分类):
Image Confidence value
Samoyed dog 0.899 (Python model with preprocess_input applied)
Samoyed dog 0.994 (Python model without preprocess_input applied)
Samoyed dog 0.837 (Apple model)
Beagle dog 0.962 (Python model with preprocess_input applied)
Beagle dog 0.975 (Python model without preprocess_input applied)
Beagle dog* 0.626 (Apple model)
* Apple model incorrectly classified as Labrador Retriever
Tabby cat 0.863 (Python model with preprocess_input applied)
Tabby cat 0.986 (Python model without preprocess_input applied)
Tabby cat 0.995 (Apple model)
有关这是一个预处理问题还是其他问题的任何想法?可能是提交给模型的图像格式不正确吗?有没有办法看看CoreML模型执行了哪些预处理步骤(如果有的话)?