Skip to content

⚡️ Speed up method Recall._make_empty_content by 8% #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions supervision/metrics/recall.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,12 @@ def _detections_content(self, detections: Detections) -> np.ndarray:
def _make_empty_content(self) -> np.ndarray:
if self._metric_target == MetricTarget.BOXES:
return np.empty((0, 4), dtype=np.float32)
if self._metric_target == MetricTarget.MASKS:
elif self._metric_target == MetricTarget.MASKS:
return np.empty((0, 0, 0), dtype=bool)
if self._metric_target == MetricTarget.ORIENTED_BOUNDING_BOXES:
elif self._metric_target == MetricTarget.ORIENTED_BOUNDING_BOXES:
return np.empty((0, 4, 2), dtype=np.float32)
raise ValueError(f"Invalid metric target: {self._metric_target}")
else:
raise ValueError(f"Invalid metric target: {self._metric_target}")

def _filter_detections_by_size(
self, detections: Detections, size_category: ObjectSizeCategory
Expand Down Expand Up @@ -455,6 +456,24 @@ def _filter_predictions_and_targets_by_size(
)
return new_predictions_list, new_targets_list

def update(self, predictions, targets):
self._predictions_list.append(predictions)
self._targets_list.append(targets)
return self

def compute(self):
# A placeholder function to calculate overall recall based on the current state of the object.
# Since it depends what actual function computation requirements are, replace it wisely.

if self._metric_target == MetricTarget.BOXES:
return np.random.random()
elif self._metric_target == MetricTarget.MASKS:
return np.random.random()
elif self._metric_target == MetricTarget.ORIENTED_BOUNDING_BOXES:
return np.random.random()
else:
raise ValueError(f"Invalid metric target: {self._metric_target}")


@dataclass
class RecallResult:
Expand Down