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

pytorchimg.png

PyTorch Course Project - ZERO TO GANs With CNN, ResNet & Pre-Trained Models

Sushil Rajeeva Bhandary

sushilrajeeva@gmail.com

Welcome to my PyTorch project for the course Zero to GANs from Jovian.ai. I'd like to take a moment to thank the instructor Aakash N S and the whole team for this awesome course, I got to learn a whole lot of maths, coding, intuitives behind the Deep Learning and PyTorch and I appreciate them greatly for that.

In this course project, I will be doing Image Classification by using the Fruit and Vegetable DataSet from Kaggle (https://www.kaggle.com/kritikseth/fruit-and-vegetable-image-recognition) that is with about 3600 images for training, 1000 images for validation, another 1000 images for testing and 36 classes to be classified defined as follows:


Context

This dataset contains images of the following food items:

  1. fruits - banana, apple, pear, grapes, orange, kiwi, watermelon, pomegranate, pineapple, mango.

  2. vegetables - cucumber, carrot, capsicum, onion, potato, lemon, tomato, raddish, beetroot, cabbage, lettuce, spinach, soy bean, cauliflower, bell pepper, chilli pepper, turnip, corn, sweetcorn, sweet potato, paprika, jalepeño, ginger, garlic, peas, eggplant.

This dataset contains three folders:

train (100 images each)
test (10 images each)
validation (10 images each)

each of the above folders contains subfolders for different fruits and vegetables wherein the images for respective food items are present.

Data Collection

The images in this dataset were scraped by someone from Bing Image Search for a project.

Inspiration

The idea was to build an application which recognizes the food item(s) from the captured photo and gives its user different recipes that can be made using the food item(s).

I will be using Convulational Neural Network (CNN), Resnet and Pre-Trained Model (Resent50) to train on this dataset and compare the results in attempt to go through the lessons of the whole course all over again. So let's get started.

project_name = 'Final-Course-Project-PyTorch-FruitVegitableDataSet'
!pip install opendatasets --upgrade --quiet

import opendatasets as od

od.download('https://www.kaggle.com/kritikseth/fruit-and-vegetable-image-recognition')
Please provide your Kaggle credentials to download this dataset. Learn more: http://bit.ly/kaggle-creds Your Kaggle username: sushilrajeeva Your Kaggle Key: ··········
0%| | 5.00M/2.19G [00:00<01:24, 27.8MB/s]
Downloading fruit-and-vegetable-image-recognition.zip to ./fruit-and-vegetable-image-recognition
100%|██████████| 2.19G/2.19G [00:18<00:00, 127MB/s]
import os
import torch
import torchvision
import torch.nn.functional as F
from torch.utils.data import random_split, DataLoader, Dataset
from torchvision.utils import make_grid
import torchvision.transforms as T
from torchvision.datasets import ImageFolder

import matplotlib
import matplotlib.pyplot as plt
%matplotlib inline

matplotlib.rcParams['figure.facecolor'] = '#ffffff'