There is a workaround to convert all your images into the size [227x227x3] all at once using the image batch processor. This process involves a custom function to ensure that all images are resized correctly while preserving the colour format required by ‘AlexNet’. Since your input images are in the RGB format from itself, we can simply resize it into [227x227] using ‘imresize’ function. To get your desired format of images using image batch processor, you can follow the steps given below:
- Go to the column ‘Batch Function’ in the image batch processor and click on ‘Create Function’.
- The MATLAB Editor will open with a template function populated. Then add the following function to it:
function out = RGBresize(img)
out = imresize(img, [227 227]);
Now the output images will be converted to the format that you desired.
Another way to carry out size conversion is by using the ‘augmentedImageDatastore’ function in with your ‘AlexNet’ network. An augmented image datastore transforms batches of training, validation, test, or prediction data with optional preprocessing, such as resizing, rotation, and reflection. The following script can be used to perform the same:
imds = imageDatastore(‘folder_name’);
augImds = augmentedImageDatastore([227 227], imds,'ColorPreprocessing', 'none');
For tasks involving 3D inputs, MATLAB does provide ‘resnet3dNetwork’ offering a more appropriate solution, as they are more specifically designed to handle volumetric data and are aligned for 3D deep learning applications.
Please find the attached documentations to get more information on the specific topics:
- Transfer Learning Using AlexNet: https://www.mathworks.com/help/deeplearning/ug/transfer-learning-using-alexnet.html
- Alexnet: https://www.mathworks.com/help/deeplearning/ref/alexnet.html
- Related MATLAB Answers post: https://www.mathworks.com/matlabcentral/answers/581307-transfer-learning-for-2d-image-using-alexnet
- resnet3dNetwork : https://www.mathworks.com/help/deeplearning/ref/resnet3dnetwork.html
- Image Batch Processor: https://www.mathworks.com/help/images/process-images-using-image-batch-processor-app-with-file-metadata.html
I hope this helps!