Transfer_learning_with_MobileNet_v1: The alpaca model

I am not quite sure how to proceed, the instructions provided are not sufficient .
This is what I have done and stuck, please help me out!

START CODE HERE

base_model = tf.keras.applications.MobileNetV2(input_shape=input_shape,
                                               include_top=False, # <== Important!!!!
                                               weights=None) # From imageNet

# freeze the base model by making it non trainable
base_model.trainable = False 

# create the input layer (Same as the imageNetv2 input size)
inputs = tf.keras.Input(shape=input_shape) 

# apply data augmentation to the inputs
x = data_augmentation(inputs)

# data preprocessing using the same weights the model was trained on
x = preprocess_input(x) 

# set training to False to avoid keeping track of statistics in the batch norm layer
x = base_model(x, training=False) 

# add the new Binary classification layers
# use global avg pooling to summarize the info in each channel
x = tf.keras.layers.GlobalAveragePooling2D()(x) 
# include dropout with probability of 0.2 to avoid overfitting
x = tf.keras.layers.Dropout(0.2)(x)
    
# use a prediction layer with one neuron (as a binary classifier only needs one)
outputs = tf.keras.layers.Dense(1)

### END CODE HERE

I have left weights value as None, what is it’s value?

You can always look at the documentation when you have questions about parameter choices:

https://www.tensorflow.org/api_docs/python/tf/keras/applications/mobilenet_v2/MobileNetV2

From there, we find that

weights: String, one of None (random initialization), ‘imagenet’ (pre-training on ImageNet), or the path to the weights file to be loaded.

2 Likes

Okay got it, I have added ‘imagenet’ as weight.
But, now I am getting another error

AttributeError: ‘Dense’ object has no attribute ‘op’

The functional API requires you to pass something to the Dense object you get back. Double check how you have connected previous layers and try to apply the same logic to outputs

Oops…my bad I missed to pass (x).
Thank you mentor

1 Like