Training, validation, and test data

We will use the first three images of the bicycles, cars, and airplanes respectively for training, the fourth image of each type for validation, and the remaining two images of each type for testing. Thus, the training data will have nine images, the validation data will have three images, and the test data will have six images. The following is the code to achieve this:

# Training Data
a <- c(1:3, 7:9, 13:15)
trainx <- NULL
for (i in a) {trainx <- rbind(trainx, mypic[[i]]) }
str(trainx)

OUTPUT

num [1:9, 1:2352] 1 1 1 1 0.953 ...

# Validation data
b <- c(4, 10, 16)
validx <- NULL
for (i in b) {validx <- rbind(validx, mypic[[i]]) }
str(validx)

OUTPUT

num [1:3, 1:2352] 1 1 0.26 1 1 ...

# Test Data
c <- c(5:6, 11:12, 17:18)
testx <- NULL
for (i in c) {testx <- rbind(testx, mypic[[i]])}
str(testx)

OUTPUT

num [1:6, 1:2352] 1 1 1 1 0.49 ...

As you can see from the preceding code, we will use the rbind function to combine the rows of data that we have for each image when creating training, validation, and test data. After combining the rows of data from the nine images, the structure of trainx indicates that there are 9 rows and 2,352 columns. Similarly, for the validation data, we have 3 rows and 2,352 columns, and for the test data, we have 6 rows and 2,352 columns.

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

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