Stack Exchange
How can I deal with "AttributeError: 'NoneType' object has no attribute 'shape'"
I wrote this code and get error below:
"AttributeError: 'NoneType' object has no attribute 'shape'"
how can I solve the problem?
categories = []
image_name = []
image_id = []
image_format = []
labels = []
img_path = []
img_height = []
img_width = []

for cat in classes:
    path = os.path.join(TRAIN_DIR, cat, "*")
    data = glob.glob(path)
    for i in range(len(data)):
        h, w, c = cv2.imread(data[i]).shape
        cls , img = data[i].split('/')[-2:]
        img_id , img_format = img.split('.')
        img_height.append(h)
        img_width.append(w)
        categories.append(cls)
        image_name.append(img)
        image_id.append(img_id)
        image_format.append(img_format) 
        labels.append(class2label[cls])
        img_path.append(data[i])


It means cv2.imread(data[i]) return None at some point.

Don't use .shape with a None object?

Check if your TRAIN_DIR and your classes are correct.

Please include traceback
