GithubHelp home page GithubHelp logo

psatler / pytorch_challenge_image_classifier Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 3.0 3.01 MB

An Image Classifier built with PyTorch and Google Colab

License: MIT License

Jupyter Notebook 100.00%
pytorch google-colab image-classifier deep-learning convolutional-neural-networks python3 numpy transfer-learning densenet-pytorch

pytorch_challenge_image_classifier's Introduction

Image Classifier

This is the final project of the PyTorch Scholarship Challenge by Facebook and Udacity

Going forward, AI algorithms will be incorporated into more and more everyday applications. For example, you might want to include an image classifier in a smart phone app. To do this, you'd use a deep learning model trained on hundreds of thousands of images as part of the overall application architecture. A large part of software development in the future will be using these types of models as common parts of applications

In this project, you'll train an image classifier to recognize different species of flowers. You can imagine using something like this in a phone app that tells you the name of the flower your camera is looking at. In practice you'd train this classifier, then export it for use in your application.

The original repo of this challenge can be found here.

TL;DR

The project was done using Google Colaboratory and its code can be found at the Notebook in this repo.

Throughout the Notebook there are instructions guiding to executing the project.

GPU

As the network makes use of a sophisticated deep convolutional neural network the training process is impossible to be done by a common laptop. In order to train your models to your local machine you have three options:

  1. Cuda: If you have an NVIDIA GPU then you can install CUDA from here.
  2. Cloud Services: There are many paid cloud services that let you train your models like AWS or Google Cloud.
  3. Google Colab: Google Colab gives you free access to a tesla K80 GPU for 12 hours at a time. Once 12 hours have ellapsed you can just reload and continue! The only limitation is that you have to upload the data to Google Drive and if the dataset is massive you may run out of space.

Once a model is trained, then a normal CPU can be used to perform predictions and you will have an answer within some seconds.

Pretrained Network

It was used the Densenet121 pretrained model from torchvision.models using the so-called Transfer Learning. Examples on how to do this can be found at PyTorch's Documentation.

Hyperparameters

There is a wide selection of hyperparameters avaiable and different configurations.

  • Model for transfer learning: densenet121
  • Definition of classifier: one hidden layer, followed by a ReLU function with 25% dropout rate as shown below
Sequential(
  (fc0): Linear(in_features=2208, out_features=256, bias=True)
  (relu0): ReLU()
  (drop0): Dropout(p=0.25)
  (output): Linear(in_features=256, out_features=102, bias=True)
)
  • Batch size: 32
  • Criterion: Cross Entropy Loss. The criterion is the method used to evaluate the model fit.
  • Optimizer: Adam. The optimizer is the optimization method used to update the weights. More info can be found here
  • Scheduler: StepLR. It provides different methods for adjusting the learning rate and step
  • Learning Rate: 0.001
  • Epochs: 5

Using such hyperparameters, where learning_rate = 0.001, dropout = 0.25, optimizer = optim.Adam(model.classifier.parameters(), learning_rate ) and a scheduler such as lr_scheduler.StepLR(optimizer, step_size=4, gamma=0.1), which decays the learning rate by a factor of 0.1 every 4 seconds, the training process took about 11 minutes with 5 epochs, reaching an accuracy of about 94%.

Useful links

Deploying Deep Learning Models

Python/Machine Learning related articles/links:

License

This project is licensed under the terms of the MIT License © Pablo Satler 2018

pytorch_challenge_image_classifier's People

Contributors

psatler avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.