输入0与图层展平不兼容:预期的min_ndim = 3,找到的ndim = 2

时间:2019-03-02 14:44:28

标签: python image-processing deep-learning flatten faster-rcnn

image_input = Input(shape=(224, 224, 3))

model = ResNet50(weights='imagenet', include_top=True)

model.summary()

last_layer = model.get_layer('avg_pool').output  
last_layer.shape  
x= Flatten(name='flatten')(last_layer)  
out = Dense(num_classes, activation='softmax', name='output_layer')(x)  
custom_resnet_model = Model(inputs=image_input,outputs= out)
custom_resnet_model.summary()

for layer in custom_resnet_model.layers[:-1]:  
    layer.trainable = False

custom_resnet_model.layers[-1].trainable

custom_resnet_model.compile(loss='categorical_crossentropy',optimizer='adam',metrics=['accuracy'])

t=time.time()  
hist = custom_resnet_model.fit(X_train, y_train, batch_size=32, epochs=1, verbose=1, 
validation_data=(X_test, y_test))  
print('Training time: %s' % (t - time.time()))  
(loss, accuracy) = custom_resnet_model.evaluate(X_test, y_test, batch_size=10, verbose=1)

print("[INFO] loss={:.4f}, accuracy: {:.4f}%".format(loss,accuracy * 100))

我遇到此错误

  

输入0与平整层不兼容:预期的min_ndim = 3,运行x = Flatten(name ='flatten')(last_layer)时发现ndim = 2。

last_layer的形状是TensorShape([Dimension(None), Dimension(2048)])? 谁能解释在喀拉拉邦如何解决这个问题?

0 个答案:

没有答案