【发布时间】:2022-01-16 11:10:50
【问题描述】:
我跟随 deeplizard 对 MobileNet 进行微调。我试图做的是从模型的第 5 层到最后一层抓取输出并将其存储在这个变量 x 中。模型第 5 层到最后一层的输出形状为global_average_pooling2d_3 (None, 1, 1, 1024)。然后添加一个具有 10 个单元的输出密集层。但是,在拟合模型时,出现以下错误。任何人都可以请给我一些指导。非常感谢。我的代码如下所示
mobile = tf.keras.applications.mobilenet.MobileNet()
mobile.summary()
x = mobile.layers[-5].output
output =layers.Dense(units=10, activation='softmax')(x)
model = Model(inputs=mobile.input, outputs=output)
for layer in model.layers[:-23]:
layer.trainable = False
model.compile(optimizer=Adam(lr=0.0001),
loss='categorical_crossentropy',
metrics=['accuracy'])
model.fit(x=train_batches,
steps_per_epoch=len(train_batches),
validation_data=valid_batches,
validation_steps=len(valid_batches),
epochs=30,
verbose=2
)
ValueError: Shapes (None, None) and (None, 1, 1, 10) are incompatible
【问题讨论】:
标签: python tensorflow keras deep-learning