(self, img, is_positive: bool,
evt: gr.SelectData)
| 922 | |
| 923 | |
| 924 | def segment_image_with_click(self, img, is_positive: bool, |
| 925 | evt: gr.SelectData): |
| 926 | |
| 927 | self.sam_predictor.set_image(img) |
| 928 | self.saved_points.append([evt.index[0], evt.index[1]]) |
| 929 | self.saved_labels.append(1 if is_positive else 0) |
| 930 | input_point = np.array(self.saved_points) |
| 931 | input_label = np.array(self.saved_labels) |
| 932 | |
| 933 | # Predict the mask |
| 934 | with torch.cuda.amp.autocast(): |
| 935 | masks, scores, logits = self.sam_predictor.predict( |
| 936 | point_coords=input_point, |
| 937 | point_labels=input_label, |
| 938 | multimask_output=False, |
| 939 | ) |
| 940 | |
| 941 | img = self.show_mask(masks[0], img, random_color=False, transparency=0.3) |
| 942 | |
| 943 | img = self.show_points(input_point, input_label, img) |
| 944 | |
| 945 | return img |
| 946 | |
| 947 | def segment_image_with_coordinate(self, img, is_positive: bool, |
| 948 | coordinate: tuple): |
nothing calls this directly
no test coverage detected