Shortcuts

BaseClassifier

class mmpretrain.models.classifiers.BaseClassifier(init_cfg=None, data_preprocessor=None)[source]

Base class for classifiers.

Parameters:
  • init_cfg (dict, optional) – Initialization config dict. Defaults to None.

  • data_preprocessor (dict, optional) – The config for preprocessing input data. If None, it will use “BaseDataPreprocessor” as type, see mmengine.model.BaseDataPreprocessor for more details. Defaults to None.

init_cfg

Initialization config dict.

Type:

dict

data_preprocessor

An extra data pre-processing module, which processes data from dataloader to the format accepted by forward().

Type:

mmengine.model.BaseDataPreprocessor

extract_feat(inputs)[source]

Extract features from the input tensor with shape (N, C, …).

The sub-classes are recommended to implement this method to extract features from backbone and neck.

Parameters:

inputs (Tensor) – A batch of inputs. The shape of it should be (num_samples, num_channels, *img_shape).

extract_feats(multi_inputs, **kwargs)[source]

Extract features from a sequence of input tensor.

Parameters:
  • multi_inputs (Sequence[torch.Tensor]) – A sequence of input tensor. It can be used in augmented inference.

  • **kwargs – Other keyword arguments accepted by extract_feat().

Returns:

Features of every input tensor.

Return type:

list

abstract forward(inputs, data_samples=None, mode='tensor')[source]

The unified entry for a forward process in both training and test.

The method should accept three modes: “tensor”, “predict” and “loss”:

  • “tensor”: Forward the whole network and return tensor or tuple of tensor without any post-processing, same as a common nn.Module.

  • “predict”: Forward and return the predictions, which are fully processed to a list of BaseDataElement.

  • “loss”: Forward and return a dict of losses according to the given inputs and data samples.

Note that this method doesn’t handle neither back propagation nor optimizer updating, which are done in the train_step().

Parameters:
  • inputs (torch.Tensor) – The input tensor with shape (N, C, …) in general.

  • data_samples (List[BaseDataElement], optional) – The annotation data of every samples. It’s required if mode="loss". Defaults to None.

  • mode (str) – Return what kind of value. Defaults to ‘tensor’.

Returns:

The return type depends on mode.

  • If mode="tensor", return a tensor or a tuple of tensor.

  • If mode="predict", return a list of mmengine.BaseDataElement.

  • If mode="loss", return a dict of tensor.

property with_head

Whether the classifier has a head.

property with_neck

Whether the classifier has a neck.

Read the Docs v: latest
Versions
latest
stable
mmcls-1.x
mmcls-0.x
dev
Downloads
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.