简体   繁体   English

如何在 Keras 中设置预测阈值?

[英]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.我用 Keras 训练了一个模型来执行带有 0 和 1 标签的二元分类任务,并在一系列图像上对其进行了测试。 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?其中一些图像非常相似并被预测为 1,所以我想知道有没有办法设置一些阈值或分数来整理 Keras 中最有可能为 1 的图像?

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

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

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