Keras单图像预测不适用于正确的暗淡

时间:2018-10-05 16:20:15

标签: keras

我想使用功能性API(keras版本2.2.2,tensorflow后端v1.7)预测单个图像。我加载了模型:

# Loading Model
base_model = VGG16(include_top = False,  weights=None,
              input_shape=(224,224,3))
x = base_model.output
x = GlobalAveragePooling2D()(x)
x = Dropout(0.7)(x)
x = Dense(1020, activation='relu')(x)
predictions = Dense(1, activation='sigmoid')(x)
model = Model(inputs=base_model.input, outputs=predictions)

model.load_weights("model.h5")

然后我加载图像并将其转换为输入格式,然后尝试预测:

from keras.preprocessing.image import img_to_array, load_img
img = load_img("data/my_image.png")  # this is a PIL image
array = img_to_array(img)  # this is a Numpy array with shape 
arrayresized = cv2.resize(array, (244,244))*1./255 
inputarray = np.expand_dims(arrayresized, axis=0)

# Predicting
prediction = model.predict(inputarray, batch_size = 1)

然后我得到此错误:

ValueError: Error when checking input: expected input_4 to have shape 
(224, 224, 3) but got array with shape (244, 244, 3)

0 个答案:

没有答案