Skip to content

ariharasudhanm/Explaining_attentions_for_Image_Classification

Repository files navigation

Contributors Last-commit license-url LinkedIn


Explaining_attentions_for_Image_classification (Kaggle Competetion)

Classification of Kenyan foods with transfer learning methods using Pytorch
Explore the docs »

· Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Usage
  3. Roadmap
  4. Results
  5. Docker Container
  6. Contributing
  7. License
  8. Contact

About The Project

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.

(back to top)

Usage

  • 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.

Roadmap

  • 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).

(back to top)

Hyperparameter Tuning

  • 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

Results

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.

Class Activation Maps

  • 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.

Docker Container

This section is composed of instructions to run a docker container for inferencing an image in the local machine(Linux).

  1. 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.
  2. 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 including img-classifier which we are going to use it to build a docker container.
  3. 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 called new_dir inside the container and mount the local directory which has images to the newly created container in the new_dir itself.
  4. Now we should be inside that container in /usr/src/files this directory if you use ls command then you should be able to see the new_dir which you created earlier.
  5. Using python3 --image {new_dir/name_of_img.jpeg} should list down the predictions with the top three probabilities.
  6. Use exit command to exit the container since, we are using the --rm tag we will loose this container after exiting.
  7. If you list down all the containers using docker ps -a or docker container list ls previously created container will not be there.

Contributing

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!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

Contact

Your Name - @AriharasudhanM - [email protected]

Project Link: Image-classification-Kaggle-Competition

(back to top)

About

Kenya food image classification

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published