Reference for ultralytics/models/yolo/pose/val.py
Note
This file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/models/yolo/pose/val.py. If you spot a problem please help fix it by contributing a Pull Request 🛠️. Thank you 🙏!
ultralytics.models.yolo.pose.val.PoseValidator
Bases: DetectionValidator
A class extending the DetectionValidator class for validation based on a pose model.
Example
Source code in ultralytics/models/yolo/pose/val.py
_prepare_batch
Prepares a batch for processing by converting keypoints to float and moving to device.
Source code in ultralytics/models/yolo/pose/val.py
_prepare_pred
Prepares and scales keypoints in a batch for pose processing.
Source code in ultralytics/models/yolo/pose/val.py
_process_batch
Return correct prediction matrix by computing Intersection over Union (IoU) between detections and ground truth.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
detections
|
Tensor
|
Tensor with shape (N, 6) representing detection boxes and scores, where each detection is of the format (x1, y1, x2, y2, conf, class). |
required |
gt_bboxes
|
Tensor
|
Tensor with shape (M, 4) representing ground truth bounding boxes, where each box is of the format (x1, y1, x2, y2). |
required |
gt_cls
|
Tensor
|
Tensor with shape (M,) representing ground truth class indices. |
required |
pred_kpts
|
Tensor | None
|
Optional tensor with shape (N, 51) representing predicted keypoints, where 51 corresponds to 17 keypoints each having 3 values. |
None
|
gt_kpts
|
Tensor | None
|
Optional tensor with shape (N, 51) representing ground truth keypoints. |
None
|
Returns:
Type | Description |
---|---|
Tensor
|
A tensor with shape (N, 10) representing the correct prediction matrix for 10 IoU levels, where N is the number of detections. |
Example
detections = torch.rand(100, 6) # 100 predictions: (x1, y1, x2, y2, conf, class)
gt_bboxes = torch.rand(50, 4) # 50 ground truth boxes: (x1, y1, x2, y2)
gt_cls = torch.randint(0, 2, (50,)) # 50 ground truth class indices
pred_kpts = torch.rand(100, 51) # 100 predicted keypoints
gt_kpts = torch.rand(50, 51) # 50 ground truth keypoints
correct_preds = _process_batch(detections, gt_bboxes, gt_cls, pred_kpts, gt_kpts)
Note
0.53
scale factor used in area computation is referenced from https://github.com/jin-s13/xtcocoapi/blob/master/xtcocotools/cocoeval.py#L384.
Source code in ultralytics/models/yolo/pose/val.py
eval_json
Evaluates object detection model using COCO JSON format.
Source code in ultralytics/models/yolo/pose/val.py
get_desc
Returns description of evaluation metrics in string format.
Source code in ultralytics/models/yolo/pose/val.py
init_metrics
Initiate pose estimation metrics for YOLO model.
Source code in ultralytics/models/yolo/pose/val.py
plot_predictions
Plots predictions for YOLO model.
Source code in ultralytics/models/yolo/pose/val.py
plot_val_samples
Plots and saves validation set samples with predicted bounding boxes and keypoints.
Source code in ultralytics/models/yolo/pose/val.py
pred_to_json
Converts YOLO predictions to COCO JSON format.
Source code in ultralytics/models/yolo/pose/val.py
preprocess
Preprocesses the batch by converting the 'keypoints' data into a float and moving it to the device.
Source code in ultralytics/models/yolo/pose/val.py
save_one_txt
Save YOLO detections to a txt file in normalized coordinates in a specific format.
Source code in ultralytics/models/yolo/pose/val.py
update_metrics
Metrics.