I was following deeplizard to fine-tuning MobileNet. What I tried to do is to grab the output from the 5th to the last layer of the model and store it in this variable x. The output of the 5th to the last layer of the model has a shape of global_average_pooling2d_3 (None, 1, 1, 1024). Then add an output dense layer with 10 units. However, when fitting the model, I got the following error. Could anyone please kindly offer me some guidance. Thanks a lot. My code looks like the following
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