Using a pretrained Imagenet model for image classification. I am not able to understand the include_top = False in the arguments.I know that it removes fully connected layers at the end. Also I would like to know how to decide which pretrained model to use for which kind of image classification task ?
Your question is related to transfer learning. In general CNN models for image classification can be divided into 2 parts:
When you do transfer learning you wish to take the trained feature extractor because it's job is to find features that most of the time will be at your classification task (this sentence comes with a big assumption that the input to your task is somewhat similar to the input that the feature extractor was trained on). When you do transfer learning you need to re-train the classifier because now it should classify different classes and train only the classifier on your data.
In CNN models the feature extractor most of the time is the convolution's layers and the fully connected are the classifier, this is the case on the ImageNet models anyway. This is why they remove the fully connect layers when doing transfer learning and retrain them.
For your second question, most of the time you should take the best available model (depending on your performance/memory limits) because it probably has the strongest feature extractor.
More on transfer learning (just google it): ftp://ftp.cs.wisc.edu/machine-learning/shavlik-group/torrey.handbook09.pdf
I am not able to understand the include_top = False in the
If you look into the code, it is a simple if-else condition:
if include_top:
# Classification block
x = layers.Flatten(name='flatten')(x)
x = layers.Dense(4096, activation='relu', name='fc1')(x)
x = layers.Dense(4096, activation='relu', name='fc2')(x)
x = layers.Dense(classes, activation='softmax', name='predictions')(x)
else:
if pooling == 'avg':
x = layers.GlobalAveragePooling2D()(x)
elif pooling == 'max':
x = layers.GlobalMaxPooling2D()(x)
If you set include_top=True, it creates a classification layer (for fine-tuning purposes) otherwise, the output of the previous layer is used (for feature-extraction) through a GlobalAvreagePooling2D().
I would like to know how to decide which pretrained model to use for which kind of image classification task?
Every model has its own pros and cons. The number of parameters, training time, inference time, accuracy, and some other things are a few things that caused a researcher to favor one model over another. There is no model which excels on every task or dataset [see no free launch theorem].
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With