import tensorflow as tf
from tensorflow import keras
from keras.models import load_model
from keras.preprocessing import image
import numpy as np
import cv2
import matplotlib.pyplot as plt
model=tf.keras.models.load_model('model_ex-024_acc-0.996875.h5')
img_array = cv2.imread('30.jpg') # convert to array
img_rgb = cv2.cvtColor(img_array, cv2.COLOR_BGR2RGB)
img_rgb = cv2.resize(img_rgb,(224,224),3)
plt.imshow(img_rgb) # graph it
plt.show()
model.predict(img_rgb)
ValueError: Error when checking input: expected input_1 to have 4 dimensions, but got array with shape (224, 224, 3)
您应该按照模型所期望的那样扩展输入图像维度。你可以用
np.expand_dims
来做。此外,您可能需要缩放图像。你知道吗希望能有帮助。你知道吗
相关问题 更多 >
编程相关推荐