Skip to content

criterion_adapter

orchard.tasks.detection.criterion_adapter

Detection Criterion Adapter.

Detection models (e.g. Faster R-CNN) compute losses internally during the forward pass — no external criterion is needed. This adapter returns a sentinel module that raises on accidental use.

DetectionCriterionAdapter

Returns a no-op sentinel criterion for detection tasks.

get_criterion(training, class_weights=None)

Return a sentinel criterion.

Detection models compute their own losses internally (classification loss, box regression loss, objectness, RPN box reg). The returned module raises RuntimeError if its forward() is ever called, making misuse immediately visible.

Parameters:

Name Type Description Default
training TrainingConfig

Training sub-config (ignored for detection).

required
class_weights Tensor | None

Per-class weights (ignored for detection).

None

Returns:

Type Description
Module

Sentinel nn.Module that raises on forward.

Source code in orchard/tasks/detection/criterion_adapter.py
def get_criterion(
    self,
    training: TrainingConfig,  # noqa: ARG002
    class_weights: torch.Tensor | None = None,  # noqa: ARG002
) -> nn.Module:
    """
    Return a sentinel criterion.

    Detection models compute their own losses internally (classification
    loss, box regression loss, objectness, RPN box reg). The returned
    module raises ``RuntimeError`` if its ``forward()`` is ever called,
    making misuse immediately visible.

    Args:
        training: Training sub-config (ignored for detection).
        class_weights: Per-class weights (ignored for detection).

    Returns:
        Sentinel ``nn.Module`` that raises on forward.
    """
    return _DetectionNoOpCriterion()