无法预测CNN模型:如何解决不兼容的图层?

问题描述

帮助!我无法预测模型,因为它给了我错误: ValueError: Input 0 of layer dense_3 is incompatible with the layer: expected axis -1 of input shape to have value 100352 but received input with shape [None,131072]

我刚刚使用ResNet50架构和一些顶层训练了CNN。 这是我用来创建模型的代码...

base_model = ResNet50(weights = None,include_top=False,input_shape=(200,200,3))

x = base_model.output
x = Flatten()(x)
x = Dropout(0.2)(x)
x = Dense(32,activation='relu')(x)
x = Dense(16,activation='relu')(x)
predictions = Dense(num_class,activation='softmax')(x)

# The model to be trained
model = Model(inputs=base_model.input,outputs=predictions)

model.compile(loss='binary_crossentropy',optimizer='rmsprop',metrics=['accuracy'])

callbacks_list = [keras.callbacks.EarlyStopping(monitor='val_acc',verbose=1)]
model.summary()

如您所见,我仅在ResNet50架构之上使用了几层。我还使用了200、200、3的图像尺寸输入 回过头来,这是FLATTEN对第二层DENDEN DENSE LAYER的摘要。

__________________________________________________________________________________________________
flatten_1 (Flatten)             (None,100352)       0           conv5_block3_out[0][0]           
__________________________________________________________________________________________________
dropout_1 (Dropout)             (None,100352)       0           flatten_1[0][0]                  
__________________________________________________________________________________________________
dense_3 (Dense)                 (None,32)           3211296     dropout_1[0][0]                  
__________________________________________________________________________________________________

致密层期望输入形状为100,352,但输入的形状为131,072 !!因此,通过...运行预测代码时出现值错误。

img_path = 'train/10_right.jpeg'
img = image.load_img(img_path,target_size =(256,256))
x = image.img_to_array(img)
x = np.expand_dims(x,axis=0)

preds = model.predict(x)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...