Skip to content

deeplabcut.pose_estimation_pytorch.models.predictors.base

Classes:

Name Description
BasePredictor

The base Predictor class.

BasePredictor

Bases: ABC, Module

The base Predictor class.

This class is an abstract base class (ABC) for defining predictors used in the DeepLabCut Toolbox. All predictor classes should inherit from this base class and implement the forward method. Regresses keypoint coordinates from a models output maps

Attributes:

Name Type Description
num_animals

Number of animals in the project. Should be set in subclasses.

Example

Create a subclass that inherits from BasePredictor and implements the forward method.

class MyPredictor(BasePredictor): def init(self, num_animals): super().init() self.num_animals = num_animals

def forward(self, outputs):
    # Implement the forward pass of your custom predictor here.
    pass

Methods:

Name Description
forward

Abstract method for the forward pass of the Predictor.

Source code in deeplabcut/pose_estimation_pytorch/models/predictors/base.py
class BasePredictor(ABC, nn.Module):
    """The base Predictor class.

    This class is an abstract base class (ABC) for defining predictors used in the DeepLabCut Toolbox.
    All predictor classes should inherit from this base class and implement the forward method.
    Regresses keypoint coordinates from a models output maps

    Attributes:
        num_animals: Number of animals in the project. Should be set in subclasses.

    Example:
        # Create a subclass that inherits from BasePredictor and implements the forward method.
        class MyPredictor(BasePredictor):
            def __init__(self, num_animals):
                super().__init__()
                self.num_animals = num_animals

            def forward(self, outputs):
                # Implement the forward pass of your custom predictor here.
                pass
    """

    def __init__(self):
        super().__init__()
        self.num_animals = None

    @abstractmethod
    def forward(self, stride: float, outputs: dict[str, torch.Tensor]) -> dict[str, torch.Tensor]:
        """Abstract method for the forward pass of the Predictor.

        Args:
            stride: the stride of the model
            outputs: outputs of the model heads

        Returns:
            A dictionary containing a "poses" key with the output tensor as value, and
            optionally a "unique_bodyparts" with the unique bodyparts tensor as value.

        Raises:
            NotImplementedError: This method must be implemented in subclasses.
        """
        pass

forward abstractmethod

forward(stride: float, outputs: dict[str, Tensor]) -> dict[str, torch.Tensor]

Abstract method for the forward pass of the Predictor.

Parameters:

Name Type Description Default

stride

float

the stride of the model

required

outputs

dict[str, Tensor]

outputs of the model heads

required

Returns:

Type Description
dict[str, Tensor]

A dictionary containing a "poses" key with the output tensor as value, and optionally a "unique_bodyparts" with the unique bodyparts tensor as value.

Raises:

Type Description
NotImplementedError

This method must be implemented in subclasses.

Source code in deeplabcut/pose_estimation_pytorch/models/predictors/base.py
@abstractmethod
def forward(self, stride: float, outputs: dict[str, torch.Tensor]) -> dict[str, torch.Tensor]:
    """Abstract method for the forward pass of the Predictor.

    Args:
        stride: the stride of the model
        outputs: outputs of the model heads

    Returns:
        A dictionary containing a "poses" key with the output tensor as value, and
        optionally a "unique_bodyparts" with the unique bodyparts tensor as value.

    Raises:
        NotImplementedError: This method must be implemented in subclasses.
    """
    pass