Convert supervision/metrics/precision.py docstrings to doctests
--- Co-authored-by: copilot-swe-agent[bot] <198982749+copilot@users.noreply.github.com>
This commit is contained in:
committed by
Jirka Borovec
co-authored by
copilot-swe-agent[bot]
parent
a542406945
commit
c999fad06f
@@ -39,37 +39,23 @@ class Precision(Metric):
|
||||
Here, `TP` is the number of true positives (correct detections), and `FP` is the
|
||||
number of false positive detections (detected, but incorrectly).
|
||||
|
||||
Example:
|
||||
```python
|
||||
import supervision as sv
|
||||
from supervision.metrics import Precision
|
||||
|
||||
predictions = sv.Detections(...)
|
||||
targets = sv.Detections(...)
|
||||
|
||||
precision_metric = Precision()
|
||||
precision_result = precision_metric.update(predictions, targets).compute()
|
||||
|
||||
print(precision_result.precision_at_50)
|
||||
# 0.8099
|
||||
|
||||
print(precision_result)
|
||||
# PrecisionResult:
|
||||
# Metric target: MetricTarget.BOXES
|
||||
# Averaging method: AveragingMethod.WEIGHTED
|
||||
# P @ 50: 0.8099
|
||||
# P @ 75: 0.7969
|
||||
# P @ thresh: [0.80992 0.80905 0.80905 ...]
|
||||
# IoU thresh: [0.5 0.55 0.6 ...]
|
||||
# Precision per class:
|
||||
# 0: [0.64706 0.64706 0.64706 ...]
|
||||
# ...
|
||||
# Small objects: ...
|
||||
# Medium objects: ...
|
||||
# Large objects: ...
|
||||
|
||||
print(precision_result.small_objects.precision_at_50)
|
||||
```
|
||||
Examples:
|
||||
>>> import numpy as np
|
||||
>>> import supervision as sv
|
||||
>>> from supervision.metrics import Precision
|
||||
>>> predictions = sv.Detections(
|
||||
... xyxy=np.array([[0, 0, 10, 10]]),
|
||||
... class_id=np.array([0]),
|
||||
... confidence=np.array([0.9])
|
||||
... )
|
||||
>>> targets = sv.Detections(
|
||||
... xyxy=np.array([[0, 0, 10, 10]]),
|
||||
... class_id=np.array([0])
|
||||
... )
|
||||
>>> precision_metric = Precision()
|
||||
>>> precision_result = precision_metric.update(predictions, targets).compute()
|
||||
>>> round(float(precision_result.precision_at_50), 2)
|
||||
1.0
|
||||
|
||||
![example_plot](\
|
||||
https://media.roboflow.com/supervision-docs/metrics/precision_plot_example.png\
|
||||
|
||||
Reference in New Issue
Block a user