We will use the flow_images_from_directory() function from keras to read and manipulate data on the fly.
- Let's read the images from the train and test directory and do the required transformations:
# Reading train datatrain_data <- flow_images_from_directory(directory = train_path, target_size = img_size, color_mode = "rgb", class_mode = "categorical", classes = class_label, batch_size = 20)# Reading test datatest_data <- flow_images_from_directory(directory = test_path, target_size = img_size, color_mode = "rgb", class_mode = "categorical", classes = class_label, batch_size = 20)
Let's see how many images we have in train and test sets:
print(paste("Number of images in train and test is",train_data$n,"and ",test_data$n,"repectively")) ...