We can now preprocess the input to prepare it so that it can be used with the pretrained RESNET50 model. The codes to preprocess the data are as follows:
# Preprocessing of input data
x <- array_reshape(x, c(1, dim(x)))
x <- imagenet_preprocess_input(x)
hist(x)
In the preceding code, we can observe the following:
- After applying the array_reshape() function, the dimensions of the array will change to 1 x 224 x 224 x 3.
- We used the imagnet_preprocess_input() function to prepare the data in the required format using the pretrained model.
A plot of the data in the form of a histogram after preprocessing is as follows:
The histogram of values after preprocessing shows a shift in location. Most of the values are now concentrated between 50 and 100. However, there is no major change in the overall pattern of the histogram.