卷积神经网络的测试

2024-06-02 11:02:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我犯了这样的错误。请让我知道如何加载此代码中的图像

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)

Tags: inimgnewinputsizemodel错误prepare