Resizing images to 224*224 for training VGG16 Model
16 views (last 30 days)
Show older comments
Hi I'm training a VGG16 Model in the latest version of MATLAB R2023-a and I keep getting the same resizing error. I'm wondering if there is a new way to resize the images in a datastore in MATLAB or if the error is really on my improper execution of resizing in my code.
I have a folder of dataset with two sub folders which are my classes. This is the first part of my code with resizing:
% Load the dataset
imds = imageDatastore('DataSetFolder', 'IncludeSubfolders', true, 'LabelSource', 'foldernames');
% Define the desired input size
inputSize = [224 224];
% Resize images to 224x224
inputSize = [224 224];
augmentedIMDS = augmentedImageDatastore(inputSize, imds);
% Use the transform function to resize images
augmentedIMDS = transform(imds, @(x)imresize(x, inputSize));
% Split the dataset into training, validation, and test sets
[trainingData, validationData, testingData] = splitEachLabel(augmentedIMDS, 0.8, 01, 01);
% Load the pretrained VGG16 model
net = vgg16;
I keep getting error for this part of the code:
% Split the dataset into training, validation, and test sets
[trainingData, validationData, testingData] = splitEachLabel(augmentedIMDS, 0.8, 01, 01);
when i change the directory to imds the error is about resizing "Incorrect input size. the input size must have a size of [224 224 3]" and when i change it to augmentedIMDS the error is "Incorrect number or types of inputs or outputs for function 'splitEachLabel'."
0 Comments
Accepted Answer
David Ho
on 5 Apr 2023
Hi Lalaine,
The "splitEachLabel" function only accepts ImageDatastores as an input. To make training, validation and test data of size [224 224], first split the imageDatastore, then transform it:
[imdsTrain, imdsValidation, imdsTest] = splitEachLabel(imds, 0.8, 0.1, 0.1);
inputSize = [224 224];
trainingData = augmentedImageDatastore(inputSize, imdsTrain);
validationData = augmentedImageDatastore(inputSize, imdsValidation);
testingData = augmentedImageDatastore(inputSize, imdsTest);
0 Comments
More Answers (1)
See Also
Categories
Find more on Image Data Workflows in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!