convolutional neural network for medical segmentation code
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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)
0 comentarios
Respuestas (1)
vaibhav mishra
el 30 de Jun. de 2020
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
0 comentarios
Ver también
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!