CheshtaK/Image-Classification

labels.append(labels_dict[label])

bincynadar opened this issue · 3 comments

Getting an error in this line

Hey @bincynadar! Apologies for the late reply.
Could you post the error log that you're receiving?

Hey @bincynadar! Apologies for the late reply.
Could you post the error log that you're receiving?


KeyError Traceback (most recent call last)
in ()
13 img_array = image.img_to_array(img)
14 image_data.append(img_array)
---> 15 labels.append(labels_dict[label])

KeyError: 'Images/dog'

To solve this issue, replace the following line of code:
label = str(folder_dir).split("\")[-1][:-1]
with:
label = os.path.basename(folder_dir).split("\")[-1][:-1]