Classification of Kenyan foods with transfer learning methods using Pytorch
Explore the docs »
·
Report Bug
·
Request Feature
Table of Contents
This is a code written for Kaggle competetion OpenCV Pytorch Course - Classification which includes more than 8000 images for training and testing and its testing procedure is carried out quite similiar to usual kaggle testing procedures which can be found under the competetion page itself. Handled number of issues from imbalanced datasets to overfitting and finally able to reach quite good results which can be found under leaderboard of the competetion page.
Project Overview:
- Data augmentation.
- Dataloader creation(train, validation).
- Training with different experimental setups such as training only the classifiers and along with feature extraction layers.
- Hyperparameter tuning and testing is performed.
- App is built with gradio which is available in Hugging face to test.
- All the codes can be found under the
main.pynb
from data to preparation to training the model. - Make sure to change the paths of all the files to your requirements where-ever needed if your'e training for a new model.
- Complete data used in this project is available in OpenCV Pytorch Course - Classification.
- Some sample images used to train can be found under
Sample_data
directory. - Trained model can be downloaded from model.pth.
- Data preparation.
- Training and validation, Testing.
- Hyperparameter Tuning.
- Class Activation Maps.
- Running docker container for inference.
- Publishing the model as app.
See the open issues for a full list of proposed features (and known issues).
- I have considered random grid search method for hyper parameter optimization for chosen parameters such as batch size, several optimizers, learning rate and dropout.
- Thanks to weight and bias since I used this tool to monitor the whole hyperparameter tuning iterations which can be found here wandb
Testing the trained model for few images from test set tested_samples.png
.
Trained model is available in the model in the hugging face page.
- Adding an explainibility method to the model with the help of class activation maps, identifying the regions that caused the model to choose that specific class for an image.
- We used the technique called Deep Features for Discriminative Localization which was published in this paper Bolei Zhou, Aditya Khosla, Agata Lapedriza, Aude Oliva, Antonio Torralba; Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2016, pp. 2921-2929. Since this technique is reliable when our network(efficientnetb4) has global average pooling layer.
- It not only adds explainability but also helped to consider necessary data augementation procedures to some extend.
- Classfication along with class activation maps are available in the huggingface which can be accessed through this Hugging face space.
This section is composed of instructions to run a docker container for inferencing an image in the local machine(Linux).
- You can pull the docker image to your local machine by using this command
docker pull ariharasudhan/food-classifier
in a command terminal or you can find it in the docker repo, by default it will pull the latest image so no issues with image versions. - You can check the availability of this image in the local host by using
docker images ls -a
in a command terminal which should list down all the images includingimg-classifier
which we are going to use it to build a docker container. - Now you can run the command
docker run --name {name_of_your_container} --rm -it -v {img_dir/path/in/localhost}:/usr/src/files/{new_dir} img-classifier bash
which will create a new container and new volume callednew_dir
inside the container and mount the local directory which has images to the newly created container in thenew_dir
itself. - Now we should be inside that container in
/usr/src/files
this directory if you usels
command then you should be able to see thenew_dir
which you created earlier. - Using
python3 --image {new_dir/name_of_img.jpeg}
should list down the predictions with the top three probabilities. - Use
exit
command to exit the container since, we are using the--rm
tag we will loose this container after exiting. - If you list down all the containers using
docker ps -a
ordocker container list ls
previously created container will not be there.
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE.txt
for more information.
Your Name - @AriharasudhanM - [email protected]
Project Link: Image-classification-Kaggle-Competition