convolutional neural network for medical segmentation code
    8 次查看(过去 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)
0 个评论
回答(1 个)
  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
0 个评论
另请参阅
类别
				在 Help Center 和 File Exchange 中查找有关 Deep Learning Toolbox 的更多信息
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!