![](/img/trans.png)
[英]Keras AttributeError: 'Sequential' object has no attribute 'predict_classes'
[英]I get the error: " AttributeError: 'Sequential' object has no attribute 'predict_classes' " while coding. Its wrong here
def classify(file_path):
global label_packed
image = Image.open(file_path)
image = image.resize((30,30))
image = numpy.expand_dims(image, axis=0)
image = numpy.array(image)
pred = model.predict_classes(image)[0]
sign = classes[pred+1]
print(sign)
label.configure(foreground='#011638', text=sign)
更改:
model.predict_classes()
至
model.predict()
它會返回一個概率。 然后你應該定義一個閾值來考慮對其中一個類的預測概率。 請記住,閾值取決於您。 您可以對此嚴格或不嚴格。 但是,我認為它是 0.5:
pred_class = np.where(model.predict(example) > 0.5, 1, 0)
然后,您將獲得預測的類。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.