@@ -110,7 +110,8 @@ def tile_prediction(
110
110
sam_predictor : SAM2ImagePredictor ,
111
111
image : np .ndarray ,
112
112
overlap : float = 0.125 ,
113
- pad_bbox : int = 0 ,
113
+ bbox_conf : float = 0.4 ,
114
+ bbox_pad : int = 0 ,
114
115
) -> np .ndarray :
115
116
"""
116
117
Predict on a large image by splitting it into tiles.
@@ -123,7 +124,9 @@ def tile_prediction(
123
124
image (np.ndarray): Image to predict on.
124
125
overlap (float): Overlap between tiles.
125
126
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.
127
130
Defaults to 0.
128
131
129
132
Returns:
@@ -135,19 +138,19 @@ def tile_prediction(
135
138
tile_image = image [left :right , top :bottom ].copy ()
136
139
sam_predictor .set_image (tile_image )
137
140
138
- bbox_result = bbox_predictor .predict (tile_image , verbose = False )
141
+ bbox_result = bbox_predictor .predict (tile_image , conf = bbox_conf , verbose = False )
139
142
140
143
for bbox in bbox_result :
141
144
if len (bbox .boxes .xyxy ) == 0 :
142
145
continue
143
146
144
147
bbox_int = list (int (x ) for x in bbox .boxes .xyxy [0 ])
145
148
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 )
151
154
152
155
masks , * _ = sam_predictor .predict (
153
156
box = [bbox_int ],
0 commit comments