Resizing images to 224*224 for training VGG16 Model

16 次查看(过去 30 天)
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);

更多回答(1 个)

asma abdulrahman
asma abdulrahman 2025-1-4
how i instell my network

类别

Help CenterFile Exchange 中查找有关 Image Data Workflows 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by