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

推理得到的结果如何计算mIou指标 #28

Open
youngbaldy opened this issue Nov 24, 2023 · 6 comments
Open

推理得到的结果如何计算mIou指标 #28

youngbaldy opened this issue Nov 24, 2023 · 6 comments

Comments

@youngbaldy
Copy link

youngbaldy commented Nov 24, 2023

您好,我想在inference的时候将得到的result与gt计算miou等相关指标。现在我使用在potsdam上预训练的权重,在potsdam的验证集上进行推理,然后使用../mmseg/core/evaluation/metrics.py,计算得到的{'aAcc': array(0.04249801), 'IoU': array([0.06536244, 0.00681113, 0.0036782 , 0.02882337, 0.00158446]), 'Acc': array([0.34386185, 0.01245181, 0.00750425, 0.05191632, 0.00163203])},这似乎与您公布的在potsdam上的OA 91.1的相差甚远,我不太清楚该如何解决。期待您的回复。
以下是我的推理代码:
`image_root = "/data/user5/potsdam/img_dir/val"
ann_root = "/data/user5/potsdam/ann_dir/val"
image_list = os.listdir(image_root)
device = "cuda" if torch.cuda.is_available() else "cpu"
config = "../configs/vit_base_win/upernet_vitae_nc_base_rvsa_v3_kvdiff_wsz7_512x512_160k_potsdam_rgb_dpr10_lr6e5_lrd90_ps16_class5_ignore5.py"
checkpoint = "../pretrain_model/potsdam/vitae_rvsa_kvdiff.pth"
seg_model = init_segmentor(config, checkpoint, device=device)
num_classes = 5
ignore_index = 5
results = []
labels = []
for image in image_list:
# print(image)
image_path = os.path.join(image_root, image)
label_path = os.path.join(ann_root, image)
label = cv2.imread(label_path, 0)
_, masks = inference_segmentor(seg_model, image_path)
# print(masks[0])
copy_masks = masks[0]
results.append(copy_masks)
labels.append(label)

ret_metrics = eval_metrics( results, labels, num_classes, ignore_index, metrics='mIoU')
print(ret_metrics)
`

@DotWang
Copy link
Collaborator

DotWang commented Nov 24, 2023

@youngbaldy 推理精度评测用mmseg的命令,不需要手写

@youngbaldy
Copy link
Author

感谢您的回复,不过由于我第一次接触mmseg所以不太清楚,您方便的话可以给个例子吗?我现在需要对我处理过的图片进行推理,而且似乎也不能以batch的形式进行inference,我不太明白该怎么对推理得到的结果与label计算评价指标。期待您的回复,再次感谢。

@DotWang
Copy link
Collaborator

DotWang commented Nov 24, 2023

@youngbaldy 你可以参考一下rsp仓库,里边有说明,RVSA仓库只是提供必要的config和模型文件,执行文件都在RSP仓库(RVSA仓库说明中已经说了),另外,我们分割就是用的mmseg

@youngbaldy
Copy link
Author

感谢您的回复,我使用tools/convert_datasets/potsdam.py得到的mask标签值是0~6,但在configs/vit_base_win/upernet_vitae_nc_base_rvsa_v3_wsz7_512x512_160k_potsdam_rgb_dpr10_lr6e5_lrd90_ps16_class5_ignore5.py的配置文件中是num_classes =5,ignore_index=5,不应该都是6吗?期待您的回复

@DotWang
Copy link
Collaborator

DotWang commented Nov 24, 2023

@youngbaldy 我们处理这个potsdam数据集时和mmseg官方不太一样,你可以参考一下相关issue

ViTAE-Transformer/ViTAE-Transformer-Remote-Sensing#21

ViTAE-Transformer/ViTAE-Transformer-Remote-Sensing#9

@youngbaldy
Copy link
Author

感谢您的回复,我再仔细看看

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

2 participants