Spaces:
Running
Running
jhj0517
commited on
Commit
·
63be95c
1
Parent(s):
13ba185
Enable box and points input
Browse files- modules/sam_inference.py +10 -9
modules/sam_inference.py
CHANGED
@@ -144,20 +144,21 @@ class SamInference:
|
|
144 |
if len(prompt) == 0:
|
145 |
return [image], []
|
146 |
|
147 |
-
|
148 |
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
|
|
154 |
|
155 |
predicted_masks, scores, logits = self.predict_image(
|
156 |
image=image,
|
157 |
model_type=model_type,
|
158 |
-
box=
|
159 |
-
point_coords=
|
160 |
-
point_labels=point_labels if
|
161 |
multimask_output=hparams["multimask_output"]
|
162 |
)
|
163 |
generated_masks = self.format_to_auto_result(predicted_masks)
|
|
|
144 |
if len(prompt) == 0:
|
145 |
return [image], []
|
146 |
|
147 |
+
point_labels, point_coords, box = [], [], []
|
148 |
|
149 |
+
for x1, y1, left_click_indicator, x2, y2, point_indicator in prompt:
|
150 |
+
if point_indicator == 4.0:
|
151 |
+
point_labels.append(left_click_indicator)
|
152 |
+
point_coords.append([x1, y1])
|
153 |
+
else:
|
154 |
+
box.append([x1, y1, x2, y2])
|
155 |
|
156 |
predicted_masks, scores, logits = self.predict_image(
|
157 |
image=image,
|
158 |
model_type=model_type,
|
159 |
+
box=np.array(box) if box else None,
|
160 |
+
point_coords=np.array(point_coords) if point_coords else None,
|
161 |
+
point_labels=np.array(point_labels) if point_labels else None,
|
162 |
multimask_output=hparams["multimask_output"]
|
163 |
)
|
164 |
generated_masks = self.format_to_auto_result(predicted_masks)
|