Now we will see how it's possible to implement TL in PyTorch by performing the following steps. We will use a standard training set, cats and dogs, and a pre-trained network:
- Import the necessary libraries as follows:
import torch
import torchvision
import torch.nn as nn
import numpy as np
import torch.optim as optim
from torchvision import models
from torchvision import transforms
import copy
import os
from os import listdir
import shutil
from torchvision import datasets
import random
from torch.optim import lr_scheduler
import matplotlib.pyplot as plt
- Now, we will use a handy PyTorch function:
# # Create train and test dataset
data_dir = os.path.join('kagglecatsanddogs_3367a','PetImages')
# # Create the train and test set folder
train_dir = os.path.join(data_dir, 'train')
validation_dir = os.path.join(data_dir, 'validation...