我遇到这样的错误。请让我知道如何在此代码中加载图像。
def prepare(filepath):
IMG_SIZE = 70 # 50 in txt-based
img_array = cv2.imread(filepath, cv2.IMREAD_GRAYSCALE)
new_array = cv2.resize(img_array, (IMG_SIZE, IMG_SIZE))
return new_array.reshape(-1, IMG_SIZE, IMG_SIZE, 1)
model = tf.keras.models.load_model("64x3-CNN.model")
prediction = model.predict([prepare('doggo.jpg')])
print(prediction) # will be a list in a list.
print(CATEGORIES[int(prediction[0][0])])
错误:
ValueError Traceback (most recent call last) <ipython-input-1-1d42891fac0e>
in <module> 14 model = tf.keras.models.load_model("cnn") 15 ---> 16
prediction = model.predict([prepare('ct.jpg')]) 17 print(prediction) # will
be a list in a list. 18 print(CATEGORIES[int(prediction[0][0])]) ValueError:
Error when checking input: expected conv2d_9_input to have shape (100,100,1)
but got array with shape (70, 70, 1)
答案 0 :(得分:0)
我找到了答案。错误是由于图片大小
IMG_SIZE = 100 # 50 in txt-based