Week 2 - Transfer Learning with MobileNet - AlpacaModel

Hi, I was having a small problem with the AlpacaModel. The error I have is related to adding the binary classification layers. The shape is right before but I don’t really know how to add them so I get an error:

Test failed
Expected value
[‘Functional’, (None, 5, 5, 1280), 2257984]
does not match the input value:
[‘GlobalAveragePooling2D’, (None, 3), 0]

I don’t know how to get the desired shape. Anybody know what I should do and could offer some insight? How should I go about adding the binary classification layer?

Best regards,

Hi BrynjarGeir,

When you use a functional model you have to assign the application of a layer to a tensor to a new tensor with each step. Have a look at the link provided here:

Thanks for the response reinoudbosch. I can’t view the article. So I think I am assigning it to a new one in each step.


I don’t know, is there a step I’m missing or? Sorry for putting the code in here but I’ve been stuck for some time now.

Hi BrynjarGeir,

There is a difference between setting base_model.trainable to False (to avoid changing the weights of the base model) and setting training in base_model to False (to avoid keeping track of statistics in the batch norm layer). For the latter, you have to pass both x and training (as False) as arguments into the base model. And don’t forget to assign to a new x!

Thank you so much. Got it to work :smile:
I’ll remove the stuff I had put in here!

1 Like