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