We can use the pretrained RESNET50 model to identify the second image in the training data. Note that, since this second image in the training data is 32 x 32 in size, whereas RESNET50 is trained on images that are 224 x 224 in size, we need to resize the image before applying the code that we have used earlier. The following code is used for identifying the image:
# Pre-processing and prediction
x <- resize(trainx[2,,,], w = 224, h = 224)
x <- array_reshape(x, c(1, dim(x)))
x <- imagenet_preprocess_input(x)
preds <- pretrained %>% predict(x)
imagenet_decode_predictions(preds, top = 5)[[1]]
OUTPUT
class_name class_description score
1 n03796401 moving_van 9.988740e-01
2 n04467665 trailer_truck 7.548324e-04
3 n03895866 passenger_car 2.044246e-04
4 n04612504 yawl 2.441246e-05
5 n04483307 trimaran 1.862814e-05
From the preceding code, we can observe that the top category with a score of 0.9988 is for a moving van. The scores for the other four categories are comparatively negligible.