Skip to content

Commit

Permalink
Update IoU capitalization (#8604)
Browse files Browse the repository at this point in the history
Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
Co-authored-by: Dean Mark <2552482+deanmark@users.noreply.github.com>
  • Loading branch information
glenn-jocher and deanmark committed Mar 2, 2024
1 parent e0b8b36 commit 1146bb0
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion docs/en/guides/yolo-performance-metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Performance metrics are key tools to evaluate the accuracy and efficiency of obj
allowfullscreen>
</iframe>
<br>
<strong>Watch:</strong> Ultralytics YOLOv8 Performance Metrics | MAP, F1 Score, Precision, IOU & Accuracy
<strong>Watch:</strong> Ultralytics YOLOv8 Performance Metrics | MAP, F1 Score, Precision, IoU & Accuracy
</p>

## Object Detection Metrics
Expand Down
4 changes: 2 additions & 2 deletions docs/en/reference/utils/metrics.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
description: Explore Ultralytics YOLO metrics tools - from confusion matrix, detection metrics, pose metrics to box IOU. Learn how to compute and plot precision-recall curves.
keywords: Ultralytics, YOLO, YOLOv3, YOLOv4, metrics, confusion matrix, detection metrics, pose metrics, box IOU, mask IOU, plot precision-recall curves, compute average precision
description: Explore Ultralytics YOLO metrics tools - from confusion matrix, detection metrics, pose metrics to box IoU. Learn how to compute and plot precision-recall curves.
keywords: Ultralytics, YOLO, YOLOv3, YOLOv4, metrics, confusion matrix, detection metrics, pose metrics, box IoU, mask IoU, plot precision-recall curves, compute average precision
---

# Reference for `ultralytics/utils/metrics.py`
Expand Down
2 changes: 1 addition & 1 deletion ultralytics/engine/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1088,7 +1088,7 @@ def _pipeline_coreml(self, model, weights_dir=None, prefix=colorstr("CoreML Pipe
# Save the model
model = ct.models.MLModel(pipeline.spec, weights_dir=weights_dir)
model.input_description["image"] = "Input image"
model.input_description["iouThreshold"] = f"(optional) IOU threshold override (default: {nms.iouThreshold})"
model.input_description["iouThreshold"] = f"(optional) IoU threshold override (default: {nms.iouThreshold})"
model.input_description["confidenceThreshold"] = (
f"(optional) Confidence threshold override (default: {nms.confidenceThreshold})"
)
Expand Down
2 changes: 1 addition & 1 deletion ultralytics/models/yolo/detect/val.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self, dataloader=None, save_dir=None, pbar=None, args=None, _callba
self.class_map = None
self.args.task = "detect"
self.metrics = DetMetrics(save_dir=self.save_dir, on_plot=self.on_plot)
self.iouv = torch.linspace(0.5, 0.95, 10) # iou vector for mAP@0.5:0.95
self.iouv = torch.linspace(0.5, 0.95, 10) # IoU vector for mAP@0.5:0.95
self.niou = self.iouv.numel()
self.lb = [] # for autolabelling

Expand Down
6 changes: 3 additions & 3 deletions ultralytics/trackers/byte_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ class BYTETracker:
reset_id(): Resets the ID counter of STrack.
joint_stracks(tlista, tlistb): Combines two lists of stracks.
sub_stracks(tlista, tlistb): Filters out the stracks present in the second list from the first list.
remove_duplicate_stracks(stracksa, stracksb): Removes duplicate stracks based on IOU.
remove_duplicate_stracks(stracksa, stracksb): Removes duplicate stracks based on IoU.
"""

def __init__(self, args, frame_rate=30):
Expand Down Expand Up @@ -373,7 +373,7 @@ def init_track(self, dets, scores, cls, img=None):
return [STrack(xyxy, s, c) for (xyxy, s, c) in zip(dets, scores, cls)] if len(dets) else [] # detections

def get_dists(self, tracks, detections):
"""Calculates the distance between tracks and detections using IOU and fuses scores."""
"""Calculates the distance between tracks and detections using IoU and fuses scores."""
dists = matching.iou_distance(tracks, detections)
# TODO: mot20
# if not self.args.mot20:
Expand Down Expand Up @@ -428,7 +428,7 @@ def sub_stracks(tlista, tlistb):

@staticmethod
def remove_duplicate_stracks(stracksa, stracksb):
"""Remove duplicate stracks with non-maximum IOU distance."""
"""Remove duplicate stracks with non-maximum IoU distance."""
pdist = matching.iou_distance(stracksa, stracksb)
pairs = np.where(pdist < 0.15)
dupa, dupb = [], []
Expand Down
6 changes: 3 additions & 3 deletions ultralytics/utils/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def bbox_ioa(box1, box2, iou=False, eps=1e-7):
Args:
box1 (np.ndarray): A numpy array of shape (n, 4) representing n bounding boxes.
box2 (np.ndarray): A numpy array of shape (m, 4) representing m bounding boxes.
iou (bool): Calculate the standard iou if True else return inter_area/box2_area.
iou (bool): Calculate the standard IoU if True else return inter_area/box2_area.
eps (float, optional): A small value to avoid division by zero. Defaults to 1e-7.
Returns:
Expand Down Expand Up @@ -194,7 +194,7 @@ def _get_covariance_matrix(boxes):

def probiou(obb1, obb2, CIoU=False, eps=1e-7):
"""
Calculate the prob iou between oriented bounding boxes, https://arxiv.org/pdf/2106.06072v1.pdf.
Calculate the prob IoU between oriented bounding boxes, https://arxiv.org/pdf/2106.06072v1.pdf.
Args:
obb1 (torch.Tensor): A tensor of shape (N, 5) representing ground truth obbs, with xywhr format.
Expand Down Expand Up @@ -233,7 +233,7 @@ def probiou(obb1, obb2, CIoU=False, eps=1e-7):

def batch_probiou(obb1, obb2, eps=1e-7):
"""
Calculate the prob iou between oriented bounding boxes, https://arxiv.org/pdf/2106.06072v1.pdf.
Calculate the prob IoU between oriented bounding boxes, https://arxiv.org/pdf/2106.06072v1.pdf.
Args:
obb1 (torch.Tensor | np.ndarray): A tensor of shape (N, 5) representing ground truth obbs, with xywhr format.
Expand Down
4 changes: 2 additions & 2 deletions ultralytics/utils/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def nms_rotated(boxes, scores, threshold=0.45):
Args:
boxes (torch.Tensor): (N, 5), xywhr.
scores (torch.Tensor): (N, ).
threshold (float): Iou threshold.
threshold (float): IoU threshold.
Returns:
"""
Expand Down Expand Up @@ -287,7 +287,7 @@ def non_max_suppression(
# if merge and (1 < n < 3E3): # Merge NMS (boxes merged using weighted mean)
# # Update boxes as boxes(i,4) = weights(i,n) * boxes(n,4)
# from .metrics import box_iou
# iou = box_iou(boxes[i], boxes) > iou_thres # iou matrix
# iou = box_iou(boxes[i], boxes) > iou_thres # IoU matrix
# weights = iou * scores[None] # box weights
# x[i, :4] = torch.mm(weights, x[:, :4]).float() / weights.sum(1, keepdim=True) # merged boxes
# redundant = True # require redundant detections
Expand Down
6 changes: 3 additions & 3 deletions ultralytics/utils/tal.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def get_box_metrics(self, pd_scores, pd_bboxes, gt_labels, gt_bboxes, mask_gt):
return align_metric, overlaps

def iou_calculation(self, gt_bboxes, pd_bboxes):
"""Iou calculation for horizontal bounding boxes."""
"""IoU calculation for horizontal bounding boxes."""
return bbox_iou(gt_bboxes, pd_bboxes, xywh=False, CIoU=True).squeeze(-1).clamp_(0)

def select_topk_candidates(self, metrics, largest=True, topk_mask=None):
Expand Down Expand Up @@ -231,7 +231,7 @@ def select_candidates_in_gts(xy_centers, gt_bboxes, eps=1e-9):
@staticmethod
def select_highest_overlaps(mask_pos, overlaps, n_max_boxes):
"""
If an anchor box is assigned to multiple gts, the one with the highest IoI will be selected.
If an anchor box is assigned to multiple gts, the one with the highest IoU will be selected.
Args:
mask_pos (Tensor): shape(b, n_max_boxes, h*w)
Expand Down Expand Up @@ -260,7 +260,7 @@ def select_highest_overlaps(mask_pos, overlaps, n_max_boxes):

class RotatedTaskAlignedAssigner(TaskAlignedAssigner):
def iou_calculation(self, gt_bboxes, pd_bboxes):
"""Iou calculation for rotated bounding boxes."""
"""IoU calculation for rotated bounding boxes."""
return probiou(gt_bboxes, pd_bboxes).squeeze(-1).clamp_(0)

@staticmethod
Expand Down

0 comments on commit 1146bb0

Please sign in to comment.