Models
ViTExtractor
- class oml.models.vit_dino.extractor.ViTExtractor(weights: Optional[Union[Path, str]], arch: str, normalise_features: bool, use_multi_scale: bool = False)[source]
Bases:
IExtractorThe base class for the extractors that follow VisualTransformer architecture.
- __init__(weights: Optional[Union[Path, str]], arch: str, normalise_features: bool, use_multi_scale: bool = False)[source]
- Parameters
weights – Path to weights or a special key to download pretrained checkpoint, use
Noneto randomly initialize model’s weights. You can check the available pretrained checkpoints inself.pretrained_models.arch – Might be one of
vits8,vits16,vitb8,vitb16. You can check all the available options inself.constructorsnormalise_features – Set
Trueto normalise output featuresuse_multi_scale – Set
Trueto use multiscale (the analogue of test time augmentations)
ViTCLIPExtractor
- class oml.models.vit_clip.extractor.ViTCLIPExtractor(weights: Optional[str], arch: str, normalise_features: bool = True)[source]
Bases:
IExtractor- __init__(weights: Optional[str], arch: str, normalise_features: bool = True)[source]
- Parameters
weights – Path to weights or special key for pretrained ones or
Nonefor random initialization. You can check available pretrained checkpoints inViTCLIPExtractor.pretrained_models.arch – Might be one of
vitb16_224,vitb32_224,vitl14_224,vitl14_336.normalise_features – Set
Trueto normalise output features
ResnetExtractor
- class oml.models.resnet.extractor.ResnetExtractor(weights: Optional[Union[Path, str]], arch: str, gem_p: Optional[float], remove_fc: bool, normalise_features: bool)[source]
Bases:
IExtractorThe base class for the extractors that follow ResNet architecture.
- __init__(weights: Optional[Union[Path, str]], arch: str, gem_p: Optional[float], remove_fc: bool, normalise_features: bool)[source]
- Parameters
weights – Path to weights or a special key to download pretrained checkpoint, use
Noneto randomly initialize model’s weights. You can check the available pretrained checkpoints inself.pretrained_models.arch – Different types of ResNet, please, check
self.constructorsgem_p – Value of power in Generalized Mean Pooling that we use as the replacement for the default one (if
gem_p == 1orNoneit’s just a normal average pooling and ifgem_p -> infit’s max-pooling)remove_fc – Set
Trueif you want to remove the last fully connected layer. Note, that having this layer is obligatory for callingdraw_gradcam()methodnormalise_features – Set
Trueto normalise output features
ExtractorWithMLP
- class oml.models.meta.projection.ExtractorWithMLP(extractor: IExtractor, mlp_features: List[int], weights: Optional[Union[Path, str]] = None, train_backbone: bool = False)[source]
Bases:
IExtractor,IFreezableClass-wrapper for extractors which an additional MLP.
- __init__(extractor: IExtractor, mlp_features: List[int], weights: Optional[Union[Path, str]] = None, train_backbone: bool = False)[source]
- Parameters
extractor – Instance of
IExtractor(e.g.ViTExtractor)mlp_features – Sizes of projection layers
weights – Path to weights file or
Nonefor random initializationtrain_backbone – set
Falseif you want to train only MLP head
LinearTrivialDistanceSiamese
- class oml.models.meta.siamese.LinearTrivialDistanceSiamese(feat_dim: int, identity_init: bool, output_bias: float = 0)[source]
Bases:
IPairwiseModelThis model is a useful tool mostly for development.
- __init__(feat_dim: int, identity_init: bool, output_bias: float = 0)[source]
- Parameters
feat_dim – Expected size of each input.
identity_init – If
True, models’ weights initialised in a way when the model simply estimates L2 distance between the original embeddings.output_bias – Value to add to the output.
TrivialDistanceSiamese
- class oml.models.meta.siamese.TrivialDistanceSiamese(extractor: IExtractor, output_bias: float = 0)[source]
Bases:
IPairwiseModelThis model is a useful tool mostly for development.
- __init__(extractor: IExtractor, output_bias: float = 0) None[source]
- Parameters
extractor – Instance of
IExtractor(e.g.ViTExtractor)output_bias – Value to add to the outputs.
ConcatSiamese
- class oml.models.meta.siamese.ConcatSiamese(extractor: IExtractor, mlp_hidden_dims: List[int], use_tta: bool = False, weights: Optional[Union[Path, str]] = None)[source]
Bases:
IPairwiseModel,IFreezableThis model concatenates two inputs and passes them through a given backbone and applyies a head after that.
- __init__(extractor: IExtractor, mlp_hidden_dims: List[int], use_tta: bool = False, weights: Optional[Union[Path, str]] = None) None[source]
- Parameters
extractor – Instance of
IExtractor(e.g.ViTExtractor)mlp_hidden_dims – Hidden dimensions of the head
use_tta – Set
Trueif you want to average the results obtained by two different orders of concatenating input images. Affects onlyself.predict()method.weights – Path to weights file or
Nonefor random initialization
- forward(x1: Tensor, x2: Tensor) Tensor[source]
- Parameters
x1 – The first input.
x2 – The second input.
- predict(x1: Tensor, x2: Tensor) 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.