How can i combine 3 datastore? and how can i improve accuracy

2 Ansichten (letzte 30 Tage)
dziri halima
dziri halima am 5 Jun. 2020
I have 64 image in datastores (imds), I wish augmet data by using imageDataAugmenter and denoisingImageDatastore and improve the validation accuracy.
Error using trainNetwork (line 165)
All tables in the bracketed expression must have the same number of rows.
Error in combindata (line 130)
net2 = trainNetwork(imdsCombined,layers,options);
Caused by:
Error using matlab.io.datastore.CombinedDatastore/read (line 109)
All tables in the bracketed expression must have the same number of rows.
imds = imageDatastore(fullfile(rootFolder, categories), 'LabelSource', 'foldernames');
inputSize = [64 64];
imds.ReadFcn = @(loc)imresize(imread(loc),inputSize);
imshow(preview(imds));
labelCount = countEachLabel(imds);
numClasses = height(labelCount);
%% Create training and validation sets
[imdsTrainingSet, imdsValidationSet] = splitEachLabel(imds, 0.7, 'randomize');
%% Build a simple CNN
imageSize = [64 64 3];
% Specify the convolutional neural network architecture.
layers = [
imageInputLayer(imageSize)
convolution2dLayer(3,16,'Padding','same')
batchNormalizationLayer
reluLayer
convolution2dLayer(3,5,'Padding','same')
batchNormalizationLayer
reluLayer
convolution2dLayer(3,32,'Padding','same')
batchNormalizationLayer
reluLayer
fullyConnectedLayer(2)
softmaxLayer
classificationLayer]
%% Specify training options %
options = trainingOptions('sgdm', ...
'MiniBatchSize',300, ...
'MaxEpochs',500, ...
'InitialLearnRate',1e-2, ...
'Shuffle','every-epoch', ...
'ValidationData',imdsValidationSet, ...
'ValidationFrequency',3, ...
'Verbose',false, ...
'L2Regularization',0.0001,...
'Plots','training-progress');
%%%%%%************Augmented data**************************
%% Create augmented image data store
% Specify data augmentation options and values/ranges
imageAugmenter = imageDataAugmenter( ...
'RandRotation',[-20,20], ...
'RandXTranslation',[-3 3], ...
'RandYTranslation',[-3 3]);
% Apply transformations (using randomly picked values) and build augmented
% data store
augImds = augmentedImageDatastore(imageSize,imdsTrainingSet, ...
'DataAugmentation',imageAugmenter);
dnimds = denoisingImageDatastore(imdsTrainingSet,...
'PatchesPerImage',512,...
'PatchSize',64,...
'GaussianNoiseLevel',[0.01 0.1],...
'ChannelFormat','rgb')
imdsCombined = combine(imds,augImds,dnimds)
% % (OPTIONAL) Preview augmentation results
% batchedData = preview(augImds);
% figure, imshow(imtile(batchedData.input))
%
% %% Train the network.
net2 = trainNetwork(imdsCombined,layers,options);
%% Report accuracy of baseline classifier with image data augmentation
YPred = classify(net2,imdsValidationSet);
YValidation = imdsValidationSet.Labels;
augImdsAccuracy = sum(YPred == YValidation)/numel(YValidation);
%% Plot confusion matrix
figure, plotconfusion(YValidation,YPred)

Antworten (0)

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by