Python. K-nearest neighbour TypeError: samples data type = 17 is not supported

asked 2016-04-29 17:00:49 -0600

sotoglzz gravatar image

I'm trying to classify some images using SIFT for detect and compute keypoints and descriptors, and then use KNN for classify them into python interpreter:

## Detect keypoints and compute descriptors for train images
for file in files:
    ima = cv2.imread(file)
    kpts, des = sift.detectAndCompute(gray, None) 

## Train knn
dsc_train = np.array(dsc_train)
responses = np.arange(len(kp_train),dtype = np.float32)
knn =
knn.train(dsc_train,, responses)

But I'm a little stuck with the next error:

>>> knn.train(dsc_train,,responses)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: dsc_train data type = 17 is not supported

I really don't know how can fix this. Any help would be great. files is a list with 10 images, so the loop detects and computes keypoints and descriptor for each image. Thanks

edit retag flag offensive close merge delete


btw, you can't use a keypoint array for responses, instead your current approach would require one integer label per (sift) feature.

but this way, you'd lose the connection between features and images, i do not think, you'll get far like this.

usually, BOW is used to overcome those issues, please read up on it.

berak gravatar imageberak ( 2016-04-30 02:44:15 -0600 )edit

Thanks for the comment berek, I've read something of BOW before, I'm currently learning about computer image classify, so I'm doing this just for understand machine learning. Thanks.

sotoglzz gravatar imagesotoglzz ( 2016-04-30 13:01:29 -0600 )edit