TensorFlow2 — MobileNets: A Pre-trained Multiclass Classifier
MobileNets are lightweight deep neural networks that are suitable for mobile and embedded vision applications (Howard et al., 2017).
Computer Vision (CV) engineers often utilize transfer learning techniques to perform CV tasks with pre-trained convolutional neural networks (CNN).
Keras Fashion-MNIST is a toy dataset which consists of images of clothing. The data has a training set of 60,000 28x28 grayscale images of 10 fashion categories, along with a testing set of 10,000 images. A dictionary key is defined below with the corresponding class name for each of the integer label values.
Data augmentation
In order to prevent model overfitting problem and help the model generalization. we use Keras “ImageDataGenerator” class to augment the training examples.
Figure 2 shows a set of augmented 128x128 grayscale images.
Modelling
We build our mobile_net model on MobileNets with pre-trained weights from ImageNet excluding the top layer. We develop a customized input layer so that our model will accept gray scale images of any size. After the base model’s last layer, we add a global_average_pooling2d layer and a Dense layer with 10 softmax functions as the output layer.
Model training
We select Adam optimizer with a learning rate of 0.001 to minimize the “categorical_crossentropy” loss. Data from generator flow is directly fitted into the model during model training.
Results:
The best validation accuracy is 95.12%.
After 50 epochs training, the model achieves the best validation accuracy: 95% .
Making predictions
To make predictions on the test set, we can first load the best-trained model that has been automatically saved as the “mobile_net.h5” file by the “checkpointer” callback function (see the “train the model” code block). Then, we use the model to predict a batch of test images.
The notebook is accessible at this link.
References
Howard, A., Zhu, M., Chen, B., Kalenichenko, D., Wang, W., Weyand, T., Andreetto, M. and Adam, H., 2017. Mobilenets: Efficient Convolutional Neural Networks For Mobile Vision Applications. [online] arXiv.org. Available at: <https://arxiv.org/abs/1704.04861> [Accessed 31 May 2020].