Skip to content

Commit 5b27747

Browse files
Merge pull request #1092 from misrasaurabh1/codeflash/optimize-select_top_confidence_detection-m7drsd4o
⚡️ Speed up function `select_top_confidence_detection` by 188%
2 parents 70cd538 + e843785 commit 5b27747

File tree

1 file changed

+3
-5
lines changed
  • inference/core/workflows/core_steps/common/query_language/operations/detections

1 file changed

+3
-5
lines changed

inference/core/workflows/core_steps/common/query_language/operations/detections/base.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,9 @@ def shift_detections(value: Any, shift_x: int, shift_y: int, **kwargs) -> sv.Det
106106

107107
def select_top_confidence_detection(detections: sv.Detections) -> sv.Detections:
108108
if len(detections) == 0:
109-
return deepcopy(detections)
110-
confidence = detections.confidence
111-
max_value = confidence.max()
112-
index = np.argwhere(confidence == max_value)[0].item()
113-
return detections[index]
109+
return detections # No need to deepcopy an empty detections object
110+
max_index = np.argmax(detections.confidence)
111+
return detections[max_index]
114112

115113

116114
def select_leftmost_detection(detections: sv.Detections) -> sv.Detections:

0 commit comments

Comments
 (0)