here is my code:https://drive.google.com/open?id=17VMRjbIU0u-H0gwd2BuMjEyj21Oi_Ndg
I dont understand the error during data preprocessing
Hey @shreyanarula3,
I think you have mistakenly attached a blank .ipynb file. Request you to attach your updated code and I’ll look into it right away.
def classWiseData(x,y):
data = {}
for i in range(CLASSES):
data[i] = []
for i in range(x.shape[0]):
data[y[i]].append(x[i])
for k in data.keys():
data[k] = np.array(data[k])
return data
In this function, you have initialized the data dictionary with numerical keys (range(CLASSES)). While appending data, you are accessing the corresponding string value of the class (y is a vector of strings). This generates a key error as the key you are trying to access does not exist.
Hope this helps!
Then why did it work in image classification project
It depends on the dataset. If the dataset is already label encoded (each class is assigned a numerical value), then your code won’t generate an error. Checkout this function: Label Encoder
Encode your labels before doing any preprocessing to avoid such errors.
Hope this resolved your issue!