how do i change the size of the image

조회 수: 12 (최근 30일)
Asha kumar
Asha kumar 2021년 10월 8일
답변: Murad Alr 2022년 4월 22일
Hi.
i want to train my data set(X-ray images) using googlenet..when i m tring to do m getting this error.Could you please help me..
Error using trainNetwork (line 184)
The training images are of size 224×224×1 but the input layer expects images of size 224×224×3.
Error in training (line 44)
net = trainNetwork(Resized_Training_Dataset, New_Network, Training_Options);
  댓글 수: 5
KSSV
KSSV 2021년 10월 8일
Show us the whole code which you have tried.
Asha kumar
Asha kumar 2021년 10월 9일
Dataset = imageDatastore('Dataset', 'IncludeSubfolders', true, 'LabelSource', 'foldernames');
[Training_Dataset, Validation_Dataset, Testing_Dataset] = splitEachLabel(Dataset, 0.7, 0.15, 0.15);
net = googlenet;
analyzeNetwork(net)
Input_Layer_Size = net.Layers(1).InputSize(1:2);
Resized_Training_Dataset = augmentedImageDatastore(Input_Layer_Size ,Training_Dataset);
Resized_Validation_Dataset = augmentedImageDatastore(Input_Layer_Size ,Validation_Dataset);
Resized_Testing_Dataset = augmentedImageDatastore(Input_Layer_Size ,Testing_Dataset);
Feature_Learner = net.Layers(142).Name;
Output_Classifier = net.Layers(144).Name;
Number_of_Classes = numel(categories(Training_Dataset.Labels));
New_Feature_Learner = fullyConnectedLayer(Number_of_Classes, ...
'Name', 'Vehicle Feature Learner', ...
'WeightLearnRateFactor', 10, ...
'BiasLearnRateFactor', 10);
New_Classifier_Layer = classificationLayer('Name', 'Thorax disease Classifier');
Network_Architecture = layerGraph(net);
New_Network = replaceLayer(Network_Architecture, Feature_Learner, New_Feature_Learner);
New_Network = replaceLayer(New_Network, Output_Classifier, New_Classifier_Layer);
analyzeNetwork(New_Network)
Minibatch_Size = 2;
Validation_Frequency = floor(numel(Resized_Training_Dataset.Files)/Minibatch_Size);
Training_Options = trainingOptions('sgdm', ...
'MiniBatchSize', Minibatch_Size, ...
'MaxEpochs', 6, ...
'InitialLearnRate', 3e-4, ...
'Shuffle', 'every-epoch', ...
'ValidationData', Resized_Validation_Dataset, ...
'ValidationFrequency', Validation_Frequency, ...
'Verbose', false, ...
'Plots', 'training-progress');
net = trainNetwork(Resized_Training_Dataset, New_Network, Training_Options);

댓글을 달려면 로그인하십시오.

답변 (2개)

Image Analyst
Image Analyst 2021년 10월 8일
You're passing in a gray scale image when it wants a color image. When you resized them you also needed to convert them to color, like
rgbImage = cat(3, grayImage, grayImage, grayImage);
  댓글 수: 3
Image Analyst
Image Analyst 2021년 10월 9일
Get code snippets in the FAQ:
Asha kumar
Asha kumar 2021년 10월 9일
okay.thank you

댓글을 달려면 로그인하십시오.


Murad Alr
Murad Alr 2022년 4월 22일
Resized_Training_Image=augmentedImageDatastore(Input_Layer_Size,Training_Dataset,'ColorPreprocessing','gray2rgb');
Resized_Validation_Image=augmentedImageDatastore(Input_Layer_Size,Validation_Dataset,'ColorPreprocessing','gray2rgb');

카테고리

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