Resizing images to 224*224 for training VGG16 Model

13 ビュー (過去 30 日間)
Lalaine
Lalaine 2023 年 4 月 4 日
回答済み: David Ho 2023 年 4 月 5 日
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'."

採用された回答

David Ho
David Ho 2023 年 4 月 5 日
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 件)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by