I am getting 0 percent accuracy when using 3-fold cross validation
2 views (last 30 days)
Show older comments
I want to train a CNN that will be k-fold cross-validated. for that, I have divided my signature data set in three equal part. using the two parts training is happening and from the remaining part, testing will be performed. this process will be done three times as k=3. I am using 3-fold cross validation in Matlab. but when I test the network it is giving 0% accuracy how it can be possible. can someone please help me what is the mistake I am making?
k = 3; % number of folds
datastore = imageDatastore(fullfile('/media/titan/ACER DATA/GPDS300'), 'IncludeSubfolders', true, 'LabelSource', 'foldernames');
partStores{k} = [];
for i = 1:k
temp = partition(datastore, k, i);
partStores{i} = temp.Files;
end
layers = [imageInputLayer([64 128 3]);
convolution2dLayer(7,40);
reluLayer();
fullyConnectedLayer(200);
softmaxLayer();
classificationLayer()];
options = trainingOptions('sgdm','MaxEpochs',150,'minibatchsize',32,'InitialLearnRate',0.001);
for i = 1:k
test_idx = (idx == i);
train_idx = ~test_idx;
test_Store = imageDatastore(partStores{test_idx}, 'IncludeSubfolders', true,
'LabelSource', 'foldernames');
train_Store = imageDatastore(cat(1, partStores{train_idx}),
'IncludeSubfolders', true, 'LabelSource', 'foldernames');
net{i} = trainNetwork(train_Store, layers, options);
pred{i} = classify(net{i}, test_Store);
TTest=test_Store.Labels;
accuracyn{i} = sum(pred{i} == TTest)/numel(TTest)
end
0 Comments
Answers (0)
See Also
Categories
Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!