deeplabcut.pose_estimation_pytorch.data.preprocessor
Helpers to run preprocess data before running inference.
Classes:
| Name | Description |
|---|---|
AugmentImage |
Adds an offset and scale key to the context: |
ComposePreprocessor |
Class to preprocess an image and turn it into a batch of inputs before running |
ComputeBoundingBoxesFromCondKeypoints |
Generates bounding boxes from predicted keypoints. |
FilterInvalidBoundingBoxes |
Filters out poses and bounding boxes that are invalid (e.g., area too small). |
FilterLowConfidencePoses |
Filters out poses with low confidence scores. |
LoadImage |
Loads an image from a file, if not yet loaded. |
Preprocessor |
Class to preprocess an image and turn it into a batch of inputs before running |
ToBatch |
Adds a batch dimension to the image tensor. |
ToTensor |
Transforms lists and numpy arrays into tensors. |
TopDownCrop |
Crops bounding boxes out of images for top-down pose estimation. |
Functions:
| Name | Description |
|---|---|
build_bottom_up_preprocessor |
Creates a preprocessor for bottom-up pose estimation (or object detection) |
build_conditional_top_down_preprocessor |
Creates a preprocessor for conditional top-down pose estimation. |
build_top_down_preprocessor |
Creates a preprocessor for top-down pose estimation. |
AugmentImage
Bases: Preprocessor
Adds an offset and scale key to the context
offset: (x, y) position of the pixel in the top left corner of the augmented image in the original image scale: size of the original image divided by the size of the new image
This allows to map the position of predictions in the transformed image back to the original image space. p_original = p_transformed * scale + offset p_transformed = (p_original - offset) / scale
Methods:
| Name | Description |
|---|---|
update_offsets_and_scales |
X = x' * scale' + offset'. |
Source code in deeplabcut/pose_estimation_pytorch/data/preprocessor.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | |
update_offsets_and_scales
staticmethod
X = x' * scale' + offset'.
x' = x'' * scale'' + offset'' -> x = x'' * (scale' * scale'') + (scale' * offset'' + offset')
Source code in deeplabcut/pose_estimation_pytorch/data/preprocessor.py
ComposePreprocessor
Bases: Preprocessor
Class to preprocess an image and turn it into a batch of inputs before running inference.
Source code in deeplabcut/pose_estimation_pytorch/data/preprocessor.py
ComputeBoundingBoxesFromCondKeypoints
Bases: Preprocessor
Generates bounding boxes from predicted keypoints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
The key under which cond. keypoints are stored in the context. |
'cond_kpts'
|
|
int
|
The margin to add around keypoints when generating bounding boxes. |
0
|
Methods:
| Name | Description |
|---|---|
__call__ |
TODO: numpy implementation |
Source code in deeplabcut/pose_estimation_pytorch/data/preprocessor.py
__call__
TODO: numpy implementation
Source code in deeplabcut/pose_estimation_pytorch/data/preprocessor.py
FilterInvalidBoundingBoxes
Bases: Preprocessor
Filters out poses and bounding boxes that are invalid (e.g., area too small).
Source code in deeplabcut/pose_estimation_pytorch/data/preprocessor.py
FilterLowConfidencePoses
Bases: Preprocessor
Filters out poses with low confidence scores.
By default, the confidence associated to the pose is the max confidence value.
Source code in deeplabcut/pose_estimation_pytorch/data/preprocessor.py
LoadImage
Bases: Preprocessor
Loads an image from a file, if not yet loaded.
Source code in deeplabcut/pose_estimation_pytorch/data/preprocessor.py
Preprocessor
Bases: ABC
Class to preprocess an image and turn it into a batch of inputs before running inference.
As an example, a pre-processor can load an image, use a "bboxes" key from context to crop bounding boxes for individuals (going from a (h, w, 3) array to a (num_individuals, h, w, 3) array), and convert it into a tensor ready for inference.
Methods:
| Name | Description |
|---|---|
__call__ |
Pre-processes an image. |
Source code in deeplabcut/pose_estimation_pytorch/data/preprocessor.py
__call__
abstractmethod
Pre-processes an image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Image
|
an image (containing height, width and channel dimensions) or a batch of images linked to a single input (containing an extra batch dimension) |
required |
|
Context
|
the context for this image or batch of images (such as bounding boxes, conditional pose, ...) |
required |
Returns:
| Type | Description |
|---|---|
tuple[Image, Context]
|
the pre-processed image (or batch of images) and their context |
Source code in deeplabcut/pose_estimation_pytorch/data/preprocessor.py
ToBatch
Bases: Preprocessor
Adds a batch dimension to the image tensor.
This preprocessor is used to convert a single image tensor into a batched format by
unsqueezing along the 0th dimension. This is typically required before passing the
image to models that expect batched input (i.e., shape [B, C, H, W]).
Source code in deeplabcut/pose_estimation_pytorch/data/preprocessor.py
ToTensor
Bases: Preprocessor
Transforms lists and numpy arrays into tensors.
Source code in deeplabcut/pose_estimation_pytorch/data/preprocessor.py
TopDownCrop
Bases: Preprocessor
Crops bounding boxes out of images for top-down pose estimation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
int | tuple[int, int]
|
The (width, height) of crops to output |
required |
|
int
|
The margin to add around detected bounding boxes before cropping |
0
|
|
bool
|
Whether to keep context in the top-down crop |
True
|
Methods:
| Name | Description |
|---|---|
__call__ |
TODO: numpy implementation |
Source code in deeplabcut/pose_estimation_pytorch/data/preprocessor.py
__call__
TODO: numpy implementation
Source code in deeplabcut/pose_estimation_pytorch/data/preprocessor.py
build_bottom_up_preprocessor
Creates a preprocessor for bottom-up pose estimation (or object detection)
Creates a preprocessor that loads an image, runs some transform on it (such as normalization), creates a tensor from the numpy array (going from (h, w, 3) to (3, h, w)) and adds a batch dimension (so the final tensor shape is (1, 3, h, w))
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
whether to load the image as an RGB or BGR |
required |
|
BaseCompose
|
the transform to apply to the image |
required |
Returns:
| Type | Description |
|---|---|
Preprocessor
|
A default bottom-up Preprocessor |
Source code in deeplabcut/pose_estimation_pytorch/data/preprocessor.py
build_conditional_top_down_preprocessor
build_conditional_top_down_preprocessor(
color_mode: str,
transform: BaseCompose,
bbox_margin: int,
top_down_crop_size: tuple[int, int],
top_down_crop_margin: int = 0,
top_down_crop_with_context: bool = False,
) -> Preprocessor
Creates a preprocessor for conditional top-down pose estimation.
Creates a preprocessor that loads an image, computes bounding boxes from conditional keypoints (given as a context (through a "cond_kpts" key), crops all bounding boxes, runs some transforms on each cropped image (such as normalization), creates a tensor from the numpy array (going from (num_ind, h, w, 3) to (num_ind, 3, h, w)).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
whether to load the image as an RGB or BGR |
required |
|
BaseCompose
|
the transform to apply to the image |
required |
|
int
|
The margin to add around keypoints when generating bounding boxes from conditional keypoints. |
required |
|
tuple[int, int]
|
the (width, height) to resize cropped bboxes to |
required |
|
int
|
the margin to add around detected bboxes for the crop |
0
|
|
bool
|
whether to keep context when applying the top-down crop |
False
|
Returns:
| Type | Description |
|---|---|
Preprocessor
|
A default conditional top-down Preprocessor |
Source code in deeplabcut/pose_estimation_pytorch/data/preprocessor.py
build_top_down_preprocessor
build_top_down_preprocessor(
color_mode: str,
transform: BaseCompose,
top_down_crop_size: tuple[int, int],
top_down_crop_margin: int = 0,
top_down_crop_with_context: bool = True,
) -> Preprocessor
Creates a preprocessor for top-down pose estimation.
Creates a preprocessor that loads an image, crops all bounding boxes given as a context (through a "bboxes" key), runs some transforms on each cropped image (such as normalization), creates a tensor from the numpy array (going from (num_ind, h, w, 3) to (num_ind, 3, h, w)).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
whether to load the image as an RGB or BGR |
required |
|
BaseCompose
|
the transform to apply to the image |
required |
|
tuple[int, int]
|
the (width, height) to resize cropped bboxes to |
required |
|
int
|
the margin to add around detected bboxes for the crop |
0
|
|
bool
|
whether to keep context when applying the top-down crop |
True
|
Returns:
| Type | Description |
|---|---|
Preprocessor
|
A default top-down Preprocessor |