Getting ready

In this example, we will work on a sample of the Fruits 360 dataset. The dataset is credited to Horea Muresan and Mihai Oltean. The dataset was introduced in their paper, Fruit recognition from images using deep learning, which presents the results of a numerical experiment for training a neural network to detect fruits. The dataset can be downloaded from Kaggle at https://www.kaggle.com/moltean/fruits. The Fruits 360 dataset contains colored images of 103 fruits of size 10× 100, but in our example, we will work on images of only 23 fruits. It has two subsets: a training set and a test set with samples of each fruit in directories corresponding to the fruit name.

We will start by loading the keras library:

library(keras)

We have our dataset in the folder named as fruits in our current working directory. This folder contains train and test subfolders that contain fruit images in folders named after that particular fruit. Let's store the paths of the train and test data into variables:

# path to train and test directories
train_path <- "fruits/train/"
test_path <- "fruits/test/"

Let's create a vector of names of the fruits that are present in our data:

class_label <- list.dirs(path = train_path, full.names = FALSE, recursive = TRUE)[-1]

Now we print the names of fruits (class labels) of our data:

class_label

The following screenshot shows the names of fruits in our data:

For looking at the number of classes of fruits, you can use the following code:

length(class_label)

Now let's set the image width and height, we will scale down the size of the image from 100 × 100 to 20 × 20:

img_width = 20
img_height = 20
img_size = c(img_width,img_height)

We are now familiar with the dataset and the transformations we want to do. Let's move on to implement these transformations.

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

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