(self,
img_list,
slice_size=[640, 640],
overlap_ratio=[0.25, 0.25],
combine_method='nms',
match_threshold=0.6,
match_metric='ios',
run_benchmark=False,
repeats=1,
visual=True,
save_results=False)
| 242 | return self.det_times |
| 243 | |
| 244 | def predict_image_slice(self, |
| 245 | img_list, |
| 246 | slice_size=[640, 640], |
| 247 | overlap_ratio=[0.25, 0.25], |
| 248 | combine_method='nms', |
| 249 | match_threshold=0.6, |
| 250 | match_metric='ios', |
| 251 | run_benchmark=False, |
| 252 | repeats=1, |
| 253 | visual=True, |
| 254 | save_results=False): |
| 255 | # slice infer only support bs=1 |
| 256 | results = [] |
| 257 | try: |
| 258 | import sahi |
| 259 | from sahi.slicing import slice_image |
| 260 | except Exception as e: |
| 261 | print( |
| 262 | 'sahi not found, plaese install sahi. ' |
| 263 | 'for example: `pip install sahi`, see https://github.com/obss/sahi.' |
| 264 | ) |
| 265 | raise e |
| 266 | num_classes = len(self.pred_config.labels) |
| 267 | for i in range(len(img_list)): |
| 268 | ori_image = img_list[i] |
| 269 | slice_image_result = sahi.slicing.slice_image( |
| 270 | image=ori_image, |
| 271 | slice_height=slice_size[0], |
| 272 | slice_width=slice_size[1], |
| 273 | overlap_height_ratio=overlap_ratio[0], |
| 274 | overlap_width_ratio=overlap_ratio[1]) |
| 275 | sub_img_num = len(slice_image_result) |
| 276 | merged_bboxs = [] |
| 277 | print('slice to {} sub_samples.', sub_img_num) |
| 278 | |
| 279 | batch_image_list = [ |
| 280 | slice_image_result.images[_ind] for _ind in range(sub_img_num) |
| 281 | ] |
| 282 | if run_benchmark: |
| 283 | # preprocess |
| 284 | inputs = self.preprocess(batch_image_list) # warmup |
| 285 | self.det_times.preprocess_time_s.start() |
| 286 | inputs = self.preprocess(batch_image_list) |
| 287 | self.det_times.preprocess_time_s.end() |
| 288 | |
| 289 | # model prediction |
| 290 | result = self.predict(repeats=50, run_benchmark=True) # warmup |
| 291 | self.det_times.inference_time_s.start() |
| 292 | result = self.predict(repeats=repeats, run_benchmark=True) |
| 293 | self.det_times.inference_time_s.end(repeats=repeats) |
| 294 | |
| 295 | # postprocess |
| 296 | result_warmup = self.postprocess(inputs, result) # warmup |
| 297 | self.det_times.postprocess_time_s.start() |
| 298 | result = self.postprocess(inputs, result) |
| 299 | self.det_times.postprocess_time_s.end() |
| 300 | self.det_times.img_num += 1 |
| 301 |
no test coverage detected