mighty.monitor.accuracy.AccuracyEmbedding

class mighty.monitor.accuracy.AccuracyEmbedding(metric='cosine', cache=False)[source]

Calculates the accuracy of embedding vectors. The mean embedding vector is kept for each class. Prediction is based on the closest centroid ID.

Parameters:
metricstr, optional

The metric to compute pairwise distances with. Default: ‘cosine’

cachebool, optional

Cache predicted data or not. Default: False

Methods

__init__([metric, cache])

distances(outputs_test)

Returns the distances to fit centroid means.

extra_repr()

partial_fit(outputs_batch, labels_batch)

If the accuracy measure is not argmax (if the model's last layer isn't a softmax), the output is an embedding vector, which has to be stored and retrieved at prediction.

predict(outputs_test)

Predict the labels, given model output.

predict_cached()

Predicts the output of a model, using cached output activations.

predict_proba(outputs_test)

Compute label probabilities, given model output.

reset()

Resets all cached predicted and ground truth data.

reset_labels()

Resets predicted and ground truth labels.

Attributes

centroids

Returns:

is_fit

Returns:

property centroids
Returns:
torch.Tensor

(C, N) mean centroids tensor, where C is the number of unique classes, and N is the hidden layer dimensionality.

distances(outputs_test)[source]

Returns the distances to fit centroid means.

Parameters:
outputs_test(B, D) torch.Tensor

Hidden layer activations.

Returns:
distances(B, C) torch.Tensor

Distances to each class (label).

property is_fit
Returns:
bool

Whether the accuracy predictor is fit with data or not.

partial_fit(outputs_batch, labels_batch)[source]

If the accuracy measure is not argmax (if the model’s last layer isn’t a softmax), the output is an embedding vector, which has to be stored and retrieved at prediction.

Parameters:
outputs_batchtorch.Tensor or tuple

The output of a model.

labels_batchtorch.Tensor

True labels.

predict(outputs_test)[source]

Predict the labels, given model output.

Parameters:
outputs_testtorch.Tensor or tuple

The output of a model.

Returns:
torch.Tensor

Predicted labels.

predict_cached()[source]

Predicts the output of a model, using cached output activations.

Returns:
torch.Tensor

Predicted labels.

predict_proba(outputs_test)[source]

Compute label probabilities, given model output.

Parameters:
outputs_testtorch.Tensor or tuple

The output of a model.

Returns:
torch.Tensor

The probabilities of assigning to each class of shape (., C), where C is the number of classes.

reset()[source]

Resets all cached predicted and ground truth data.

reset_labels()

Resets predicted and ground truth labels.