Skip to content

Commit 96253e2

Browse files
committed
enh(inference): add bbox_conf arg.
1 parent c59334c commit 96253e2

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/osm_ai_helper/utils/inference.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ def tile_prediction(
110110
sam_predictor: SAM2ImagePredictor,
111111
image: np.ndarray,
112112
overlap: float = 0.125,
113-
pad_bbox: int = 0,
113+
bbox_conf: float = 0.4,
114+
bbox_pad: int = 0,
114115
) -> np.ndarray:
115116
"""
116117
Predict on a large image by splitting it into tiles.
@@ -123,7 +124,9 @@ def tile_prediction(
123124
image (np.ndarray): Image to predict on.
124125
overlap (float): Overlap between tiles.
125126
Defaults to 0.125.
126-
pad_bbox (int): Padding to be added to the predicted bbox.
127+
bbox_conf (float): Sets the minimum confidence threshold for detections.
128+
Defaults to 0.4.
129+
bbox_pad (int): Padding to be added to the predicted bbox.
127130
Defaults to 0.
128131
129132
Returns:
@@ -135,19 +138,19 @@ def tile_prediction(
135138
tile_image = image[left:right, top:bottom].copy()
136139
sam_predictor.set_image(tile_image)
137140

138-
bbox_result = bbox_predictor.predict(tile_image, verbose=False)
141+
bbox_result = bbox_predictor.predict(tile_image, conf=bbox_conf, verbose=False)
139142

140143
for bbox in bbox_result:
141144
if len(bbox.boxes.xyxy) == 0:
142145
continue
143146

144147
bbox_int = list(int(x) for x in bbox.boxes.xyxy[0])
145148

146-
if pad_bbox > 0:
147-
bbox_int[0] = max(0, bbox_int[0] - pad_bbox)
148-
bbox_int[1] = max(0, bbox_int[1] - pad_bbox)
149-
bbox_int[2] = min(512, bbox_int[2] + pad_bbox)
150-
bbox_int[3] = min(512, bbox_int[3] + pad_bbox)
149+
if bbox_pad > 0:
150+
bbox_int[0] = max(0, bbox_int[0] - bbox_pad)
151+
bbox_int[1] = max(0, bbox_int[1] - bbox_pad)
152+
bbox_int[2] = min(512, bbox_int[2] + bbox_pad)
153+
bbox_int[3] = min(512, bbox_int[3] + bbox_pad)
151154

152155
masks, *_ = sam_predictor.predict(
153156
box=[bbox_int],

0 commit comments

Comments
 (0)