MATLAB Answers


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

Asked by Pradip Gupta on 16 Mar 2017
Latest activity Answered by Dr. Murtaza Khan on 23 Jan 2019
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)
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, ...


Unfortunately current versions of MATLAB require a GPU driver that is later than any compatible with my operating system.
I was able to pull up a version of MATLAB that was new enough to have alexnet and imresize3() but also still supported GPU on my OS.
I loaded down caltech101 and modified your code to use it. I encountered a problem in that some of the images in it are grayscale, including only the second grayscale .jpg image I have ever seen that was not just a proof of concept to show that such images were possible. But I encountered a problem / limitation with imresize3() that I had to work around.
Now my GPU is busy analayzing 9144 images, and will need to get through those before the kdtrees problem can possibly show up. And if I need to retest, it will need to re-analyze 9144 images again...
This is not exactly convenient for a volunteer running on a single 5 year old desktop.
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.

Sign in to comment.

2 Answers

Answer by Walter Roberson
on 23 Oct 2018

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.


Your exampleBagofFeaturesExtractor uses activations('OutputAs','rows'), which is going to return either a vector or a 2D array. But the next line does
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.
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.

Sign in to comment.

Answer by Dr. Murtaza Khan on 23 Jan 2019

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.


Sign in to comment.