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

About IOU? #26

Open
qianyuli123 opened this issue Oct 29, 2024 · 1 comment
Open

About IOU? #26

qianyuli123 opened this issue Oct 29, 2024 · 1 comment

Comments

@qianyuli123
Copy link

When I was using the CRAG dataset for training and testing, I found that the final Dice score of 0.8737 was close to the 0.8831 in the paper. However, the IoU was only 0.779, which was quite different from the 0.8841 in the paper. Have you ever encountered such a situation? The following is my evaluation code:

import numpy as np
import albumentations as A
from PIL import Image
import matplotlib.pyplot as plt
import os
import csv
from medpy.metric.binary import dc,jc

def resize_mask(mask_path, target_size=(1536, 1536)):
mask = Image.open(mask_path)
transform = A.Compose([
A.Resize(target_size[1], target_size[0])
])
mask_np = np.array(mask)
mask_resized = transform(image=mask_np)["image"]
return mask_resized

def calculate_metrics_for_folders(folder1, folder2):
iou_values = []
dice_values = []

# 获取两个文件夹中的文件列表
file_list1 = os.listdir(folder1)
file_list2 = os.listdir(folder2)

for i in range(1,41):
    mask1_path = os.path.join(folder1,f"test_{i}_mask.png")
    mask2_path = os.path.join(folder2,f"test_{i}.png")
    # 调整两个掩码图像的大小
    mask1_resized = resize_mask(mask1_path)
    mask2_resized = resize_mask(mask2_path)

    # 调整掩码的类别
    mask1_resized = mask1_resized - 1

    # 计算IoU和Dice系数
    iou_value = jc(mask1_resized, mask2_resized)
    dice_value = dc(mask1_resized, mask2_resized)

    iou_values.append(iou_value)
    dice_values.append(dice_value)

# 计算IoU和Dice系数的平均值和方差
iou_mean = np.mean(iou_values)
iou_var = np.var(iou_values)
dice_mean = np.mean(dice_values)
dice_var = np.var(dice_values)

return iou_mean, iou_var, dice_mean, dice_var, iou_values, dice_values

if name == "main":
folder1 = "test_result/CRAG"
folder2 = "dataset/merged/mask"

iou_mean, iou_var, dice_mean, dice_var, iou_values, dice_values = calculate_metrics_for_folders(folder1, folder2)
@jingweizhang-xyz
Copy link
Member

It might have something to do with the definition of IoU, you can check the IoU in the main.py to see if it is the same as yours.

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