フィルターのクリア

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

6 ビュー (過去 30 日間)
Hamed
Hamed 2022 年 11 月 28 日
コメント済み: Hamed 2022 年 12 月 5 日
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)
  1 件のコメント
Hamed
Hamed 2022 年 12 月 5 日
Hi Michelle thanks for your answer, even though I already done it if you see the output of my function.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeImage Data Workflows についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by