- class mmpretrain.models.selfsup.BaseSelfSupervisor(backbone, neck=None, head=None, target_generator=None, pretrained=None, data_preprocessor=None, init_cfg=None)¶
BaseModel for Self-Supervised Learning.
All self-supervised algorithms should inherit this module.
head (dict, optional) – The head module to do prediction and calculate loss from processed features. See
mmpretrain.models.heads. Notice that if the head is not set, almost all methods cannot be used except
extract_feat(). Defaults to None.
target_generator – (dict, optional): The target_generator module to generate targets for self-supervised learning optimization, such as HOG, extracted features from other modules(DALL-E, CLIP), etc.
pretrained (str, optional) – The pretrained checkpoint path, support local path and remote path. Defaults to None.
data_preprocessor (Union[dict, nn.Module], optional) – The config for preprocessing input data. If None or no specified type, it will use “SelfSupDataPreprocessor” as type. See
SelfSupDataPreprocessorfor more details. Defaults to None.
init_cfg (dict, optional) – the config to control the initialization. Defaults to None.
Extract features from the input tensor with shape (N, C, …).
The default behavior is extracting features from backbone.
inputs (Tensor) – A batch of inputs. The shape of it should be
(num_samples, num_channels, *img_shape).
The output feature tensor(s).
- Return type:
tuple | Tensor
- forward(inputs, data_samples=None, mode='tensor')¶
The unified entry for a forward process in both training and test.
The method currently accepts two modes: “tensor” and “loss”:
“tensor”: Forward the backbone network and return the feature tensor(s) tensor without any post-processing, same as a common PyTorch Module.
“loss”: Forward and return a dict of losses according to the given inputs and data samples.
data_samples (List[DataSample], optional) – The other data of every samples. It’s required for some algorithms if
mode="loss". Defaults to None.
mode (str) – Return what kind of value. Defaults to ‘tensor’.
The return type depends on
mode="tensor", return a tensor or a tuple of tensor.
mode="loss", return a dict of tensor.
Get the layer-wise depth of a parameter.
- abstract loss(inputs, data_samples)¶
Calculate losses from a batch of inputs and data samples.
This is a abstract method, and subclass should overwrite this methods if needed.
- property with_head¶
Check if the model has a head module.
- property with_neck¶
Check if the model has a neck module.
- property with_target_generator¶
Check if the model has a target_generator module.