Learn practical skills, build real-world projects, and advance your career
Created 4 years ago
Cats/Dogs Image Classification using Transfer Learning(ResNet34) in PyTorch
import os
import torch
import torchvision
import zipfile
import torchvision.transforms as T
import torch.nn as nn
import torch.nn.functional as F
import torchvision.models as models
from torchvision.datasets.utils import download_url
from torch.utils.data import random_split
from torchvision.datasets import ImageFolder
from torchvision.transforms import ToTensor
from torch.utils.data import DataLoader
image_size = 64
batch_size = 128
Exploring the Data
We'll download the images in PNG format from this page, using some helper functions from the torchvision
and zipfile
packages.
# Dowload the dataset
dataset_url = "http://files.fast.ai/data/dogscats.zip"
download_url(dataset_url, '.')
Downloading http://files.fast.ai/data/dogscats.zip to ./dogscats.zip
HBox(children=(FloatProgress(value=1.0, bar_style='info', max=1.0), HTML(value='')))
with zipfile.ZipFile('./dogscats.zip') as zip:
zip.extractall(path='./data')