Error using classreg.learning.FitTemplate/fillIfNeeded (line 612) ObservationIn is not a valid parameter name.?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
when i execute this code, Matlab shows this error
OutputFolder = fullfile('caltech101');
rootfolder=fullfile(OutputFolder,'101_ObjectCategories');
Categories={'airplanes','ferry','laptop'};
imds=imageDatastore(fullfile(rootfolder,Categories),'labelsource','foldername');%,'IncludeSubfolders',true
%imds=imageDatastore(fullfile(rootfolder),'IncludeSubfolders',true,'labelsource','foldername');
tbl = countEachLabel(imds);
minSetCount =min(tbl{:,2});
imds=splitEachLabel(imds,minSetCount,'randomize');
countEachLabel(imds);
net = resnet50();
plot(net)
set(gca,'Ylim',[150 170])
net.Layers(1)
numel(net.Layers(end).ClassNames)
[TrainingSet,TestSet]=splitEachLabel(imds,0.3,'randomize');
ImageSize=net.Layers(1).InputSize;
augmentedTrainingSet=augmentedImageDatastore(ImageSize,TrainingSet,...
'ColorPreprocessing','gray2rgb');
augmentedTestSet=augmentedImageDatastore(ImageSize,TestSet,...
'ColorPreprocessing','gray2rgb');
% w1= net.Layers(2).Weights;
% w1=mat2gray(w1);
% figure
% montage(w1);
% title('first convolution layer weight');
featureLayer='fc1000';
trainingFeature= activations(net,...
augmentedTrainingSet,featureLayer,'MiniBatchSize',32,'OutputAs','Columns');
trainingLabeles=TrainingSet.Labels;
classifier=fitcecoc(trainingFeature,trainingLabeles,...
'Learner','Linear','Coding','onevsall','ObservationIn','Columns');
testFeature=activations(net,...
augmentedTestSet,featureLayer,'MiniBatchSize',32,'OutputAs','Columns');
predictLabel=predict(classifier,testFeature,'ObservationsIn','columns');
testLabels=TestSet.Labels;
confusionmat(testLabels,predictLabel)
Error using classreg.learning.FitTemplate/fillIfNeeded (line 612)
ObservationIn is not a valid parameter name.
Error in classreg.learning.FitTemplate.make (line 124)
temp = fillIfNeeded(temp,type);
Error in ClassificationECOC.template (line 111)
temp = classreg.learning.FitTemplate.make('ECOC','type','classification',varargin{:});
Error in ClassificationECOC.fit (line 115)
temp = ClassificationECOC.template(varargin{:});
Error in fitcecoc (line 329)
obj = ClassificationECOC.fit(X,Y,ecocArgs{:});
Error in classification (line 31)
classifier=fitcecoc(trainingFeature,trainingLabeles,...
0 comentarios
Respuestas (1)
sanidhyak
el 25 de Jun. de 2025
I understand that you are trying to train a classifier using MATLAB’s "fitcecoc" function with features extracted from a deep network, and you are encountering an error regarding the "ObservationsIn" parameter.
When running the code you provided, I too encountered a similar issue. This error arises because the "fitcecoc" function does not recognize "ObservationsIn" as a valid name-value argument. Also, the features extracted using the "activations" function with "OutputAs, Columns" are stored in a format where each column represents one observation. However, "fitcecoc" expects the data in a "rows = observations", "columns = features" format.
To resolve this issue, you simply need to transpose your feature matrices before passing them to the "fitcecoc and "predict" functions, and remove the unsupported "ObservationsIn" argument.
Please do refer to the corrected code below:
% Train the classifier (transpose feature matrix)
classifier = fitcecoc(trainingFeature', trainingLabeles, ...
'Learner', 'Linear', 'Coding', 'onevsall');
% Predict labels for test data (transpose again)
predictLabel = predict(classifier, testFeature');
This resolves the "ObservationIn is not a valid parameter name" error and ensures the input format aligns with "fitcecoc" function's expectations. The transpose "(' )" operation transforms the feature matrix from "columns-as-observations" to the correct "rows-as-observations" format.
For further reference on the "fitcecoc" function, kindly refer to the following official documentation:
Cheers & Happy Coding!
0 comentarios
Ver también
Categorías
Más información sobre Get Started with Deep Learning Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!