小编Joe*_*Joe的帖子

当使用 OpenCV 完成图像加载和调整大小时,Resnet50 会产生不同的预测

我想使用使用 OpenCV 的 Keras Resnet50 模型来读取和调整输入图像的大小。我正在使用来自 Keras 的相同预处理代码(使用 OpenCV,我需要转换为 RGB,因为这是 preprocess_input() 期望的格式)。我使用 OpenCV 和 Keras 图像加载得到的预测略有不同。我不明白为什么预测不一样。

这是我的代码:

import numpy as np
import json
from tensorflow.keras.applications.resnet50 import ResNet50
from tensorflow.keras.preprocessing import image
from tensorflow.keras.applications.resnet50 import preprocess_input, decode_predictions
import cv2

model = ResNet50(weights='imagenet')

img_path = '/home/me/squirle.jpg'

# Keras prediction
img = image.load_img(img_path, target_size=(224, 224))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
preds = model.predict(x)
print('Predicted Keras:', decode_predictions(preds, top=3)[0])

# OpenCV prediction
imgcv = cv2.imread(img_path)
dim = (224, 224)
imgcv_resized …
Run Code Online (Sandbox Code Playgroud)

python opencv machine-learning keras tensorflow

8
推荐指数
1
解决办法
797
查看次数

标签 统计

keras ×1

machine-learning ×1

opencv ×1

python ×1

tensorflow ×1