ViTAE-Transformer / Remote-Sensing-RVSA

The official repo for [TGRS'22] "Advancing Plain Vision Transformer Towards Remote Sensing Foundation Model"
MIT License
420 stars 32 forks source link

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

Open youngbaldy opened 12 months ago

youngbaldy commented 12 months ago

您好,我想在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 commented 12 months ago

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

youngbaldy commented 12 months ago

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

DotWang commented 12 months ago

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

youngbaldy commented 12 months ago

感谢您的回复,我使用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 commented 12 months ago

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

https://github.com/ViTAE-Transformer/ViTAE-Transformer-Remote-Sensing/issues/21

https://github.com/ViTAE-Transformer/ViTAE-Transformer-Remote-Sensing/issues/9

youngbaldy commented 12 months ago

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