loss_fn.detection package
Submodules
loss_fn.detection.base_detection_criteria module
- class loss_fn.detection.base_detection_criteria.BaseDetectionCriteria(opts: Namespace, *args, **kwargs)[source]
Bases:
BaseCriteria
Base class for defining detection loss functions. Sub-classes must implement forward function.
- Parameters:
opts – command line arguments
loss_fn.detection.mask_rcnn_loss module
- class loss_fn.detection.mask_rcnn_loss.MaskRCNNLoss(opts: Namespace, *args, **kwargs)[source]
Bases:
BaseDetectionCriteria
Mask RCNN loss is computed inside the MaskRCNN model. This class is a wrapper to extract loss values for different heads (RPN, classification, etc.) and compute the weighted sum.
- Parameters:
opts – command-line arguments
- __init__(opts: Namespace, *args, **kwargs) None [source]
Initializes internal Module state, shared by both nn.Module and ScriptModule.
- classmethod add_arguments(parser: ArgumentParser) ArgumentParser [source]
Add criterion-specific arguments to the parser.
- forward(input_sample: Any, prediction: Dict[str, Tensor], *args, **kwargs) Dict[str, Tensor] [source]
Compute MaskRCNN loss.
- Parameters:
input_sample – Input image tensor to the model.
prediction – Mapping of the Maskrcnn losses.
- Shapes:
input_sample: This loss function does not care about input to the model. prediction: Dictionary containing scalar Mask RCNN loss values. Expected keys are
loss_classifier, loss_box_reg, loss_mask, loss_objectness, loss_rpn_box_reg.
- Returns:
scalar) is returned. Output contains following keys: (total_loss, loss_classifier, loss_box_reg, loss_mask, loss_objectness, loss_rpn_box_reg).
- Return type:
A mapping of (string
loss_fn.detection.ssd_multibox_loss module
- class loss_fn.detection.ssd_multibox_loss.SSDLoss(opts: Namespace, *args, **kwargs)[source]
Bases:
BaseDetectionCriteria
Loss for single shot multi-box object detection
- Parameters:
opts – command-line arguments
- __init__(opts: Namespace, *args, **kwargs) None [source]
Initializes internal Module state, shared by both nn.Module and ScriptModule.
- reset_unscaled_loss_values() None [source]
Reset the unscaled coefficients for confidence and regression losses to small values
- classmethod add_arguments(parser: ArgumentParser) ArgumentParser [source]
Add criterion-specific arguments to the parser.
- forward(input_sample: Any, prediction: Dict[str, Tensor], target: Dict[str, Tensor], *args, **kwargs) Dict[str, Tensor] [source]
Compute the SSD Loss
- Parameters:
input_sample – Input image tensor to the model.
prediction – Model output. It is a mapping of the form (string: Tensor) containing two mandatory keys, i.e., scores and boxes
target – Ground truth labels. It is a mapping of the form (string: Tensor) containing two mandatory keys, i.e., box_labels and box_coordinates.
- Shape:
input_sample: This loss function does not care about input to the model. prediction[“scores”]: Shape is [Batch size, number of anchors, number of classes] prediction[“boxes”]: Shape is [Batch size, number of anchors, 4] where 4 is the number of box coordinates
target[“box_labels”]: Shape is [Batch size, number of anchors] target[“box_coordinates”]: Shape is [Batch size, number of anchors, 4]
- Returns:
scalar) is returned. Output contains following keys: (total_loss, reg_loss, cls_loss).
- Return type:
A mapping of (string