cvnets.models.detection package
Subpackages
Submodules
cvnets.models.detection.base_detection module
- class cvnets.models.detection.base_detection.BaseDetection(opts: Namespace, encoder: BaseImageEncoder, *args, **kwargs)[source]
Bases:
BaseAnyNNModel
Base class for the task of object detection
- Parameters:
opts – Command-line arguments
encoder – Image-encoder model (e.g., MobileNet or ResNet)
- __init__(opts: Namespace, 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 model specific arguments
- static reset_layer_parameters(layer: Module, opts: Namespace) None [source]
Initialize weights of a given layer
- 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.
cvnets.models.detection.mask_rcnn module
- class cvnets.models.detection.mask_rcnn.MaskRCNNEncoder(opts: Namespace, encoder: BaseImageEncoder, output_strides: List, projection_channels: int, encoder_lr_multiplier: float | None = 1.0, *args, **kwargs)[source]
Bases:
Module
- __init__(opts: Namespace, encoder: BaseImageEncoder, output_strides: List, projection_channels: int, encoder_lr_multiplier: float | None = 1.0, *args, **kwargs) None [source]
Initializes internal Module state, shared by both nn.Module and ScriptModule.
- forward(x: Tensor) Dict[str, Tensor] [source]
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cvnets.models.detection.mask_rcnn.MaskRCNNDetector(opts, encoder: BaseImageEncoder, *args, **kwargs)[source]
Bases:
BaseDetection
This class implements a Mask RCNN style object detector <https://arxiv.org/abs/1703.06870>
- Parameters:
opts – command-line arguments
encoder (BaseImageEncoder) – Encoder network (e.g., ResNet or MobileViT)
- __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 model specific arguments
- get_trainable_parameters(weight_decay: float = 0.0, no_decay_bn_filter_bias: bool = False, *args, **kwargs) Tuple[List, List] [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
- forward(x: Dict, *args, **kwargs) Tuple[Tensor, ...] | Tuple[Any, ...] | Dict [source]
Implement the model-specific forward function in sub-classes.
- predict(x: Tensor, *args, **kwargs) DetectionPredTuple [source]
Predict the bounding boxes given an image tensor
cvnets.models.detection.ssd module
- class cvnets.models.detection.ssd.SingleShotMaskDetector(opts, encoder: BaseImageEncoder)[source]
Bases:
BaseDetection
This class implements a Single Shot Object Detector
- Parameters:
opts – command-line arguments
encoder (BaseImageEncoder) – Encoder network (e.g., ResNet or MobileViT)
- coordinates = 4
- __init__(opts, encoder: BaseImageEncoder) None [source]
Initializes internal Module state, shared by both nn.Module and ScriptModule.
- classmethod add_arguments(parser: ArgumentParser) ArgumentParser [source]
Add model specific arguments
- ssd_forward(end_points: Dict[str, Tensor], device: device | None = device(type='cpu'), *args, **kwargs) Tuple[Tensor, Tensor, Tensor] | Tuple[Tensor, ...] [source]
- forward(x: Tensor | Dict) Tuple[Tensor, ...] | Tuple[Any, ...] | Dict [source]
Implement the model-specific forward function in sub-classes.
- predict(x: Tensor, *args, **kwargs) DetectionPredTuple [source]
Predict the bounding boxes given an image tensor
- postprocess_detections(boxes: Tensor, scores: Tensor) List[DetectionPredTuple] [source]
Post process detections, including NMS