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

Classifying Fruits 360 images using ResNets and regularization in PyTorch

Imports

import os
import torch
import torchvision
import tarfile
import torch.nn as nn
import numpy as np
import torch.nn.functional as F
from torchvision.datasets.utils import download_url
from torchvision.datasets import ImageFolder
from torch.utils.data import DataLoader
import torchvision.transforms as tt
from torch.utils.data import random_split
from torchvision.utils import make_grid
import matplotlib
import matplotlib.pyplot as plt
from tqdm import tqdm
%matplotlib inline

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

Preparing the data

Downloading the dataset.

Fruits 360 dataset is a dataset of images containing fruits and vegetables.

Our goal is to classify each fruit and vegetable image according to its label. Therefore it is a classifying problem.

There are 90483 images, 67692 of which are in the training set and 22688 in the test size.

The total number of classes to predict is 131. All images are 100 X 100 pixels

it can be found here: https://www.kaggle.com/moltean/fruits