how to fix this issue through running the program?
Show older comments
i am using Matlab for medical image classification and i get this issue:
note: i used pre-trained network (alexnet) with .dicom files dataset.
first i prepare my design network
second, i run my code.
>> deepNetworkDesigner
>> SHIVANCLASSIFY
net =
SeriesNetwork with properties:
Layers: [25×1 nnet.cnn.layer.Layer]
InputNames: {'data'}
OutputNames: {'output'}
Error using trainNetwork (line 170)
The training images are of size 227x227x1 but the input layer expects images of size 227x227x3.
Error in SHIVANCLASSIFY (line 36)
net = trainNetwork(augimdsTrain,layers_1,options)
net=alexnet
imds = imageDatastore('lung dataset-Labeled', ...
'IncludeSubfolders',true, 'LabelSource','foldernames', ... % this for labeling by folder names
'FileExtensions','.dcm','ReadFcn',@readDicomDatastoreImage); % this a function
[imdsTrain,imdsValidation] = splitEachLabel(imds,0.7);
augmenter = imageDataAugmenter( ...
'RandRotation',[-20,20], ...
'RandXReflection',1,...
'RandYReflection',1,...
'RandXTranslation',[-3 3], ...
'RandYTranslation',[-3 3]);
%augimdsTrain = augmentedImageDatastore([224 224],imdsTrain,'DataAugmentation',augmenter);
%augimdsValidation = augmentedImageDatastore([224 224],imdsValidation,'DataAugmentation',augmenter);
augimdsTrain = augmentedImageDatastore([227 227],imdsTrain);
augimdsValidation = augmentedImageDatastore([227 227],imdsValidation);
options = trainingOptions('rmsprop', ...
'MiniBatchSize',10, ...
'MaxEpochs',20, ...
'InitialLearnRate',1e-3, ...
'Shuffle','every-epoch', ...
'ValidationData',augimdsValidation, ...
'ValidationFrequency',3, ...
'Verbose',false, ...
'Plots','training-progress');
net = trainNetwork(augimdsTrain,layers_1,options)
[YPred, probs] = classify(net,augimdsValidation);
accuracy = mean(YPred ==imdsValidation.Labels)
figure
cm=confusionchart (imdsValidation.Labels, YPred);
8 Comments
Walter Roberson
on 27 Mar 2020
dicom images are mostly grayscale, but that code is expecting to train on RGB.
You can promote a grayscale image to RGB by IMG = repmat(IMG,[1 1 3])
shivan artosh
on 27 Mar 2020
Walter Roberson
on 27 Mar 2020
Change readDicomDatastoreImage to include a repmat()
shivan artosh
on 27 Mar 2020
Walter Roberson
on 27 Mar 2020
function I = readDicomDatastoreImage(filename)
onState = warning('off', 'backtrace');
c = onCleanup(@() warning(onState));
I = dicomread(filename);
I = repmat(I, 1, 1, 3);
shivan artosh
on 27 Mar 2020
Walter Roberson
on 27 Mar 2020
Sorry, I do not know.
shivan artosh
on 28 Mar 2020
Accepted Answer
More Answers (0)
Categories
Find more on Deep Learning Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!