Error using vision.int​ernal.Kdtr​ee/index Invalid input class.

3 次查看(过去 30 天)
Error using bagOfFeatures. It was earlier working fine but suddenly it stopped. I am using custom extractor function.
extractorFcn= @calcFeatures;
bag = bagOfFeatures(trainingSet,'CustomExtractor',extractorFcn,'VocabularySize',500);
% function [T, TMetric] = calcFeatures(pic) Custom Extractor looks like this
The Error I get is:
Clustering...completed 0/100 iterations Error using vision.internal.Kdtree/index
Invalid input class.
Error in vision.internal.approximateKMeans>assignDataToClustersSerial (line 172)
searcher.index(centers);
Error in vision.internal.approximateKMeans>assignDataToClusters (line 153)
[assignments, dists, varargout{1:nargout-2}] = assignDataToClustersSerial(features, centers, randState);
Error in vision.internal.approximateKMeans (line 73)
[assignments, dists, isValid] = assignDataToClusters(features, centers, params);
Error in bagOfFeatures/createVocabulary (line 640)
clusterCenters = vision.internal.approximateKMeans(descriptors, K, ...
Error in bagOfFeatures (line 197)
this.Vocabulary = this.createVocabulary(descriptorSet, ...
  11 个评论
Walter Roberson
Walter Roberson 2018-10-22
I chopped out a lot of images and was able to trigger the input class problem you mention. Unfortunately it also triggered a MATLAB kernel crash, so I am trying again.
Raju Pal
Raju Pal 2019-11-23
I have faced the problem in knn search when using alexnet features
* Clustering...completed 0/100 iterations Error using vision.internal.Kdtree/index
Invalid input class.
Error in vision.internal.approximateKMeans>assignDataToClustersSerial (line 172)
searcher.index(centers);
Error in vision.internal.approximateKMeans>assignDataToClusters (line 153)
[assignments, dists, varargout{1:nargout-2}] = assignDataToClustersSerial(features, centers, randState);
Error in vision.internal.approximateKMeans (line 73)
[assignments, dists, isValid] = assignDataToClusters(features, centers, params);

请先登录,再进行评论。

回答(2 个)

Walter Roberson
Walter Roberson 2018-10-23
Digging into this: that error is being triggered by the fact that the features array that vision.internal.approximateKMeans is being asked to work on is a single column; it is expecting a minimum of two columns.
I am still tracing through to figure out what the one column is at that point, and why it is not multiple columns.
  2 个评论
Walter Roberson
Walter Roberson 2018-10-23
Your exampleBagofFeaturesExtractor uses activations('OutputAs','rows'), which is going to return either a vector or a 2D array. But the next line does
features=reshape(trainFeatures,[size(trainFeatures,1)*size(trainFeatures,2)*size(trainFeatures,3),size(trainFeatures,4)]);
which will reduce anything of less than 4 dimensions into a column vector.
There is a transpose in the next line, but it is commented out, so the output is a single column.
If the output were a row instead of a column, then that would have succeeded in the approximateKMeans -- just watch out for which dimension you are taking the feature metric relative to.
Suvidha Tripathi
Suvidha Tripathi 2018-10-23
Yes, You are right. I ran the example code by MATLAB, and figured out the error yesterday. I corrected it by reshaping my array like this
features=reshape(trainFeatures,[size(trainFeatures,1)*size(trainFeatures,2) ,size(trainFeatures,3),size(trainFeatures,4)]);
This worked for me. Thank you for your time.

请先登录,再进行评论。


Dr. Murtaza Ali Khan
I got the same error when my features matrix was of size M-by-1 in the custom feature extractor function. I changed it to size 1-by-M then the error did not appear.

Community Treasure Hunt

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

Start Hunting!

Translated by