Learn practical skills, build real-world projects, and advance your career
import os
import torch
import pandas as pd
import numpy as np
from torch.utils.data import Dataset, random_split, DataLoader
from PIL import Image
import torchvision.models as models
import matplotlib.pyplot as plt
import torchvision.transforms as transforms
from sklearn.metrics import f1_score
import torch.nn.functional as F
import torch.nn as nn
from torchvision.utils import make_grid
%matplotlib inline

Extracting the data

In this segment I'll create the paths to read the data.
The data (from kaggle.com) is a bird image dataset containing photos from dozens of species. 10 species will be chosen out of the whole dataset.

TEST_DIR = '../input/100-bird-species/test/'    # Path to test dataset
TRAIN_DIR = '../input/100-bird-species/train/'    # Path to train dataset
VALID_DIR = '../input/100-bird-species/valid/'    # Path to validation dataset
label_dict = {        # The chosen species
    0: 'Mallard duck',
    1: 'Mandrin duck',
    2: 'Red headed duck',
    3: 'Teal duck',
    4: 'Steamer duck',
    5: 'Emu',
    6: 'Ostrich',
    7: 'Javan magpie',
    8: 'Taiwan magpie',
    9: 'Eurasian magpie'
}
print(label_dict)
{0: 'Mallard duck', 1: 'Mandrin duck', 2: 'Red headed duck', 3: 'Teal duck', 4: 'Steamer duck', 5: 'Emu', 6: 'Ostrich', 7: 'Javan magpie', 8: 'Taiwan magpie', 9: 'Eurasian magpie'}