Base Interfaces

IExtractor

class oml.interfaces.models.IExtractor(*args, **kwargs)[source]

Bases: Module, ABC

Models have to inherit this interface to be comparable with the rest of the library.

property feat_dim: int

The only method that obligatory to implemented.

extract(x: Tensor) Tensor[source]
classmethod from_pretrained(weights: str) IExtractor[source]

This method allows to download a pretrained checkpoint. The class field self.pretrained_models is the dictionary which keeps records of all the available checkpoints in the format, depending on implementation of a particular child of IExtractor. As a user, you don’t need to worry about implementing this method.

Parameters

weights – A unique identifier (key) of a pretrained model information stored in a class field self.pretrained_models.

Returns: An instance of IExtractor

IPairwiseModel

class oml.interfaces.models.IPairwiseModel(*args, **kwargs)[source]

Bases: Module

A model of this type takes two inputs, for example, two embeddings or two images.

forward(x1: Any, x2: Any) Tensor[source]
Parameters
  • x1 – The first input.

  • x2 – The second input.

predict(x1: Any, x2: Any) Tensor[source]

While self.forward() is called during training, this method is called during inference or validation time. For example, it allows application of some activation, which was a part of a loss function during the training.

Parameters
  • x1 – The first input.

  • x2 – The second input.

IFreezable

class oml.interfaces.models.IFreezable[source]

Bases: ABC

Models which can freeze and unfreeze their parts.

freeze() None[source]

Function for freezing. You can use it to partially freeze a model.

unfreeze() None[source]

Function for unfreezing. You can use it to unfreeze a model.

IBatchSampler

class oml.interfaces.samplers.IBatchSampler[source]

Bases: ABC

We introduce our interface instead of using the default BatchSampler from Torch, because the last one is just a wrapper for the sequential sampler, which is not convenient for our purposes.

abstract __len__() int[source]
Returns

The number of batches in an epoch

abstract __iter__() Iterator[List[int]][source]
Returns

Iterator contains indices for the batches

ITripletLossWithMiner

class oml.interfaces.criterions.ITripletLossWithMiner(*args, **kwargs)[source]

Bases: Module

Base class for TripletLoss combined with Miner.

forward(features: Tensor, labels: Union[Tensor, List[int]]) Tensor[source]
Parameters
  • features – Features with the shape [batch_size, features_dim]

  • labels – Labels with the size of batch_size

Returns

Loss value

IBaseDataset

class oml.interfaces.datasets.IBaseDataset(*args, **kwds)[source]

Bases: Dataset

ILabeledDataset

class oml.interfaces.datasets.ILabeledDataset(*args, **kwds)[source]

Bases: IBaseDataset, ABC

This is an interface for the datasets which provide labels of containing items.

__getitem__(item: int) Dict[str, Any][source]
Parameters

item – Idx of the sample

Return type

Dictionary including the following keys

self.labels_key

abstract get_labels() ndarray[source]

IQueryGalleryDataset

class oml.interfaces.datasets.IQueryGalleryDataset(*args, **kwds)[source]

Bases: IBaseDataset, ABC

This is an interface for the datasets which hold the information on how to split the data into the query and gallery. The query and gallery ids may overlap. It doesn’t need the ground truth labels, so it can be used for prediction on not annotated data.

abstract get_query_ids() LongTensor[source]

IQueryGalleryLabeledDataset

class oml.interfaces.datasets.IQueryGalleryLabeledDataset(*args, **kwds)[source]

Bases: IQueryGalleryDataset, ILabeledDataset, ABC

This interface is similar to IQueryGalleryDataset, but there are ground truth labels.

abstract get_query_ids() LongTensor
abstract get_labels() ndarray

IPairsDataset

class oml.interfaces.datasets.IPairsDataset(*args, **kwds)[source]

Bases: Dataset, ABC

This is an interface for the datasets which return pair of something.

__init__()
abstract __getitem__(item: int) Dict[str, Any][source]
Parameters

item – Idx of the sample

Return type

Dictionary with the following keys

self.pairs_1st_key self.pairs_2nd_key self.index_key

IVisualizableDataset

class oml.interfaces.datasets.IVisualizableDataset(*args, **kwds)[source]

Bases: Dataset, ABC

Base class for the datasets which know how to visualise their items.

abstract visualize(item: int, color: Tuple[int, int, int]) ndarray[source]

IBasicMetric

class oml.interfaces.metrics.IBasicMetric[source]

Bases: ABC

This is a base interface for the objects that calculate metrics.

abstract setup(*args: Any, **kwargs: Any) Any[source]

Method for preparing metrics to work: memory allocation, placeholder preparation, etc. Has to be called before the first call of self.update_data().

abstract update_data(*args: Any, **kwargs: Any) Any[source]

Method for passing data to calculate the metrics later on.

abstract compute_metrics(*args: Any, **kwargs: Any) Any[source]

The output must be in the following format:

{
    "self.overall_categories_key": {"metric1": ..., "metric2": ...},
    "category1": {"metric1": ..., "metric2": ...},
    "category2": {"metric1": ..., "metric2": ...}
}

Where category1 and category2 are optional.

ITripletsMiner

class oml.interfaces.miners.ITripletsMiner[source]

Bases: ABC

An abstraction of triplet miner.

abstract sample(features: Tensor, labels: Union[List[int], Tensor]) Tuple[Tensor, Tensor, Tensor][source]

This method includes the logic of mining/sampling triplets.

Parameters
  • features – Features with the shape of [batch_size, feature_size]

  • labels – Labels with the size of batch_size

Returns

Batch of triplets

ITripletsMinerInBatch

class oml.interfaces.miners.ITripletsMinerInBatch[source]

Bases: ITripletsMiner

We expect that the child instances of this class will be used for mining triplets inside the batches. The batches must contain at least 2 samples for each class and at least 2 different labels, such behaviour can be guarantee via using samplers from our registry.

But you are not limited to using it in any other way.

abstract _sample(features: Tensor, labels: List[int]) Tuple[List[int], List[int], List[int]][source]

This method includes the logic of mining triplets inside the batch. It can be based on information about the distance between the features, or the choice can be performed randomly.

Parameters
  • features – Features with the shape of [batch_size, feature_size]

  • labels – Labels with the size of batch_size

Returns

Indices of the batch samples to form the triplets

sample(features: Tensor, labels: Union[List[int], Tensor]) Tuple[Tensor, Tensor, Tensor][source]
Parameters
  • features – Features with the shape of [batch_size, feature_size]

  • labels – Labels with the size of batch_size

Returns

Batch of triplets

IPipelineLogger

class oml.interfaces.loggers.IPipelineLogger[source]

Bases: Logger, IFigureLogger

abstract log_figure(fig: Figure, title: str, idx: int) None
abstract log_pipeline_info(cfg: Union[Dict[str, Any], DictConfig]) None[source]