We are tasked with building a transfer learning network. The issue I’m having is that we are asked to exclude the last layer when setting our model. However, the weights that are used to initialize the model include the last layer. I get a expect 104 layers, loaded 105.

When I use 'imagenet' to load the weights the error goes away. This requires that I replace what was already in place (already set for me in the template). Everything is so well thought out in these assignments that I suspect I might be doing something wrong.

base_model = tf.keras.applications.MobileNetV2(input_shape=input_shape,
include_top=False, # <== Important!!!!
weights='imagenet') # WAS base_model_path
# where base_model_path="imagenet_base_model/with_top_mobilenet_v2_weights_tf_dim_ordering_tf_kernels_1.0_160.h5"

I still have not passed all the tests (I’m still working on the network configuration), but wanted to get clarification here. What weights should I load to initialize the model where I’m tasked with training the last few layers?

I suspect a newer version of the template had the wrong reference to the previously computed weights. The model works and passes the tests using 'imagenet' instead of the locally available file.

Note: There are older posts that ask different questions about the assignment. The older version uses 'imagenet'.

I have tested your notebook after making the following changes:

In cells [10] and [14], I used the correct base_model_path to load the weights. Note that the base model weights paths are different for cell [10] (with top layer) than for cell [14] (without top layer).

I removed the chained assignment “=loss=” from the definition of the loss function (in UNQ_C3).

In cell [26], I removed the initialization of the variables. The reason for not initializing the variables here is that for the history plots, we want to show the first 5 epochs (the base training) along with the second 5 epochs (for the fine tuning) to present them all in one plot of all 10 epochs.