this code fails with one file and one sub-folder https://ww​w.mathwork​s.com/help​/deeplearn​ing/ug/tra​in-deep-le​arning-net​work-to-cl​assify-new​-images.ht​ml#

1 visualización (últimos 30 días)
I'm trying to run this code see also the copy&paste below. For that purpose I've created a folder in myPath with the name "Orig_normal_D".
Inside this folder I have created a file 460.png and subfolder aktivni with a file with the same name 460.png.
Now, after training and evaulating I expected that there should be a 100% accurracy and 0% Loss.
Instead I'm getting an error as below (I do not follow what's wrong with it and how to fix it):
It is perfectly OK (without an error) with 2 subfolders and different single images in each of them, but for the thing that it reports
0% or 50% accuracy and never otherwise say never 100%. This is also strange BTW. My m-file is called sebest.m
>> sebest
ans =
ClassificationOutputLayer with properties:
Name: 'output'
Classes: [1000×1 categorical]
ClassWeights: 'none'
OutputSize: 1000
Hyperparameters
LossFunction: 'crossentropyex'
Error using nnet.cnn.TrainingOptionsADAM (line 134)
The value of 'ValidationData' is invalid. No more data to read. Use reset method to reset to
start of data. Use the hasdata method to check if data is available to read.
Error in trainingOptions (line 326)
opts = nnet.cnn.TrainingOptionsADAM(varargin{:});
Error in sebest (line 45)
options = trainingOptions('adam', ...
****************************************************************************************************************************************************************
MY CODE IS AS BELOW
****************************************************************************************************************************************************************
imds = imageDatastore('Orig_normal_D', ...
'IncludeSubfolders',true, ...
'LabelSource','foldernames');
[imdsTrain,imdsValidation] = splitEachLabel(imds,0.64);
net=googlenet();
net.Layers(144)
inputSize = net.Layers(1).InputSize;
lgraph = layerGraph(net);
[learnableLayer,classLayer] = findLayersToReplace(lgraph);
numClasses = numel(categories(imdsTrain.Labels));
if isa(learnableLayer,'nnet.cnn.layer.FullyConnectedLayer')
newLearnableLayer = fullyConnectedLayer(numClasses, ...
'Name','new_fc', ...
'WeightLearnRateFactor',1, ...
'BiasLearnRateFactor',1);
elseif isa(learnableLayer,'nnet.cnn.layer.Convolution2DLayer')
newLearnableLayer = convolution2dLayer(1,numClasses, ...
'Name','new_conv', ...
'WeightLearnRateFactor',1, ...
'BiasLearnRateFactor',1);
end
lgraph = replaceLayer(lgraph,learnableLayer.Name,newLearnableLayer);
newClassLayer = classificationLayer('Name','new_classoutput');
lgraph = replaceLayer(lgraph,classLayer.Name,newClassLayer);
figure('Units','normalized','Position',[0.3 0.3 0.4 0.4]);
plot(lgraph)
ylim([0,10])
layers = lgraph.Layers;
connections = lgraph.Connections;
layers(1:10) = freezeWeights(layers(1:10));
lgraph = createLgraphUsingConnections(layers,connections);
pixelRange = [-30 30];
scaleRange = [0.9 1.1];
imageAugmenter = imageDataAugmenter( ...
'RandXReflection',true, ...
'RandXTranslation',pixelRange, ...
'RandYTranslation',pixelRange, ...
'RandXScale',scaleRange, ...
'RandYScale',scaleRange);
augimdsTrain = augmentedImageDatastore(inputSize(1:2),imdsTrain, ...
'DataAugmentation',imageAugmenter);
augimdsValidation = augmentedImageDatastore(inputSize(1:2),imdsValidation);
miniBatchSize = 1;
valFrequency = floor(numel(augimdsTrain.Files)/miniBatchSize);
options = trainingOptions('adam', ...
'MiniBatchSize',miniBatchSize, ...
'MaxEpochs',8, ...
'InitialLearnRate',30e-4, ...
'Shuffle','never', ...
'ValidationData',augimdsValidation, ...
'ValidationFrequency',valFrequency, ...
'Verbose',true, ...
'Plots','training-progress');
net = trainNetwork(augimdsTrain,lgraph,options)

Respuesta aceptada

Walter Roberson
Walter Roberson el 30 de Oct. de 2023
If you only have one input then splitting is not going to work.
Note also that if you only have data for one class then training will probably fail.
  1 comentario
Jan
Jan el 30 de Oct. de 2023
Editada: Jan el 30 de Oct. de 2023
For my curiosity:
How can I achieve a constant 100% accuracy ? By which setting, i.e. how many subfolders with Orgig_normal_D and how many files in it, which for this purpose, I assume, should be copies of the very same file ?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Image Data Workflows en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by