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

조회 수: 3 (최근 30일)
Pradip Gupta
Pradip Gupta 2017년 3월 16일
댓글: Raju Pal 2019년 11월 23일
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
Dr. Murtaza Ali Khan 2019년 1월 23일
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