简体   繁体   中英

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:

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

Then, you'll get predicted classes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM