The goal here is to load all the images in the ‘train’ folder and ‘validation’ folder into image data generators and visualize some of the images and their labels. Please re-order the blocks of code below, copy-paste the code blocks in appropriate order in a new Colab notebook, run them, and analyze the outputs.
import matplotlib.pyplot as plt
images, labels = train_ds[0] # # Take one batch full of images
plt.imshow(images[0])
plt.title(labels[0])
plt.axis("off")
valid_ds = datagen.flow_from_directory(
'./face-expression-kaggle/images/validation/',
target_size=(48, 48),
shuffle=True,
batch_size=32)
from tensorflow.keras.preprocessing.image import ImageDataGenerator
datagen = ImageDataGenerator(rescale=1./255)
train_ds = datagen.flow_from_directory(
'./face-expression-kaggle/images/train/',
target_size=(48, 48),
shuffle=True,
batch_size=32)
Upload the (.zip file) to Google Colab from the folder icon in the left toolbar.
import pathlib
data_dir = pathlib.Path('./face-expression-kaggle/')
image_count = len(list(data_dir.glob('*/*/*/*.jpg')))
print(image_count)
import matplotlib.pyplot as plt
images, labels = valid_ds[0] # # Take one batch full of images
plt.imshow(images[0])
plt.title(labels[0])
plt.axis("off")
! unzip face-expression-kaggle.zip