(self, image_pil, image, boxes_filt)
| 854 | |
| 855 | |
| 856 | def get_mask_with_boxes(self, image_pil, image, boxes_filt): |
| 857 | |
| 858 | size = image_pil.size |
| 859 | H, W = size[1], size[0] |
| 860 | for i in range(boxes_filt.size(0)): |
| 861 | boxes_filt[i] = boxes_filt[i] * torch.Tensor([W, H, W, H]) |
| 862 | boxes_filt[i][:2] -= boxes_filt[i][2:] / 2 |
| 863 | boxes_filt[i][2:] += boxes_filt[i][:2] |
| 864 | |
| 865 | boxes_filt = boxes_filt.cpu() |
| 866 | transformed_boxes = self.sam_predictor.transform.apply_boxes_torch(boxes_filt, image.shape[:2]).to(self.device) |
| 867 | |
| 868 | masks, _, _ = self.sam_predictor.predict_torch( |
| 869 | point_coords = None, |
| 870 | point_labels = None, |
| 871 | boxes = transformed_boxes.to(self.device), |
| 872 | multimask_output = False, |
| 873 | ) |
| 874 | return masks |
| 875 | |
| 876 | def segment_image_with_boxes(self, image_pil, image_path, boxes_filt, pred_phrases): |
| 877 |
no outgoing calls
no test coverage detected