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
Michelle Patrick-Krueger 2022년 12월 3일
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