pytorch-image-classifier

Image classifier with Pytorch


Project maintained by achimoraites Hosted on GitHub Pages — Theme by mattgraham

Photo by Tara Winstead from Pexels

Setup

To be able to try the code you will need to

  1. Download the flowers.zip file
  2. Extract it to the root of the project as flowers/
  3. Install the dependencies Using Anaconda (recommended)
    conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch
    conda install -c anaconda pillow 
    

The flowers.zip has 3 folders that contain our flower images

The cat_to_name.json has the mappings between the flower ids and their actual names

📖 Train your classifier

Now it is time to do fun stuff!

💻 Available options

👨‍🏫 Lets train our classifier

The train.py script requires you to:

If you have CUDA compatible gpu

python train.py flowers --epochs=15 --gpu

Otherwise

python train.py flowers --epochs=15

This will start the training process for each epoch the tool will train the classifier and will evaluate the classifier accuracy.

When the training is completed the tool will save a checkpoint in checkpoints/alexnet_checkpoint.pth

We will need this for making predictions later!

🔮 Making image predictions using our classifier

Now it is time to use our classifier!

💻 Available options

👨‍🏫 Lets use our classifier

The predict.py script requires you to:

🧑‍💻 Examples

If you have CUDA compatible gpu

python predict.py flowers/test/10/image_07090.jpg checkpoints/alexnet_checkpoint.pth --gpu

Otherwise

python predict.py flowers/test/10/image_07090.jpg checkpoints/alexnet_checkpoint.pth

This will start the prediction process and you will get a list of the top predictions for the flowers/test/10/image_07090.jpg !

🎉 Congratz!

You have trained an image classifier and used it to make predictions 👏 !!!