percy
percy

Reputation: 21

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?

Upvotes: 1

Views: 5235

Answers (1)

thefifthjack005
thefifthjack005

Reputation: 638

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

Upvotes: 2

Related Questions