【问题标题】:Testing in convolution neural networks卷积神经网络中的测试
【发布时间】:2019-11-16 06:01:31
【问题描述】:

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

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)

【问题讨论】:

  • 哪里出错了!请告诉我们。

标签: python tensorflow keras


【解决方案1】:

我找到了答案。错误是因为图像大小

  IMG_SIZE = 100 # 50 in txt-based

【讨论】: