TransWikia.com

Number classes in tf.keras.metrics.MeanIoU for one class in image segmentation why must set num_classes = 2? What difference between this and IoU?

Data Science Asked by Noon Kamonchat on June 24, 2021

I train U-Net model for audiometric CT image segmentation. I have one class in train data set and test data set (such as bladder). At the first time I set tf.keras.metrics.MeanIoU in model.fit, I set (num_classes=1) because I have only one class but it is error. Then I searched in many source it tell that I must set (num_classes=2) but I wonder why?

  1. It separates background and foreground?
  2. If my data have two classes (such as bladder and femur) I must set num_classes = 3?

And I set def IoU like code as show below to see that will they be same? but not it very different or nearly at the end of epoch but not same.

 def IoU(y_true, y_pred):
    y_true_f = k.flatten(y_true)
    y_pred_f = k.flatten(y_pred)
    intersection = k.sum(y_true_f * y_pred_f)
    union = k.sum(y_true_f) + k.sum(y_pred_f) - intersection
    return intersection/union

sample of result

Epoch 1/50

  • IoU: 0.0016 – mean_io_u: 0.4996

Epoch 2/50

  • IoU: 0.0025 – mean_io_u: 0.4996

Epoch 3/50

  • IoU: 0.0028 – mean_io_u: 0.4996

Epoch 4/50

  • IoU: 0.0039 – mean_io_u: 0.4996

Epoch 5/50

  • IoU: 0.0050 – mean_io_u: 0.4996

Epoch 6/50

  • IoU: 0.0053 – mean_io_u: 0.4996

Epoch 7/50

  • IoU: 0.0065 – mean_io_u: 0.4996

Epoch 8/50

  • IoU: 0.0081 – mean_io_u: 0.4996

Epoch 9/50

  • IoU: 0.0111 – mean_io_u: 0.4996

Epoch 10/50

  • IoU: 0.0226 – mean_io_u: 0.4996

Epoch 11/50

  • IoU: 0.0482 – mean_io_u: 0.4996

Epoch 12/50

  • IoU: 0.0793 – mean_io_u: 0.4996

Epoch 13/50

  • IoU: 0.2421 – mean_io_u: 0.4996

Epoch 14/50

  • IoU: 0.3821 – mean_io_u: 0.4996

Epoch 15/50

  • IoU: 0.4970 – mean_io_u: 0.4996

Epoch 16/50

  • IoU: 0.6159 – mean_io_u: 0.4996

Can anyone explain to me? Thankyou.

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP