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().- __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), wherethree_crop_batchis a tensor of shapeB x T x C x H x Wandlabel_batchis a tensor of shapeB, withBthe batch size,T = 3for the three crops,Cthe number of channels,H = Wthe 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), wherethree_crop_batchis a tensor of shapeB x T x C x H x Wandlabel_batchis a tensor of shapeB, withBthe batch size,T = 3for the three crops,Cthe number of channels,H = Wthe 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, withBthe batch size,T = 3for the three crops,Cthe number of channels,H = Wthe 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.
- 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.