'Spyder python 3.9 AttributeError: 'NoneType' object has no attribute 'shape'
import os
import cv2
import pickle
from sklearn.cluster import KMeans
import numpy as np
train_path = './Train/'
class_list = os.listdir(train_path)
for i in range(len(class_list)):
image_list = os.listdir(os.path.join(train_path, class_list[i]))
for j in range(len(image_list)):
image = cv2.imread(os.path.join(train_path, class_list[i], image_list[j]))
sift = cv2.SIFT_create()
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
(kp, descs) = sift.detectAndCompute(gray, None)
descs_samples = descs[np.random.randint(descs.shape[0], size=20)]
I am trying to get sift features of 43 diffrent classes of images but for some reason when i try to use the command
descs_samples = descs[np.random.randint(descs.shape[0], size=20)]function i am getting this eror * AttributeError: 'NoneType' object has no attribute 'shape'* My friend was able to runs this code correctly but for some reason i can't.
I tried changing my files loaction and printing images to make sure they were actullay are getting read.I was able to see my images with print (image).
Solution 1:[1]
My friend wasn't using the same dataset so i tought there might be something wrong with it.After a bit of debugging i found that i wasn't able to get descropitores from some of the train images.So i isolated them. I lost around %10 of the dataset but now it works great. I am trying to figure out why i couldn't get descriptores from this %10.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mustafa Ya??z Özduygun |
