Skip to content

Instantly share code, notes, and snippets.

View aunsid's full-sized avatar

Mohammed Aun Siddiqui aunsid

View GitHub Profile
@aunsid
aunsid / binSegMetrics.py
Created September 17, 2020 13:49
Binary Class Segmentation Metrics(f1, acc, precision, recall) in Numpy
# https://github.com/Abe404/segmentation_of_roots_in_soil_with_unet/blob/master/src/metrics.py
def get_metrics(y_pred, y_true, loss=float('nan')):
true_positives = np.sum(np.logical_and(y_pred == 1, y_true == 1))
true_negatives = np.sum(np.logical_and(y_pred == 0, y_true == 0))
false_positives = np.sum(np.logical_and(y_pred == 1, y_true == 0))
false_negatives = np.sum(np.logical_and(y_pred == 0, y_true == 1))
accuracy = (true_positives + true_negatives) / len(y_true)
assert not np.isnan(true_negatives)
assert not np.isnan(false_positives)
@aunsid
aunsid / RandGammaCorrection.py
Created September 14, 2020 15:20
Random Gamma Correction Data Augmentation Pytorch
import torchvision.transforms.functional as TF
class RandomGammaCorrection(object):
"""
Apply Gamma Correction to the images
"""
def __init__(self, gamma = None):
self.gamma = gamma