convolutional neural network for medical segmentation code

2 ビュー (過去 30 日間)
Mohamed Nasr
Mohamed Nasr 2020 年 4 月 27 日
回答済み: vaibhav mishra 2020 年 6 月 30 日
please this is my code and error is
labelCount =
2×2 table
Label Count
_____ _____
no 91
yes 154
Error using trainNetwork (line 170)
The validation images are of size 248x208x3 but the input layer expects images of size 201x173x3.
Error in ccn (line 51)
net = trainNetwork(imdsTrain,layers,options);
>> (what I do ?!)
clear all;
clc;
close all;
imds = imageDatastore('D:\matlab aml\dataset1','FileExtensions',{'.jpg'},'IncludeSubfolders',true,'LabelSource','foldernames');
imgs = readall(imds);
figure;
perm = randperm(200,20);%Display some of the images in the datastore.
for i = 1:20
subplot(4,5,i);
imshow(imds.Files{perm(i)});
end
img = readimage(imds,1); %Check the size of the first image in digitData. Each image is 201-by-173-by-3 pixels.
size(img)
%Specify Training and Validation Sets
labelCount = countEachLabel(imds) %Calculate the number of images in each category
numTrainFiles = 90;
[imdsTrain,imdsValidation] = splitEachLabel(imds,numTrainFiles,'randomize');
%Define the convolutional neural network architecture.
layers = [
imageInputLayer([201 173 3])
convolution2dLayer(3,8,'Padding','same')
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,'Stride',2)
convolution2dLayer(3,16,'Padding','same')
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,'Stride',2)
convolution2dLayer(3,32,'Padding','same')
batchNormalizationLayer
reluLayer
fullyConnectedLayer(2)
softmaxLayer
classificationLayer];
%Specify Training Options
options = trainingOptions('sgdm', ...
'InitialLearnRate',0.01, ...
'MaxEpochs',4, ...
'Shuffle','every-epoch', ...
'ValidationData',imdsValidation, ...
'ValidationFrequency',10, ...
'Verbose',false, ...
'Plots','training-progress');
%Train Network Using Training Data
net = trainNetwork(imdsTrain,layers,options);
YPred = classify(net,imdsValidation);
YValidation = imdsValidation.Labels;
accuracy = sum(YPred == YValidation)/numel(YValidation)

回答 (1 件)

vaibhav mishra
vaibhav mishra 2020 年 6 月 30 日
to resize all the images collectively,
you can use audimds=augmentedImageDatastore([201 173],imds);
read more-: https://in.mathworks.com/help/deeplearning/ref/augmentedimagedatastore.html

カテゴリ

Help Center および File ExchangeImage Data Workflows についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by