trainNetwork error (input layer size)

5 visualizaciones (últimos 30 días)
sai
sai el 4 de Abr. de 2024
Comentada: Milan Bansal el 4 de Abr. de 2024
[trainedNet, traininfo] = trainNetwork(trainData, lgraph, options);
class = traindNet1;
save('class1.mat','class')
[trainedNet1, traininfo] = trainNetwork(trainData,lgraph,options);
class =trainedNet1;
save('class1.mat','class')
convnet = trainNetwork(trainData,layers,options);
load newtrain.mat
detector=new;
train1=deector;
load class1.mat
convnet=class;
error : trainNetwork
The size of the training images is 1024×1024×3. However, the input layer requires images of size 224×224×3.
error : argument3 (line 166)
[trainedNet, traininfo] = trainNetwork(trainData, lgraph, options);
I set the layer size to 224x224x3, but this error occurred.

Respuestas (1)

Milan Bansal
Milan Bansal el 4 de Abr. de 2024
Hi sai,
I understand that you are facing a size mismatch error while training a neural network using the "trainNetwork" function.
The error you're encountering indicates that there's a mismatch between the size of the training images (1024x1024x3) and the expected input size of the network (224x224x3). To address this issue, ensure that all your training images are resized to 224x224x3 before they are fed into the network for training.
This preprocessing step can be performed in MATLAB using the augmentedImageDatastore function, which allows you to automatically resize the images as they are input into the training function. Please refer to the code snippet below for resizing the images to the expected input size.
% Assuming trainData is an imageDatastore 1024x1024x3 images
inputSize = [224 224 3]; % The expected input size
% Create an augmentedImageDatastore to automatically resize the images
augmentedTrainData = augmentedImageDatastore(inputSize(1:2), trainData);
% Use augmentedTrainData in place of trainData for training
[trainedNet, trainInfo] = trainNetwork(augmentedTrainData, lgraph, options);
Please refer to the following documentation link to learn more about "augmentedImageDatastore" .
Hope this helps!
  2 comentarios
sai
sai el 4 de Abr. de 2024
Hi Milan Bansal,
I understand the problem.
imageSize = [224 224 3];
layers = [
imageInputLayer([224 224 3],'Name','input')
Even though I set the image size to 224x224x3, an error occurred.
Milan Bansal
Milan Bansal el 4 de Abr. de 2024
Actually the images in your dataset are of size 1024x1024x3 and your network is expecting the input images of size 224x224x3. You can either resize all the images in your training data to 224x224x3 as show in the answer above or change the input size of image input layer in the network to 1024x1024x3 as shown below to resolve the error.
layers = [
imageInputLayer([1024 1024 3],'Name','input')

Iniciar sesión para comentar.

Categorías

Más información sobre Image Data Workflows en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by