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
댓글 수: 0
답변 (2개)
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
Michelle Patrick-Krueger
2022년 12월 3일
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)
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Data Workflows에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!