Calculating DCS and IoU of different channels of a segmentation at once #7156
-
Hello, I'm a novice in AI and image segmentation. Previousely, I'd used this code in for this task: if len(devices) > 1:
model = torch.nn.DataParallel(model, device_ids=devices)
post_label = Compose([AsDiscrete(to_onehot=3)])
model.eval()
with torch.no_grad():
for val_data in val_loader:
val_inputs, val_labels = val_data["image"].to(device), val_data["label"].to(device)
# define sliding window size and batch size for windows inference
roi_size = (128, 128, 128)
sw_batch_size = 4
val_outputs = sliding_window_inference(val_inputs, roi_size, sw_batch_size, model)
val_outputs = [post_pred(i) for i in decollate_batch(val_outputs)]
val_labels = [post_label(i) for i in decollate_batch(val_labels)]
# compute metric for current iteration
dice_metric(y_pred=val_outputs, y=val_labels)
for val_output_dice in val_outputs:
saver(val_output_dice)
print("evaluation dice metric:", dice_metric.aggregate().item())
#dice_metric.reset()
IoU_metric(y_pred=val_outputs, y=val_labels)
for val_output_IoU in val_outputs:
#saver(val_output_IoU)
print("evaluation IoU metric:", IoU_metric.aggregate().item())
#IoU_metric.reset()
# reset the status
dice_metric.reset()
IoU_metric.reset() which returns one value for DSC and one value for IoU for the whole segmented image. However, as I mentioned above, I want four values for each segmentation. One DSC and one IoU score for segmented channel no.2 and one DSC and one IoU score for segmented channel no.3 for each segmented image (I don't want the background channel no.0). How do I do that? Thanks in advance, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
have you tried changing the MONAI/monai/metrics/meandice.py Lines 40 to 44 in 77b1759 |
Beta Was this translation helpful? Give feedback.
I found this configuration that is working:
The output is: