Reference for ultralytics/models/yolo/detect/val.py
Note
This file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/models/yolo/detect/val.py. If you spot a problem please help fix it by contributing a Pull Request 🛠️. Thank you 🙏!
ultralytics.models.yolo.detect.val.DetectionValidator
Bases: BaseValidator
A class extending the BaseValidator class for validation based on a detection model.
Example
Source code in ultralytics/models/yolo/detect/val.py
_prepare_batch
Prepares a batch of images and annotations for validation.
Source code in ultralytics/models/yolo/detect/val.py
_prepare_pred
Prepares a batch of images and annotations for validation.
Source code in ultralytics/models/yolo/detect/val.py
_process_batch
Return correct prediction matrix.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
detections
|
Tensor
|
Tensor of shape (N, 6) representing detections where each detection is (x1, y1, x2, y2, conf, class). |
required |
gt_bboxes
|
Tensor
|
Tensor of shape (M, 4) representing ground-truth bounding box coordinates. Each bounding box is of the format: (x1, y1, x2, y2). |
required |
gt_cls
|
Tensor
|
Tensor of shape (M,) representing target class indices. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
Correct prediction matrix of shape (N, 10) for 10 IoU levels. |
Note
The function does not return any value directly usable for metrics calculation. Instead, it provides an intermediate representation used for evaluating predictions against ground truth.
Source code in ultralytics/models/yolo/detect/val.py
build_dataset
Build YOLO Dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img_path
|
str
|
Path to the folder containing images. |
required |
mode
|
str
|
|
'val'
|
batch
|
int
|
Size of batches, this is for |
None
|
Source code in ultralytics/models/yolo/detect/val.py
eval_json
Evaluates YOLO output in JSON format and returns performance statistics.
Source code in ultralytics/models/yolo/detect/val.py
finalize_metrics
Set final values for metrics speed and confusion matrix.
get_dataloader
Construct and return dataloader.
Source code in ultralytics/models/yolo/detect/val.py
get_desc
Return a formatted string summarizing class metrics of YOLO model.
get_stats
Returns metrics statistics and results dictionary.
Source code in ultralytics/models/yolo/detect/val.py
init_metrics
Initialize evaluation metrics for YOLO.
Source code in ultralytics/models/yolo/detect/val.py
plot_predictions
Plots predicted bounding boxes on input images and saves the result.
Source code in ultralytics/models/yolo/detect/val.py
plot_val_samples
Plot validation image samples.
Source code in ultralytics/models/yolo/detect/val.py
postprocess
Apply Non-maximum suppression to prediction outputs.
Source code in ultralytics/models/yolo/detect/val.py
pred_to_json
Serialize YOLO predictions to COCO json format.
Source code in ultralytics/models/yolo/detect/val.py
preprocess
Preprocesses batch of images for YOLO training.
Source code in ultralytics/models/yolo/detect/val.py
print_results
Prints training/validation set metrics per class.
Source code in ultralytics/models/yolo/detect/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/detect/val.py
update_metrics
Metrics.