trainNetwork error (input layer size)
조회 수: 5 (최근 30일)
이전 댓글 표시
[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.
댓글 수: 0
답변 (1개)
Milan Bansal
2024년 4월 4일
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
Milan Bansal
2024년 4월 4일
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')
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Data Workflows에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!