How to do it...

We will use the flow_images_from_directory() function from keras to read and manipulate data on the fly.

  1. 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")) ...

Get Deep Learning with R Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.