Author: Awais Farooq

  • Image data loading

    image_dataset_from_directory function Generates a tf.data.Dataset from image files in a directory. If your directory structure is: Then calling image_dataset_from_directory(main_directory, labels=’inferred’) will return a tf.data.Dataset that yields batches of images from the subdirectories class_a and class_b, together with labels 0 and 1 (0 corresponding to class_a and 1 corresponding to class_b). Supported image formats: .jpeg, .jpg, .png, .bmp, .gif. Animated gifs are truncated to the first frame. Arguments Returns A tf.data.Dataset object. Rules regarding labels format:…

  • Hinge losses for “maximum-margin” classification

    Hinge class Computes the hinge loss between y_true & y_pred. Formula: y_true values are expected to be -1 or 1. If binary (0 or 1) labels are provided we will convert them to -1 or 1. Arguments SquaredHinge class Computes the squared hinge loss between y_true & y_pred. Formula: y_true values are expected to be -1 or 1. If binary (0 or 1) labels are…

  • Regression losses

    MeanSquaredError class Computes the mean of squares of errors between labels and predictions. Formula: Arguments MeanAbsoluteError class Computes the mean of absolute difference between labels and predictions. Formula: Arguments MeanAbsolutePercentageError class Computes the mean absolute percentage error between y_true & y_pred. Formula: Arguments MeanSquaredLogarithmicError class Computes the mean squared logarithmic error between y_true & y_pred. Formula: Arguments CosineSimilarity class Computes the cosine similarity between y_true & y_pred. Note that…

  • Probabilistic losses

    BinaryCrossentropy class Computes the cross-entropy loss between true labels and predicted labels. Use this cross-entropy loss for binary (0 or 1) classification applications. The loss function requires the following inputs: Arguments Examples Recommended Usage: (set from_logits=True) With compile() API: As a standalone function: Default Usage: (set from_logits=False) BinaryFocalCrossentropy class Computes focal cross-entropy loss between true labels and predictions. Binary cross-entropy loss is often…

  • Metric wrappers and reduction metrics

    MeanMetricWrapper class Wrap a stateless metric function with the Mean metric. You could use this class to quickly build a mean metric from a function. The function needs to have the signature fn(y_true, y_pred) and return a per-sample loss array. MeanMetricWrapper.result() will return the average metric value across all samples seen so far. For example: Arguments Mean class Compute the (weighted) mean of…

  • Hinge metrics for “maximum-margin” classification

    Hinge class Computes the hinge metric between y_true and y_pred. y_true values are expected to be -1 or 1. If binary (0 or 1) labels are provided we will convert them to -1 or 1. Arguments Examples SquaredHinge class Computes the hinge metric between y_true and y_pred. y_true values are expected to be -1 or 1. If binary (0 or 1) labels are provided we…

  • Image segmentation metrics

    IoU class Computes the Intersection-Over-Union metric for specific target classes. Formula: Intersection-Over-Union is a common evaluation metric for semantic image segmentation. To compute IoUs, the predictions are accumulated in a confusion matrix, weighted by sample_weight and the metric is then calculated from it. If sample_weight is None, weights default to 1. Use sample_weight of 0 to mask values. Note, this class first computes…

  • Classification metrics based on True/False positives & negatives

    AUC class Approximates the AUC (Area under the curve) of the ROC or PR curves. The AUC (Area under the curve) of the ROC (Receiver operating characteristic; default) or PR (Precision Recall) curves are quality measures of binary classifiers. Unlike the accuracy, and like cross-entropy losses, ROC-AUC and PR-AUC evaluate all the operational points of a…

  • Regression metrics

    MeanSquaredError class Computes the mean squared error between y_true and y_pred. Formula: Arguments Example RootMeanSquaredError class Computes root mean squared error metric between y_true and y_pred. Formula: Arguments Example Example Usage with compile() API: MeanAbsoluteError class Computes the mean absolute error between the labels and predictions. Formula: Arguments Examples Usage with compile() API: MeanAbsolutePercentageError class Computes mean absolute percentage error between y_true and y_pred. Formula: Arguments Example Example Usage with compile() API: MeanSquaredLogarithmicError class Computes…

  • Probabilistic metrics

    BinaryCrossentropy class Computes the crossentropy metric between the labels and predictions. This is the crossentropy metric class to be used when there are only two label classes (0 and 1). Arguments Example Example Usage with compile() API: CategoricalCrossentropy class Computes the crossentropy metric between the labels and predictions. This is the crossentropy metric class to be used when there…