recognite.utils package

Average reference embeddings

recognite.utils.avg_ref_embs(embeddings: Tensor, labels: Tensor) Tuple[Tensor, Tensor][source]

Groups the embeddings by label and computes the average embedding.

Parameters:
  • embeddings – The embeddings (one embedding per row).

  • labels – The label of each embedding.

Returns:

A tuple containing the averaged embeddings and their corresponding labels.

Three-cropping

class recognite.utils.three_crop.ThreeCrop[source]

Class wrapper around three_crop().

__call__(img: Tensor) Tuple[Tensor, Tensor, Tensor][source]

Call self as a function.

__weakref__

list of weak references to the object (if defined)

recognite.utils.three_crop.collate_three_crops(batch: List[Tuple[Tensor, int]]) Tuple[Tensor, Tensor][source]

Collate a batch containing three-crop crops.

Converts a list of tuples (three_crops, label) into a single tuple (three_crops_batch, label_batch), where three_crop_batch is a tensor of shape B x T x C x H x W and label_batch is a tensor of shape B, with B the batch size, T = 3 for the three crops, C the number of channels, H = W the height and width of the images.

Parameters:

batch – A list of tuples (three_crops, label) containing three-crop crops and their corresponding label.

Returns:

A single tuple (three_crops_batch, label_batch), where three_crop_batch is a tensor of shape B x T x C x H x W and label_batch is a tensor of shape B, with B the batch size, T = 3 for the three crops, C the number of channels, H = W the height and width of the images.

recognite.utils.three_crop.embeddings_three_crops(model: Module, batch: Tensor) Tensor[source]

Computes the embeddings for a batch with three-crop crops.

The embeddigs of each three crops are averaged.

Parameters:
  • model – The model to use for computing the embedding of a batch of images.

  • batch – A batch of shape B x T x C x H x W, with B the batch size, T = 3 for the three crops, C the number of channels, H = W the height and width of the images.

Returns:

The embeddings, averaged per three crops.

recognite.utils.three_crop.three_crop(img: Tensor) Tuple[Tensor, Tensor, Tensor][source]

Converts an image into a tuple of three-crop crops.

The “three-crop” crops consist of three square crops one at the start, one at the center and one at the end of the largest dimension of the given image.

Parameters:

img – The image to convert into three-crop crops.

Returns:

The start crop, center crop and end crop.

Running Extrema

class recognite.utils.RunningExtrema(extremum: str)[source]

Keeps a running extremum (max/min) of a set of named values.

extremum

The extremum (max/min) to use.

extrema_dict

A dictionary with the running extremum per key. The key is prepended with ‘Max’ or ‘Min’, depending on the choses extremum.

clear()[source]

Clears all running values.

is_new_extremum(key: str, val: Any)[source]

Returns if the value is a new extremum for the key.

Parameters:
  • key – The key.

  • val – The value.

update(key: str, val: Any)[source]

Replaces the running value of the given key if the value is a new extremum.

update_dict(d: dict)[source]

Replaces the running value of those keys in the given dict that have a new extremum as value.