Skip to content

coral_pytorch.dataset

coral_pytorch version: 1.4.0

label_to_levels

label_to_levels(label, num_classes, dtype=torch.float32)

Converts integer class label to extended binary label vector

Parameters

  • label : int

    Class label to be converted into a extended binary vector. Should be smaller than num_classes-1.

  • num_classes : int

    The number of class clabels in the dataset. Assumes class labels start at 0. Determines the size of the output vector.

  • dtype : torch data type (default=torch.float32)

    Data type of the torch output vector for the extended binary labels.

Returns

  • levels : torch.tensor, shape=(num_classes-1,)

    Extended binary label vector. Type is determined by the dtype parameter.

Examples

    >>> label_to_levels(0, num_classes=5)
    tensor([0., 0., 0., 0.])
    >>> label_to_levels(1, num_classes=5)
    tensor([1., 0., 0., 0.])
    >>> label_to_levels(3, num_classes=5)
    tensor([1., 1., 1., 0.])
    >>> label_to_levels(4, num_classes=5)
    tensor([1., 1., 1., 1.])

proba_to_label

proba_to_label(probas)

Converts predicted probabilities from extended binary format to integer class labels

Parameters

  • probas : torch.tensor, shape(n_examples, n_labels)

    Torch tensor consisting of probabilities returned by CORAL model.

Examples

    >>> # 3 training examples, 6 classes
    >>> probas = torch.tensor([[0.934, 0.861, 0.323, 0.492, 0.295],
    ...                        [0.496, 0.485, 0.267, 0.124, 0.058],
    ...                        [0.985, 0.967, 0.920, 0.819, 0.506]])
    >>> proba_to_label(probas)
    tensor([2, 0, 5])

corn_label_from_logits

corn_label_from_logits(logits)

Returns the predicted rank label from logits for a network trained via the CORN loss.

Parameters

  • logits : torch.tensor, shape=(n_examples, n_classes)

    Torch tensor consisting of logits returned by the neural net.

Returns

  • labels : torch.tensor, shape=(n_examples)

    Integer tensor containing the predicted rank (class) labels

Examples

    >>> # 2 training examples, 5 classes
    >>> logits = torch.tensor([[14.152, -6.1942, 0.47710, 0.96850],
    ...                        [65.667, 0.303, 11.500, -4.524]])
    >>> corn_label_from_logits(logits)
    tensor([1, 3])

levels_from_labelbatch

levels_from_labelbatch(labels, num_classes, dtype=torch.float32)

Converts a list of integer class label to extended binary label vectors

Parameters

  • labels : list or 1D orch.tensor, shape=(num_labels,)

    A list or 1D torch.tensor with integer class labels to be converted into extended binary label vectors.

  • num_classes : int

    The number of class clabels in the dataset. Assumes class labels start at 0. Determines the size of the output vector.

  • dtype : torch data type (default=torch.float32)

    Data type of the torch output vector for the extended binary labels.

Returns

  • levels : torch.tensor, shape=(num_labels, num_classes-1)

Examples

    >>> levels_from_labelbatch(labels=[2, 1, 4], num_classes=5)
    tensor([[1., 1., 0., 0.],
    [1., 0., 0., 0.],
    [1., 1., 1., 1.]])