Getting ready

In this recipe, we will use a subset of the Flowers Recognition dataset, which is credited to Alexsandr Mamaev. The subset of data that we'll be using in this example contains around 2,500 images of three types of flowers – sunflower, dandelion, and daisy. Each class consists of about 800 photos. The data can be downloaded from Kaggle at https://www.kaggle.com/alxmamaev/flowers-recognition.

Let's start by loading the required libraries:

library(keras)
library(reticulate)
library(abind)
library(grid)

Now, we can load the data into the R environment. We will leverage the flow_images_from_directory() function from keras to load the data. The data is present in a folder named flowers, which contains subfolders, each belonging to a particular class of flower. Since our input images are not uniform in size, while loading the data itself, we specify the target size so that each image is resized accordingly:

train_path <- "data/flowers/"

image_width = 32
image_height = 32
target_image_size = c(image_width,image_height)

training_data <- flow_images_from_directory(directory = train_path,target_size = target_image_size, color_mode = "rgb", class_mode = NULL, batch_size = 2500)

training_data = as_iterator(training_data)
training_data = iter_next(training_data)
training_data <- training_data/255
dim(training_data)

The following screenshot shows the dimensions of the training data:

Now that we are aware of the data, let's move on to the model building stage.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset