Author: Awais Farooq

  • Audio data loading

    audio_dataset_from_directory function Generates a tf.data.Dataset from audio files in a directory. If your directory structure is: Then calling audio_dataset_from_directory(main_directory, labels=’inferred’) will return a tf.data.Dataset that yields batches of audio files 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). Only .wav files are supported at this time. Arguments Returns A tf.data.Dataset object. Rules regarding labels format:

  • Text data loading

    text_dataset_from_directory function Generates a tf.data.Dataset from text files in a directory. If your directory structure is: Then calling text_dataset_from_directory(main_directory, labels=’inferred’) will return a tf.data.Dataset that yields batches of texts 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). Only .txt files are supported at this time. Arguments Returns A tf.data.Dataset object. Rules regarding labels format:

  • Timeseries data loading

    timeseries_dataset_from_array function Creates a dataset of sliding windows over a timeseries provided as array. This function takes in a sequence of data-points gathered at equal intervals, along with time series parameters such as length of the sequences/windows, spacing between two sequence/windows, etc., to produce batches of timeseries inputs and targets. Arguments Returns A tf.data.Dataset instance. If targets was passed, the…

  • 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…