[英]ValueError: Input 0 of layer sequential_3 is incompatible with the layer:
I started studying deep learning a few days ago, so I don't know much about it.我前几天开始学习深度学习,所以对它了解不多。 I followed the practice of CNN model that classifies dogs vs cats using Inception V3.
我遵循 CNN model 的做法,使用 Inception V3 对狗和猫进行分类。 Model training and save are successful and I want to predict whether the picture is a dog or a cat.
Model 训练和保存成功,我想预测图片是狗还是猫。 So I did this, but I keep getting the same error.
所以我这样做了,但我一直收到同样的错误。
ValueError: Input 0 of layer sequential_3 is incompatible with the layer:
expected axis -1 of input shape to have value 2048
but received input with shape [None, 224, 224, 3]
# load and prepare the image
def load_image(filename):
# load the image
img = load_img(filename, target_size=(224, 224))
# convert to array
img = img_to_array(img)
# reshape into a single sample with 3 channels
img = img.reshape(1, 224, 224, 3)
# center pixel data
img = img.astype('float32')
img = img - [123.68, 116.779, 103.939]
return img
# load an image and predict the class
def run_example():
# load the image
img = load_image('sample_image.jpg')
# load model
model = load_model('model_fin.h5')
# predict the class
result = model.predict(img)
print(result[0])
run_example()
extractor = Sequential()
extractor.add(InceptionV3(include_top=False, weights='imagenet', input_shape=IMG_SIZE))
extractor.add(layers.GlobalAveragePooling2D())
extractor_output_shape = extractor.get_output_shape_at(0)[1:]
model = Sequential()
model.add(layers.InputLayer(input_shape=extractor_output_shape))
model.add(layers.Dense(2, activation='sigmoid'))
model.summary()
I tried so hard to solve this problem but I couldn't find the cause.我非常努力地解决这个问题,但我找不到原因。 I'd really appreciate your help.
我真的很感谢你的帮助。
IMG_size = (224,224,3)
extractor.add(InceptionV3(include_top=False, weights='imagenet', input_shape=IMG_SIZE)
This should do这应该做
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.