Learn practical skills, build real-world projects, and advance your career
import os
os.environ['KAGGLE_CONFIG_DIR'] = "/content/gdrive/My Drive/Kaggle"
from google.colab import drive
drive.mount('/content/gdrive')
Mounted at /content/gdrive
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 torchvision.transforms as T
import torch.nn as nn
from torchvision.utils import make_grid
from torchvision.datasets import ImageFolder
%matplotlib inline
# checking the number of images for each class.
data_directory = '/content/gdrive/My Drive/Kaggle/stanford_dogs_dataset/train2/'
#data_directory = '/content/gdrive/My Drive/Kaggle/stanford_dogs_dataset/train/'

num_images = []
for root, dirs, files in os.walk(data_directory):
  if files == []:
    continue
  else:
    num_images.append(len(files))
print(num_images)
# to test the size of the images
image_size_test = ImageFolder(data_directory, T.ToTensor())
len(image_size_test)
#checking the size of the first 10 images in the dataset

im_count = 0
for image,_ in image_size_test:
  im_count += 1
  print(image.shape)
  if im_count == 10:
    break
height = []
width = []
for image,_ in image_size_test:
  height.append(image.shape[1])
  width.append(image.shape[2])
print("minimum height: {}, maximum height: {}, minimum width: {}, maximum width: {}".format(min(height), max(height), min(width), max(width)))

Course Project for zero-to-gans

This notebook uses the Stanford Dogs dataset Classification.

I used this medium article How to fetch kaggle datasets into google colab to download the kaggle dataset into my google drive. Beware fellow datascience practitioners of these thingsissues while working on this dataset-

  1. Massive image datasets (numbering into several GB)
  2. Download times
  3. there is no separate training/val/test folders but only labelled folders
%cd /content/gdrive/My Drive/Kaggle
/content/gdrive/My Drive/Kaggle