Fitting the model

Now we are ready to train the model. The following is the code for this:

# Fit model
model_one <- model %>% fit(trainx,
trainLabels,
epochs = 30,
batch_size = 32,
validation_data = list(validx, validLabels))
plot(model_one)

From the preceding code, we can see the following facts:

  • We can fit the model using independent variables stored in trainx and target variables stored in trainLabelsTo safeguard against overfitting, we will use validation_data
Note that, in the previous chapters, we made use of validation_split by specifying a certain percentage, such as 20%; however, if we used validation_split with a 20% rate, it would have used the last 20% of the training data (all airplane images) for validation.
  • This would have created a situation where the training data had no sample from the airplane images and the classification model would have been based on bicycle and car images only.
  • Therefore, the resulting image classification model would be biased and would have performed well only with bicycle and car images. Therefore, instead of using the validation_split function, in this situation, we make use of validation_datawhere we have made sure that we have a sample of each type represented in both the training and validation data.

The following graphs show the loss and accuracy for 30 epochs separately for training and validation data:

We can make the following observations from the preceding plots:

  • From the parts of the graphs dealing with accuracy, we can see that from the eighteenth epoch onward, the accuracy values for the training data attain the highest value of 1. 
  • On the other hand, the accuracy based on the validation data is mainly around two thirds, or 66.7%. Since we have data from three images that is used for validation, if all three images' from validation data is correctly classified, the reported accuracy will be 1. In this case, two out of three images are correctly classified, and that leads to accuracy of 66.7%.
  • From the parts of the graphs dealing with loss, we can see that for the training data, the loss values drop significantly from about 3 to less than 1 after 8 epochs. They continue to reduce from then on; however, the rate of decrease in the loss values slows down.
  • An approximately similar pattern can be seen based on the validation data.
  • In addition, since the loss uses probability values in its calculation, we observe a clearer trend for the loss-related plot compared to the accuracy-related plot.

Next, let's evaluate the model's image classification performance in greater detail to understand its behavior.

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

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