I think it is important to highlight that Keras is calculating the IoU macro-average. That is, the average IoU of all classes. You can also use the micro-average IoU, which is the sum of the intersections of each class divided by the sum of the unions of all classes. The choice of micro or macro should be made according to the imbalance of the dataset.
IOU_keras.update_state(val_y, y_pred_val) does this work for batch inputs. I tried, but gives only first 2 class pixel count in the confusion matrix variable
I'm realizing a semantic segmentation task, and I want to compute the mIoU over a dataset. My doubt is, should I compute the mIoU of each image and average the results in the end, or should I build a giant confusion matrix of all image results and compute the mIoU from there?
Thanks for the useful video, but I have confusion when implement MeanIOU into my Unet Semantic Segmentation ( not multiple class). Can you help me, please ?
Nice tutorial. I just find 1 mistake in the class2_IOU calculations. In the false positive you have added values[2,1] twice and skip the values[2,4]. Correct me if I am wrong.
You are probably right, I will have to go back and check. I do not write unit tests for the code I generate for videos, this means I will make mistakes that can be hard to catch. I will correct the code on GitHub if there is a mistake. Thanks for reporting.
@@DigitalSreeni thanks sir for reply. One question please. It is shown the miou calculation of background class is zero as it is ignored in miou calculation. Will you please tell me how can we ignore the background in iou calculation?
Background class is part of the prediction process so it needs to be included as part of your IoU. If you only want to look at other real classes. For example, with keras' MeanIOU, you can print IoU for all classes individually, almost like a confusion matrix. You can just take the values for real classes and ignore the background.
Sir, please make video on Metrics for evaluating 3D medical image segmentation like Dice Coefficient Jaccard Coefficient Area under ROC Curve (one system state) Cohen Kappa Volumetric Similarity Coefficient Hausdorff Distance (optionally in voxel or millimeter) Average Hausdorff Distance (optionally in voxel or millimeter) Balanced Average Hausdorff Distance Mahanabolis Distance Global Consistency Error Coefficient of Variation Probabilistic Distance and also Classic measures
sombody can help me import cv2 import numpy as np def vegetation_segmentation(image): # Normalize the image to the range [0, 1] image_norm = image.astype(np.float32) / 255.0 # Calculate the individual color channels R = image_norm[:, :, 2] G = image_norm[:, :, 1] B = image_norm[:, :, 0] # Perform the necessary calculations R_prime = R * 255 G_prime = G * 255 B_prime = B * 255 M = np.max([R_prime, G_prime, B_prime], axis=0) m = np.min([R_prime, G_prime, B_prime], axis=0) C = M - m H = np.zeros_like(R_prime) S = np.zeros_like(R_prime) V = M # Calculate H, S, and V values idx = np.where(C != 0) H[idx] = np.where(M == R_prime, 60 * ((G_prime - B_prime) / C % 6), np.where(M == G_prime, 60 * ((B_prime - R_prime) / C + 2), 60 * ((R_prime - G_prime) / C + 4))) S[idx] = C[idx] / M[idx] # Perform thresholding to create a binary mask binary_mask = np.zeros_like(R_prime) binary_mask[np.where((H >= 60) & (H = 0.25))] = 1 return binary_mask # Load the image image = cv2.imread("path/to/image.jpg") # Perform vegetation segmentation binary_mask = vegetation_segmentation(image) # Save the binary mask as a TIFF image cv2.imwrite("path/to/output_mask.tif", binary_mask.astype('uint8') * 255) # Display or further process the segmentation results as needed
Love the energy, really sharp Sreeni.
Best tutorial sir. I just love your efforts. You're such a great personality.
Thanks a ton
Salvou meu mestrado paizão, valeu demais!
i like your videos for crisp and clear delivery
Glad you like them!
Great video, thanks for the effort and the high quality material
My pleasure!
I think it is important to highlight that Keras is calculating the IoU macro-average. That is, the average IoU of all classes. You can also use the micro-average IoU, which is the sum of the intersections of each class divided by the sum of the unions of all classes. The choice of micro or macro should be made according to the imbalance of the dataset.
Good work Srini
Thanks for teaching new concepts
Thanks and welcome
IOU_keras.update_state(val_y, y_pred_val)
does this work for batch inputs. I tried, but gives only first 2 class pixel count in the confusion matrix variable
For IOU_keras.results(), how did we really calculate the mean of the IOU values?
Anyone please tell me how can we ignore background class in IOU calculation. Thanks
Love it. Wonderful teaching.
Glad you enjoyed it!
HEY can you share code for finding jaccard coefficient for multi class semantic segmentation Unet please
your very excellent professor. I love your lecture
Thank you very much and these are very valuable information. Thank you so much...
You are very welcome
I'm realizing a semantic segmentation task, and I want to compute the mIoU over a dataset. My doubt is, should I compute the mIoU of each image and average the results in the end, or should I build a giant confusion matrix of all image results and compute the mIoU from there?
Thanks for the useful video, but I have confusion when implement MeanIOU into my Unet Semantic Segmentation ( not multiple class). Can you help me, please ?
thank you for the videos sir
Sir, I have a pair of ground truth and predicted images, but I don't have the model. is it possible to use just the images to find miou?
Hello can you please make video on segmentation evaluation metrics like precision recall and ap, map. Thank you
These codes will work in colab or not sir please reply sir
All my code should work in any python IDE, including Colab.
Awesome tutorial...Thanks...
Welcome 😊
Thanks for the great video! I am just wondering how do you produce the ground truth images? Thank you.
Hi you need to label your dataset using some tool which could give your labelled images (ground truths)
You either label the ground truth yourself with a tool or they are given with the dataset you're using.
Many thanks.
You are welcome!
Nice tutorial. I just find 1 mistake in the class2_IOU calculations. In the false positive you have added values[2,1] twice and skip the values[2,4]. Correct me if I am wrong.
You are probably right, I will have to go back and check. I do not write unit tests for the code I generate for videos, this means I will make mistakes that can be hard to catch. I will correct the code on GitHub if there is a mistake. Thanks for reporting.
@@DigitalSreeni thanks sir for reply. One question please. It is shown the miou calculation of background class is zero as it is ignored in miou calculation. Will you please tell me how can we ignore the background in iou calculation?
Background class is part of the prediction process so it needs to be included as part of your IoU. If you only want to look at other real classes. For example, with keras' MeanIOU, you can print IoU for all classes individually, almost like a confusion matrix. You can just take the values for real classes and ignore the background.
Whay don’t use kappa?
May be this is why...
journals.plos.org/plosone/article?id=10.1371/journal.pone.0222916
@@DigitalSreeni Very good. Thanks. Do you know how Keras calculate the MeanIOU? just (sum/n?)
It will be a great help if you show how to calculate the mean iou using tensorflow2. I have faced problem while using tf.keras.MeanIoU()
Sir, please make video on Metrics for evaluating 3D medical image segmentation like
Dice Coefficient
Jaccard Coefficient
Area under ROC Curve (one system state)
Cohen Kappa
Volumetric Similarity Coefficient
Hausdorff Distance (optionally in voxel or millimeter)
Average Hausdorff Distance (optionally in voxel or millimeter)
Balanced Average Hausdorff Distance
Mahanabolis Distance
Global Consistency Error
Coefficient of Variation
Probabilistic Distance
and also Classic measures
Thanks for another great video. Sir I want to contact you
How can I help you?
@@DigitalSreeni Sir I have sent a mail to you
sombody can help me
import cv2
import numpy as np
def vegetation_segmentation(image):
# Normalize the image to the range [0, 1]
image_norm = image.astype(np.float32) / 255.0
# Calculate the individual color channels
R = image_norm[:, :, 2]
G = image_norm[:, :, 1]
B = image_norm[:, :, 0]
# Perform the necessary calculations
R_prime = R * 255
G_prime = G * 255
B_prime = B * 255
M = np.max([R_prime, G_prime, B_prime], axis=0)
m = np.min([R_prime, G_prime, B_prime], axis=0)
C = M - m
H = np.zeros_like(R_prime)
S = np.zeros_like(R_prime)
V = M
# Calculate H, S, and V values
idx = np.where(C != 0)
H[idx] = np.where(M == R_prime, 60 * ((G_prime - B_prime) / C % 6),
np.where(M == G_prime, 60 * ((B_prime - R_prime) / C + 2),
60 * ((R_prime - G_prime) / C + 4)))
S[idx] = C[idx] / M[idx]
# Perform thresholding to create a binary mask
binary_mask = np.zeros_like(R_prime)
binary_mask[np.where((H >= 60) & (H = 0.25))] = 1
return binary_mask
# Load the image
image = cv2.imread("path/to/image.jpg")
# Perform vegetation segmentation
binary_mask = vegetation_segmentation(image)
# Save the binary mask as a TIFF image
cv2.imwrite("path/to/output_mask.tif", binary_mask.astype('uint8') * 255)
# Display or further process the segmentation results as needed
A1