Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_mIoU计算评价指标得不到结果,只能计算背景(2分类 #85

Open
ladynine opened this issue Nov 17, 2023 · 0 comments
Open

Comments

@ladynine
Copy link

'''
进行指标评估需要注意以下几点:
1、该文件生成的图为灰度图,因为值比较小,按照JPG形式的图看是没有显示效果的,所以看到近似全黑的图是正常的。
2、该文件计算的是验证集的miou,当前该库将测试集当作验证集使用,不单独划分测试集
3、仅有按照VOC格式数据训练的模型可以利用这个文件进行miou的计算。
'''
出现的问题,混淆矩阵只有背景有结果
image
image

不过多说明细节了,被这个问题折磨了太久,也找了不少地方的问题,接下来直接说解决办法。

首先是2分类任务,背景+目标
输出了图像结果排查,发现

标签(VOCdevkit\VOC2007\SegmentationClass\xx.png)的图是这样的,目标部分标签255(白色),
image
image

但代码流程中预测出的图(路径miou_out\detection-results\xx.png)目标部分是1(灰度图,看上去是黑色的)(相当于没有mix可视化
image
image

观察混淆矩阵,发现背景确实是识别到了,但是另一个类别没有结果,感觉是这部分的问题(utils/utils_metrics.py/fask_hist函数),在这里用np.bincount计算的混淆矩阵

遂在utils/utils_metrics.py/compute_mIoU函数中,增加了一行代码转换了标签图的数值
(最差的办法

#------------------------------------------------#
        #   读取一张对应的标签,转化成numpy数组
        #------------------------------------------------#
        label = np.array(Image.open(gt_imgs[ind]))
        label = np.minimum(1, label) # 添加了此行代码将255转换到了1

最终得到了混淆矩阵,结果也能计算了,不过这个问题不应该在这里解决,只能就事论事来救急了
image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant