gpt4 book ai didi

python - Input 0 is incompatible with layerfunctional_3 : expected shape=(None, 224, 224, 3), found shape=(None, 240, 240, 3)

转载 作者:行者123 更新时间:2023-12-04 01:09:14 25 4
gpt4 key购买 nike

我是 VGG19 和 python 图像处理的新手。我正在尝试测试我训练的 VGG19 模型来预测图像。我收到此错误:-

ValueError: Input 0 is incompatible with layer functional_3: expected shape=(None, 224, 224, 3), found shape=(None, 240, 240, 3)
我用于预测的 tensorflow 代码是:-
import os
os.environ['CUDA_VISIBLE_DEVICES'] = '-1'
import numpy as np
import cv2
import tensorflow as tf
from tensorflow.keras.models import load_model
model = load_model('VGG19.h5')
CATEGORIES = ["Pneumonia", "Non-Pneumonia"]
img = cv2.imread('person1_bacteria_1.jpeg')
img = cv2.resize(img,(240,240)) # resize image to match model's expected sizing
img = np.reshape(img,[1,240,240,3]) # return the image with shaping that TF wants.
prediction = model.predict(img)
prediction
但在 .ipynb 文件的情况下,我只是收到关于此的警告:-
This the image

最佳答案

您是 resizing to wrong shape .而不是 240,240

img = cv2.resize(img,(240,240))     # resize image to match model's expected sizing
img = img.reshape(1,240,240,3) # return the image with shaping that TF wants.
使用 224,224
img = cv2.resize(img,(224,224))     # resize image to match model's expected sizing
img = img.reshape(1,224,224,3) # return the image with shaping that TF wants.

关于python - Input 0 is incompatible with layerfunctional_3 : expected shape=(None, 224, 224, 3), found shape=(None, 240, 240, 3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65388357/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com