Skip to content

Commit 70cd538

Browse files
Merge pull request #1093 from misrasaurabh1/codeflash/optimize-select_leftmost_detection-m7drw59y
⚡️ Speed up function `select_leftmost_detection` by 153%
2 parents 00f2731 + c6f6996 commit 70cd538

File tree

1 file changed

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

1 file changed

+3
-3
lines changed

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ def select_top_confidence_detection(detections: sv.Detections) -> sv.Detections:
115115

116116
def select_leftmost_detection(detections: sv.Detections) -> sv.Detections:
117117
if len(detections) == 0:
118-
return deepcopy(detections)
118+
return detections # Directly return the original empty detections if empty
119+
119120
centers_x = detections.get_anchors_coordinates(anchor=Position.CENTER)[:, 0]
120-
min_value = centers_x.min()
121-
index = np.argwhere(centers_x == min_value)[0].item()
121+
index = np.argmin(centers_x)
122122
return detections[index]
123123

124124

0 commit comments

Comments
 (0)