(*args, **kwargs)
| 282 | return selected_idx |
| 283 | |
| 284 | def masks_update(*args, **kwargs): |
| 285 | # remove redundant masks based on the scores and overlap rate between masks |
| 286 | masks_new = () |
| 287 | for masks_lvl in (args): |
| 288 | seg_pred = torch.from_numpy(np.stack([m['segmentation'] for m in masks_lvl], axis=0)).cuda() |
| 289 | iou_pred = torch.from_numpy(np.stack([m['predicted_iou'] for m in masks_lvl], axis=0)).cuda() |
| 290 | stability = torch.from_numpy(np.stack([m['stability_score'] for m in masks_lvl], axis=0)).cuda() |
| 291 | |
| 292 | scores = stability * iou_pred |
| 293 | keep_mask_nms = mask_nms(seg_pred, scores, **kwargs) |
| 294 | masks_lvl = filter(keep_mask_nms, masks_lvl) |
| 295 | |
| 296 | masks_new += (masks_lvl,) |
| 297 | return masks_new |
| 298 | |
| 299 | def sam_encoder(image): |
| 300 | image = cv2.cvtColor(image[0].permute(1,2,0).numpy().astype(np.uint8), cv2.COLOR_BGR2RGB) |
no test coverage detected