Error using vision.internal.Kdtree/index Invalid input class.
Mostra commenti meno recenti
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 Commenti
Domhnall Boyle
il 13 Mar 2018
Hi, I am having the same issue. Did you manage to solve this problem?
Suvidha Tripathi
il 17 Ott 2018
same problem!
Walter Roberson
il 17 Ott 2018
Could you post code the reproduces the problem?
Suvidha Tripathi
il 18 Ott 2018
I am using CNN for custom feature extraction and using BoF for feature selection.
imageDir=fullfile(oldfolder,dataset,newfold,strip(list2(subfold,:)));
imds=imageDatastore(imageDir);
imds=imageDatastore(imageDir,'Labels',labelIds);
imds.ReadFcn= @(loc)imresize3(imread(loc),[227 227 3]);
extractorFcn = @exampleBagofFeaturesExtractor;
FeatureBag=bagOfFeatures(imds,'CustomExtractor',extractorFcn,'vocabularySize',100);
function [features,featureMetric] = exampleBagofFeaturesExtractor(patchimds)
%patchimds.ReadFcn = @(loc)imresize3(imread(loc),[227 227 3]);
net = alexnet;
layer = 'pool5';
trainFeatures = activations(net,patchimds,layer,'OutputAs','rows','ExecutionEnvironment','gpu');
features=reshape(trainFeatures,[size(trainFeatures,1)*size(trainFeatures,2)*size(trainFeatures,3),size(trainFeatures,4)]);
% features=features';
featureMetric=var(features,[],2);
end
Creating Bag-Of-Features.
-------------------------
* Image category 1: 1
* Image category 2: 2
* Image category 3: 3
* Image category 4: 4
* Extracting features using a custom feature extraction function: exampleBagofFeaturesExtractor.
* Extracting features from 43735 images...done. Extracted 403061760 features.
* Keeping 80 percent of the strongest features from each category.
* Balancing the number of features across all image categories to improve clustering.
** Image category 3 has the least number of strongest features: 35278848.
** Using the strongest 35278848 features from each of the other image categories.
* Using K-Means clustering to create a 100 word visual vocabulary.
Starting parallel pool (parpool) using the 'local' profile ...
IdleTimeout has been reached.
Parallel pool using the 'local' profile is shutting down.
connected to 8 workers.
* Number of features : 141115392
* Number of clusters (K) : 100
* Initializing cluster centers...100.00%.
* Clustering...completed 0/100 iterations Error using vision.internal.approximateKMeans>assignDataToClustersSerial (line
172)
Invalid input class.
Error in vision.internal.approximateKMeans>assignDataToClustersParallel (line
214)
parfor n = 1:size(featuresCube,3)
Error in vision.internal.approximateKMeans>assignDataToClusters (line 151)
[assignments, dists, varargout{1:nargout-2}] =
assignDataToClustersParallel(features, centers, randState);
Error in vision.internal.approximateKMeans (line 73)
[assignments, dists, isValid] = assignDataToClusters(features, centers,
params);
Error in bagOfFeatures/createVocabulary (line 639)
clusterCenters = vision.internal.approximateKMeans(descriptors, K,
...
Error in bagOfFeatures (line 197)
this.Vocabulary = this.createVocabulary(descriptorSet, ...
Walter Roberson
il 18 Ott 2018
Is there a set of example folders to run this on?
Suvidha Tripathi
il 18 Ott 2018
the dataset is not publicly available, so I cannot share it. You can run this on any dataset like caltech101 for testing.
Suvidha Tripathi
il 18 Ott 2018
I must also mention that this same code was working fine few days ago, but unusually, this error started to occur now. Also, if I transpose the features matrix _ features_ (like I used to do earlier), then It is reducing the number of samples instead of trimming the feature vector. And consequently encoding feature vectors is giving me only ones and zeros. I am perplexed because the same methodology had been working well few days back. I am desperate for help.
Suvidha Tripathi
il 22 Ott 2018
Hi, no updates?
Walter Roberson
il 22 Ott 2018
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.
Walter Roberson
il 22 Ott 2018
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
il 23 Nov 2019
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);
Risposte (2)
Walter Roberson
il 23 Ott 2018
1 voto
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 Commenti
Walter Roberson
il 23 Ott 2018
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
il 23 Ott 2018
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
il 23 Gen 2019
0 voti
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.
Categorie
Scopri di più su Image Category Classification in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!