How to resolve "Unable to determine if experiment is for classification or regression because setup function returned invalid outputs"?

5 次查看(过去 30 天)
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

回答(2 个)

Ben
Ben 2022-11-29
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
  1 个评论
Hamed
Hamed 2022-11-30
Hi thanks for your answer, though I dont think it can be the main source of issue, since I used single variable for data and still had the sam problem.

请先登录,再进行评论。


Michelle Patrick-Krueger
Hello Hamed,
I was having the same problem. This helped me solve it.
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)

类别

Help CenterFile Exchange 中查找有关 Image Data Workflows 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by