cvnets.models package

Subpackages

Submodules

cvnets.models.base_model module

class cvnets.models.base_model.BaseAnyNNModel(opts, *args, **kwargs)[source]

Bases: Module

Base class for any neural network

__init__(opts, *args, **kwargs) None[source]

Initializes internal Module state, shared by both nn.Module and ScriptModule.

classmethod add_arguments(parser: ArgumentParser)[source]

Add model-specific arguments

reset_parameters(opts: Namespace) None[source]

Initialize model weights

forward(x: Any, *args, **kwargs) Any[source]

Implement the model-specific forward function in sub-classes.

get_trainable_parameters(weight_decay: float = 0.0, no_decay_bn_filter_bias: bool = False, module_name: str = '', *args, **kwargs) Tuple[List[Mapping], List[float]][source]

Get parameters for training along with the learning rate.

Parameters:
  • weight_decay – weight decay

  • no_decay_bn_filter_bias – Do not decay BN and biases. Defaults to False.

Returns:

Returns a tuple of length 2. The first entry is a list of dictionary with three keys (params, weight_decay, param_names). The second entry is a list of floats containing learning rate for each parameter.

Note

Kwargs may contain module_name. To avoid multiple arguments with the same name, we pop it and concatenate with encoder or head name

dummy_input_and_label(batch_size: int) Dict[source]

Create dummy input and labels for CI/CD purposes. Child classes should implement it.

get_exportable_model() Module[source]

This function can be used to prepare the architecture for inference. For example, re-parameterizing branches when possible. The functionality of this method may vary from model to model, so child model classes have to implement this method, if such a transformation exists.

classmethod freeze_norm_layers(opts: Namespace, model: BaseAnyNNModel) None[source]

Freeze normalization layers in the model

Parameters:
  • opts – Command-line arguments

  • model – An instance of BaseAnyNNModel

classmethod build_model(opts: Namespace, *args, **kwargs) BaseAnyNNModel[source]

Build a model from command-line arguments. Sub-classes must implement this method

Parameters:

opts – Command-line arguments

…note::

This function is typically implemented in the base class for each task and implementation is reused by all models in that task.

info() None[source]

Prints model, parameters, and FLOPs on start rank.

Module contents

cvnets.models.get_model(opts: Namespace, category: str | None = None, model_name: str | None = None, *args, **kwargs) BaseAnyNNModel[source]

Create a task-specific model from command-line arguments. If model category (or task) and name are passed as an argument, then they are used. Otherwise, dataset.category and model.{category}.name are read from command-line arguments to read model category and name, respectively.

Parameters:
  • opts – Command-line arguments

  • category – Category or task (e.g., segmentation)

  • model_name – Model name for a specific task (e.g., vit for classification)

Returns:

An instance of cvnets.models.BaseAnyNNModel.

cvnets.models.arguments_model(parser: ArgumentParser) ArgumentParser[source]