Artificial Intelligence

PyTorch Ignite Tutorial- Classifying Tiny ImageNet with EfficientNet

A step-by-step guide on using PyTorch Ignite to simplify your PyTorch deep learning implementation

Kenneth Leung
August 22, 20212 min read
Photo by Olga Bast on Unsplash
Photo by Olga Bast on Unsplash

Define GPU support for PyTorch (i.e., use CUDA).


If done correctly, you should see the folders appear on the Colab sidebar:

  • Create DataLoaders for the image datasets

The job of a DataLoader is to generate mini-batches of data from a dataset, giving us the flexibility to choose from different sampling strategies and batch sizes.

In the code above, we used the ImageFolder function from torchvision.datasets to generate datasets. For ImageFolder to work, images in training and validation folders must be arranged in the following structure:




The PyTorch implementation of the newer EfficientNet v2 is coming soon, so stay tuned to this GitHub repo for the latest updates.




You can also create your own custom metric before attaching it to an engine. For example, the F1 score can be derived arithmetically from the default Precision and Recall metrics:

text


Although we are using Tensorboard here, we can easily use other popular logging tools such as Weights and Biases, ClearML, and MLflow. Have a look at the common module documentation for more information.


Here is what the first training epoch looks like in Colab:

After executing the above commands, the following Tensorboard interface will load in the Colab notebook. This visual dashboard provides us with metrics information obtained from the training runs.

Screenshot of Tensorboard | Image by author
Screenshot of Tensorboard | Image by author

Wrapping things up

In this tutorial, we covered the steps to leverage the flexibility and simplicity of the Ignite framework to build PyTorch deep learning models.

PyTorch Ignite has many other functionalities to suit the needs of more complex neural network designs, so feel free to explore the documentation and example notebooks.

For example, instead of the static learning rate used earlier, we can incorporate a learning rate scheduler (LRScheduler) handler to **** adjust the learning rate values during training. The flexibility also means that we can include other algorithms like FastAI's learning rate finder in the setup.

Project Links

Photo by Aziz Acharki on Unsplash
Photo by Aziz Acharki on Unsplash

Before You Go

I welcome you to join me on a data science learning journey. Follow this Medium page and check out my GitHub to stay in the loop of practical and educational data science content. Meanwhile, here's wishing you the best of luck in the exam!


References

Related Articles