How to resolve "Unable to determine if experiment is for classification or regression because setup function returned invalid outputs"?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello,
I wanted to use Alexnet for transfer learning and in the meantime, I was going to tune initial learning rate using Baysian hyper paramter tuning in experiment manager. I have defined the function as below, even though when I run experiment it shows and error saying " Unable to determine if experiment is for classification or regression because setup function returned invalid outputs. Layers argument must be an array of layers or a layer graph." I cannot find out what I did wrong and how should I resove this issue, so any help would be highly appreciated.
function [aug_traData,aug_valData,Laye,options] = BayesOptExperiment_setup2(params)
imds=imageDatastore('C:\Users\hamedm1\Documents\MATLAB\final',...
'IncludeSubfolders',true,'LabelSource','foldernames');
[traData, valData] = splitEachLabel(imds, 0.8, 'randomized');
N=227;
M=227;
aug_traData = augmentedImageDatastore([N M], traData);
aug_valData = augmentedImageDatastore([N M], valData);
labelCount = countEachLabel(imds); %newly added to count number of
Num_out_class=numel(labelCount(:,1));
net = alexnet;
LL=net.Layers(1:end-3);
Lay=[LL
fullyConnectedLayer(Num_out_class,'WeightLearnRateFactor',20,'BiasLearnRateFactor',20,'name','bb')
softmaxLayer('name','cc')
classificationLayer('name','dd')];
lgraph = layerGraph(Lay);
Laye=lgraph.Layers;
miniBatchSize = 18;
validationFrequency = 10;
options = trainingOptions('sgdm', ...
'InitialLearnRate',params.InitialLearnRate, ...
'MiniBatchSize',miniBatchSize,...
'Shuffle','every-epoch','ValidationData',aug_valData,...
'LearnRateSchedule','piecewise','ValidationFrequency',validationFrequency,...
'Plots','training-progress');
end
0 Kommentare
Antworten (2)
Ben
am 29 Nov. 2022
I think the issue is that the 2nd returned output of BayesOptExperiment_setup2 needs to be the layer array or layerGraph object - in your case you've returned the validation data. As far as I can tell that shouldn't be necessary, for example see the setup function in Appendix 1 of the ofllowing example
https://www.mathworks.com/help/deeplearning/ug/experiment-using-bayesian-optimization.html
Michelle Patrick-Krueger
am 3 Dez. 2022
Hello Hamed,
The function that MATLAB gives has outputs:
function [TrainingData, layers, options] = Experiment_setup(params)
Change it to this and see if it helps:
function [XTrain, YTrain, layers, options] = Experiment_setup(params)
Siehe auch
Kategorien
Mehr zu Image Data Workflows finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!