cvnets.models.segmentation package
Subpackages
Submodules
cvnets.models.segmentation.base_seg module
- class cvnets.models.segmentation.base_seg.BaseSegmentation(opts, encoder: BaseImageEncoder, *args, **kwargs)[source]
Bases:
BaseAnyNNModel
Base class for segmentation networks.
- Parameters:
opts – Command-line arguments
encoder – Image classification network
- __init__(opts, encoder: BaseImageEncoder, *args, **kwargs) None [source]
Initializes internal Module state, shared by both nn.Module and ScriptModule.
- classmethod add_arguments(parser: ArgumentParser) ArgumentParser [source]
Add segmentation model specific arguments
- dummy_input_and_label(batch_size: int) Dict [source]
Create dummy input and labels for CI/CD purposes. Child classes must override it if functionality is different.
- cvnets.models.segmentation.base_seg.set_model_specific_opts_before_model_building(opts: Namespace) Dict[str, Any] [source]
Override library-level defaults with model-specific default values.
- Parameters:
opts – Command-line arguments
- Returns:
A dictionary containing the name of arguments that are updated along with their original values. This dictionary is used in unset_model_specific_opts_after_model_building function to unset the model-specific to library-specific defaults.
- cvnets.models.segmentation.base_seg.unset_model_specific_opts_after_model_building(opts: Namespace, default_opts_info: Dict[str, Any], *ars, **kwargs) None [source]
Given command-line arguments and a mapping of opts that needs to be unset, this function unsets the library-level defaults that were over-ridden previously in set_model_specific_opts_before_model_building.
cvnets.models.segmentation.enc_dec module
- class cvnets.models.segmentation.enc_dec.SegEncoderDecoder(opts, encoder: BaseImageEncoder, seg_head, *args, **kwargs)[source]
Bases:
BaseSegmentation
This class defines a encoder-decoder architecture for the task of semantic segmentation. Different segmentation heads (e.g., PSPNet and DeepLabv3) can be used
- Parameters:
opts – command-line arguments
encoder (BaseImageEncoder) – Backbone network (e.g., MobileViT or ResNet)
- __init__(opts, encoder: BaseImageEncoder, seg_head, *args, **kwargs) None [source]
Initializes internal Module state, shared by both nn.Module and ScriptModule.
- get_trainable_parameters(weight_decay: float | None = 0.0, no_decay_bn_filter_bias: bool | None = False, *args, **kwargs)[source]
This function separates the parameters for backbone and segmentation head, so that different learning rates can be used for backbone and segmentation head
- forward(x: Tensor, *args, **kwargs) Tuple[Tensor, Tensor] | Tensor | Dict [source]
Implement the model-specific forward function in sub-classes.
- update_classifier(opts, n_classes: int) None [source]
This function updates the classification layer in a model. Useful for finetuning purposes.
- 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.