Exception in Tkinter callback Traceback (most recent call last): File "C:\python\lib\tkinter_init_.py", line 1921, in call return self.func(*args) File "C:\Users\umutc\PycharmProjects\pythonProject2\main.py", line 189, in classify_b = Button(top, text="Görseli Sınıflandır", command=lambda: classify(file_path), padx=10, pady=10) File "C:\Users\umutc\PycharmProjects\pythonProject2\main.py", line 171, in classify sign = classes[pred] TypeError: unhashable type: 'numpy.ndarray'
# Classifier Function / Sınıflandırma Fonksiyonu
def classify(file_path):
global label_packed
image = Image.open(file_path)
image = image.resize((32, 32))
image = numpy.expand_dims(image, axis=0)
pred = model.predict([image])[0]
sign = classes[pred]
print(sign)
CodePudding user response:
Based on comments, you appear to be trying to access a value a dictionary with an array. Of course that isn't going to work. The keys of classes are int, not arrays. And even if you used elements of pred rather than the entire object, the elements are float, not int. What you probably want is classes[max(range(len(pred)), key = lambda x: pred[x])]. This will find the largest value in pred, then find the index of that number, and then find the corresponding value in classes. I don't know what module model is from, but if you look up the documentation of that module, there's probably a more idiomatic way of getting this.

