简体   繁体   English

ValueError: 层序号_3 的输入 0 与层不兼容:

[英]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.

相关问题 LSTM 中的交叉验证 - ValueError:层序号_3 的输入 0 与层不兼容 - Cross-Validation in LSTM - ValueError: Input 0 of layer sequential_3 is incompatible with the layer ValueError: 层序列 1 的输入 0 与层不兼容 - ValueError: Input 0 of layer sequential_1 is incompatible with the layer TensorFlow ValueError:层顺序的输入0与层不兼容 - TensorFlow ValueError: Input 0 of layer sequential is incompatible with the layer ValueError: 层序号_2 的输入 0 与层不兼容 - ValueError: Input 0 of layer sequential_2 is incompatible with the layer "ValueError: Input 0 of layer "sequential" is in compatible with the layer" 在预测中 - "ValueError: Input 0 of layer "sequential" is incompatible with the layer" In prediction 层“sequential_3”的输入0与层不兼容:预期形状=(无,60),找到形状=(5,174) - Input 0 of layer "sequential_3" is incompatible with the layer: expected shape=(None, 60), found shape=(5, 174) ValueError: Input 0 of layer "sequential_8" is in compatible with the layer - 深度学习 model - ValueError: Input 0 of layer "sequential_8" is incompatible with the layer - deep learning model ValueError:层顺序的输入0与层不兼容(重塑错误) - ValueError: Input 0 of layer sequential is incompatible with the layer(Reshape error) 构建简单的神经网络:ValueError: Input 0 of layer sequence is in compatible with the layer - Building a simple Neural Network: ValueError: Input 0 of layer sequential is incompatible with the layer 无法解决 ValueError: 层序贯_1 的输入 0 与层不兼容 - Cannot solve ValueError: Input 0 of layer sequential_1 is incompatible with the layer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM