Reference for ultralytics/models/yolo/pose/predict.py
Note
This file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/models/yolo/pose/predict.py. If you spot a problem please help fix it by contributing a Pull Request 🛠️. Thank you 🙏!
ultralytics.models.yolo.pose.predict.PosePredictor
PosePredictor(cfg=DEFAULT_CFG, overrides=None, _callbacks=None)
Bases: DetectionPredictor
flowchart TD
ultralytics.models.yolo.pose.predict.PosePredictor[PosePredictor]
ultralytics.models.yolo.detect.predict.DetectionPredictor[DetectionPredictor]
ultralytics.engine.predictor.BasePredictor[BasePredictor]
ultralytics.models.yolo.detect.predict.DetectionPredictor --> ultralytics.models.yolo.pose.predict.PosePredictor
ultralytics.engine.predictor.BasePredictor --> ultralytics.models.yolo.detect.predict.DetectionPredictor
click ultralytics.models.yolo.pose.predict.PosePredictor href "" "ultralytics.models.yolo.pose.predict.PosePredictor"
click ultralytics.models.yolo.detect.predict.DetectionPredictor href "" "ultralytics.models.yolo.detect.predict.DetectionPredictor"
click ultralytics.engine.predictor.BasePredictor href "" "ultralytics.engine.predictor.BasePredictor"
A class extending the DetectionPredictor class for prediction based on a pose model.
This class specializes in pose estimation, handling keypoints detection alongside standard object detection capabilities inherited from DetectionPredictor.
Attributes:
| Name | Type | Description |
|---|---|---|
args |
namespace
| Configuration arguments for the predictor. |
model |
Module
| The loaded YOLO pose model with keypoint detection capabilities. |
Methods:
| Name | Description |
|---|---|
construct_result | Construct the result object from the prediction, including keypoints. |
Examples:
>>> from ultralytics.utils import ASSETS
>>> from ultralytics.models.yolo.pose import PosePredictor
>>> args = dict(model="yolo11n-pose.pt", source=ASSETS)
>>> predictor = PosePredictor(overrides=args)
>>> predictor.predict_cli()
Sets up a PosePredictor instance, configuring it for pose detection tasks and handling device-specific warnings for Apple MPS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg
|
Any
| Configuration for the predictor. |
DEFAULT_CFG
|
overrides
|
dict
| Configuration overrides that take precedence over cfg. |
None
|
_callbacks
|
list
| List of callback functions to be invoked during prediction. |
None
|
Examples:
>>> from ultralytics.utils import ASSETS
>>> from ultralytics.models.yolo.pose import PosePredictor
>>> args = dict(model="yolo11n-pose.pt", source=ASSETS)
>>> predictor = PosePredictor(overrides=args)
>>> predictor.predict_cli()
Source code in ultralytics/models/yolo/pose/predict.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
construct_result
construct_result(pred, img, orig_img, img_path)
Construct the result object from the prediction, including keypoints.
Extends the parent class implementation by extracting keypoint data from predictions and adding them to the result object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pred
|
Tensor
| The predicted bounding boxes, scores, and keypoints with shape (N, 6+K*D) where N is the number of detections, K is the number of keypoints, and D is the keypoint dimension. | required |
img
|
Tensor
| The processed input image tensor with shape (B, C, H, W). | required |
orig_img
|
ndarray
| The original unprocessed image as a numpy array. | required |
img_path
|
str
| The path to the original image file. | required |
Returns:
| Type | Description |
|---|---|
Results
| The result object containing the original image, image path, class names, bounding boxes, and keypoints. |
Source code in ultralytics/models/yolo/pose/predict.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |