Course 4 - Week #2 : Assignment 2

Hi Team,
I am stuck with below error while trying train the top layers of a base model.

I am getting an Assertion error saying “The number of layers in the model is incorrect. Expected: 8 Found: 7”. When I try to inspect the layers of the alpaca model, it is missing “Sequential” layer.

model2.summary()
Model: “functional_5”


Layer (type) Output Shape Param #

input_15 (InputLayer) [(None, 160, 160, 3)] 0


tf_op_layer_RealDiv_2 (Tenso [(None, 160, 160, 3)] 0


tf_op_layer_Sub_2 (TensorFlo [(None, 160, 160, 3)] 0


mobilenetv2_1.00_160 (Functi (None, 5, 5, 1280) 2257984


global_average_pooling2d_5 ( (None, 1280) 0


dropout_2 (Dropout) (None, 1280) 0


dense_2 (Dense) (None, 1) 1281

Total params: 2,259,265
Trainable params: 1,281
Non-trainable params: 2,257,984


I am just using the data_augmenter() function as is. It should have the sequential model created and returned as a output and passing the “inputs” as an input to this model. Still it is not added to the layers. Please let me know what am I missing here.

Maybe the way you are invoking data_augmentation is incorrect. If you call it, but don’t use the output as the input to the next layer, then it doesn’t get included in the compute graph.

Also note that data_augmenter is a function that you call and it returns you the actual function you really want to call. So it’s a mistake to call data_augmenter from alpaca_model. You need to call data_augmentation, which is the function that is actually passed in as an argument and is the return value of calling data_augmenter.

Thanks for reply @paulinpaloalto !

Yes thats correct. I am not using the data_augmenter inside alpaca_model. I am using data_augmentation to pass input arguments.
Also, the output of data_aumentation is not used as input to next layer. Please find the masked code as below:

{moderator edit - solution code removed}

Yes, the problem is with the compute graph, as I suggested. Notice that you don’t use the output of the call to data_augmentation, so that is a dead branch in the compute graph: it contributes nothing to the final result, which is why it does not show up in the “summary” of the model. Well, I can’t completely see the code, but the argument you are passing to the next step looks like it’s probably inputs, which is wrong.

ahh… got it! It worked now!

Thank you @paulinpaloalto for helping me with this!

1 Like