简体   繁体   中英

How to set prediction threshold in Keras?

I'm trained a model with Keras to do a binary classification task with 0 and 1 labels, and I tested it on a series of images. Some of these images are very similar and were predicted as 1, so I want to know is there a way to set some threshold or scores to sort out the images that most likely to be 1 in Keras?

if you are performing semantic segmentation then carry out the below method

perform

image = model.predict(your_input_image)
_,height,width,_ = image.shape()
image = image.reshape(height,width)
image[image >= threshold_percentage] = 255
image[image < threshold_percentage] = 0

if normal binary

result = model.predict(your_input_image)
if result[0][1] > threshold_percentage:
    #belongs to class 1
else:
    #belongs to class 2

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