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.
- classmethod from_pretrained(weights: str, **kwargs) 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 ofIExtractor
. 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.
- 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
IBatchSampler
ITripletLossWithMiner
IIndexedDataset
IBaseDataset
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.
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.
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_gallery_ids() LongTensor
- abstract get_labels() ndarray
IPairDataset
- class oml.interfaces.datasets.IPairDataset(*args, **kwds)[source]
Bases:
IIndexedDataset
This is an interface for the datasets which return pair of something.
- __init__()
IVisualizableDataset
IHTMLVisualizableDataset
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(data: Dict[str, Any], indices: Union[LongTensor, List[int]]) None [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
andcategory2
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