-1

I'm trying to use tensorflow's MobileNet v2. I don't understand why, but it seems that the last fully connected layers, with the output categories (dimensionality 1000) layer is missing and I'm left with what seems to be just the embeddings after some convolutional layer.

Any idea on why this is happening? How can I add, or where can I find the pre-trained fully connected layers block?

Here is the code:

image = np.array(PIL.Image.open("amsterdam.jpg"))
image = np.expand_dims(image,0)
IMG_SIZE = image.shape[1:3]
IMG_SHAPE = IMG_SIZE + (3,)
base_model = tf.keras.applications.MobileNetV2(input_shape=IMG_SHAPE,
                                               include_top=False,
                                               weights='imagenet')
tf.keras.utils.plot_model(base_model,to_file='model.png', show_shapes=True)

Here you can see the structure of the neural network as I plotted it with tf.keras.utils.plot_model: enter image description here

Any idea on how to fix this?

fstab
  • 4,801
  • 8
  • 34
  • 66

1 Answers1

0
  • include_top=False: return the model without dense layers for classification. You can add your own dense layers.
  • include_top=True: return the entire model.

If you want to get also dense layers for classification, use include_top=True as the default is. When you set include_top=False the model will not return the dense layers, in order to let you make your own dense layers and make your own classification to suit your needs.

Kaveh
  • 4,618
  • 2
  • 20
  • 33