MATLAB Answers

0

Error using trainNetwork Unexpected image size: All images must have the same size.

hammad younas 님이 질문을 제출함. 9 Oct 2019
최근 활동 hammad younas 님이 편집함. 9 Oct 2019
Hello all i hope you are all doing well
i have all coloured images of 256x256 when i give this to input layer it gives following error
Error using trainNetwork (line 165)
Unexpected image size: All images must have the same size.
Error in imdstrain (line 49)
net = trainNetwork(imdsTrain,layers,options);
Can anybody help me in that please
my Code is given below:
imagedata='E:\data ML\NEW DATA IMAGES';
imds = imageDatastore(imagedata,'IncludeSubfolders',true,'FileExtensions','.jpg','LabelSource','foldernames')
fileList = imds.Files
T=countEachLabel(imds)
imgtotal=length(imds.Files)
img = readimage(imds,1);
size(img)
numTrainFiles = .75;
[imdsTrain,imdsValidation] = splitEachLabel(imds,numTrainFiles,'randomize');
%%%%%%%code for resizing
%% Configurar a rede neural
layers = [
imageInputLayer([256 256 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,512,'Padding','same')
batchNormalizationLayer
reluLayer
fullyConnectedLayer(7)
softmaxLayer
classificationLayer];
options = trainingOptions('sgdm', ...
'InitialLearnRate',0.01, ...
'MaxEpochs',1, ...
'Shuffle','every-epoch', ...
'ValidationData',imdsValidation, ...
'ValidationFrequency',30, ...
'Verbose',false, ...
'Plots','training-progress');
net=trainNetwork(imdsTrain,layers,options);
YPred = classify(net,imdsValidation);
YValidation = imdsValidation.Labels;
accuracy = sum(YPred == YValidation)/numel(YValidation)

  댓글 수: 0

로그인 to comment.

태그

답변 수: 0


Translated by