Learn practical skills, build real-world projects, and advance your career

Image Classification using Logistic Regression in PyTorch

Part 3 of "PyTorch: Zero to GANs"

This post is the third in a series of tutorials on building deep learning models with PyTorch, an open source neural networks library. Check out the full series:

  1. PyTorch Basics: Tensors & Gradients
  2. Linear Regression & Gradient Descent
  3. Image Classfication using Logistic Regression
  4. Training Deep Neural Networks on a GPU
  5. Coming soon.. (CNNs, RNNs, GANs etc.)
pip install jovian --upgrade
Requirement already up-to-date: jovian in /srv/conda/envs/notebook/lib/python3.7/site-packages (0.1.89) Requirement already satisfied, skipping upgrade: requests in /srv/conda/envs/notebook/lib/python3.7/site-packages (from jovian) (2.21.0) Requirement already satisfied, skipping upgrade: pyyaml in /srv/conda/envs/notebook/lib/python3.7/site-packages (from jovian) (5.1.2) Requirement already satisfied, skipping upgrade: uuid in /srv/conda/envs/notebook/lib/python3.7/site-packages (from jovian) (1.30) Requirement already satisfied, skipping upgrade: chardet<3.1.0,>=3.0.2 in /srv/conda/envs/notebook/lib/python3.7/site-packages (from requests->jovian) (3.0.4) Requirement already satisfied, skipping upgrade: urllib3<1.25,>=1.21.1 in /srv/conda/envs/notebook/lib/python3.7/site-packages (from requests->jovian) (1.24.1) Requirement already satisfied, skipping upgrade: certifi>=2017.4.17 in /srv/conda/envs/notebook/lib/python3.7/site-packages (from requests->jovian) (2019.3.9) Requirement already satisfied, skipping upgrade: idna<2.9,>=2.5 in /srv/conda/envs/notebook/lib/python3.7/site-packages (from requests->jovian) (2.8) Note: you may need to restart the kernel to use updated packages.
import jovian
jovian.commit()
[jovian] Saving notebook..

In this tutorial, we'll use our existing knowledge of PyTorch and linear regression to solve a very different kind of problem: image classification. We'll use the famous MNIST Handwritten Digits Database as our training dataset. It consists of 28px by 28px grayscale images of handwritten digits (0 to 9), along with labels for each image indicating which digit it represents. Here are some sample images from the dataset:

mnist-sample