简体   繁体   English

编码时出现错误:“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) 

Change the:更改:

model.predict_classes() 

to

model.predict() 

and it'll return a probability.它会返回一个概率。 Then you should define a threshold to consider prediction probabilities to one of the classes.然后你应该定义一个阈值来考虑对其中一个类的预测概率。 Remember that threshold is up to you.请记住,阈值取决于您。 You can be strict about that or not.您可以对此严格或不严格。 However, I suppose it to be 0.5:但是,我认为它是 0.5:

pred_class = np.where(model.predict(example) > 0.5, 1, 0)

Then, you'll get predicted classes.然后,您将获得预测的类。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Keras AttributeError: 'Sequential' object 没有属性 'predict_classes' - Keras AttributeError: 'Sequential' object has no attribute 'predict_classes' AttributeError: 'Sequential' object 没有属性 'predict_classes'/ - AttributeError: 'Sequential' object has no attribute 'predict_classes'/ AttributeError: 'Sequential' object 没有属性 'predict_classes' - AttributeError: 'Sequential' object has no attribute 'predict_classes' 即使使用顺序 model,我也会收到“AttributeError: 'Model' object has no attribute 'predict_classes'” - Even when using Sequential model, I am getting “AttributeError: 'Model' object has no attribute 'predict_classes' ” AttributeError:“功能”对象没有属性“predict_classes” - AttributeError: 'Functional' object has no attribute 'predict_classes'' AttributeError:“功能”object 没有属性“predict_classes” - AttributeError: 'Functional' object has no attribute 'predict_classes' AttributeError: 'History' 对象没有属性 'predict_classes' - AttributeError: 'History' object has no attribute 'predict_classes' pred = model.predict_classes([prepare(file_path)]) AttributeError: 'Functional' object 没有属性 'predict_classes' - pred = model.predict_classes([prepare(file_path)]) AttributeError: 'Functional' object has no attribute 'predict_classes' 我收到此错误 --> AttributeError: 'NoneType' object has no attribute 'predict' - I get this error --> AttributeError: 'NoneType' object has no attribute 'predict' 我正在尝试让 elasticsearch 和 flask 工作。 这是错误 AttributeError: 'function' object has no attribute 'elasticsearch' - I am trying to get elasticsearch and flask to work. Here is the error AttributeError: 'function' object has no attribute 'elasticsearch'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM