John Ho
commited on
Commit
·
33aa4bb
1
Parent(s):
f8e7037
fixed bug in image inferece
Browse files
app.py
CHANGED
@@ -87,19 +87,23 @@ def process_image(
|
|
87 |
logger.debug(f"bboxes type: {type(bboxes)}, value: {bboxes}")
|
88 |
has_bboxes = type(bboxes) != type(None) and bboxes != ""
|
89 |
has_points = type(points) != type(None) and points != ""
|
|
|
90 |
assert has_bboxes or has_points, f"either bboxes or points must be provided."
|
91 |
if has_points:
|
92 |
-
assert
|
93 |
-
point_labels
|
94 |
-
), f"{len(points)} points provided but there are {len(point_labels)} labels."
|
95 |
|
96 |
bboxes = json.loads(bboxes) if isinstance(bboxes, str) and has_bboxes else bboxes
|
97 |
points = json.loads(points) if isinstance(points, str) and has_points else points
|
98 |
point_labels = (
|
99 |
json.loads(point_labels)
|
100 |
-
if isinstance(point_labels, str) and
|
101 |
else point_labels
|
102 |
)
|
|
|
|
|
|
|
|
|
|
|
103 |
model = load_im_model(variant=variant)
|
104 |
return run_sam_im_inference(
|
105 |
model,
|
@@ -148,17 +152,17 @@ with gr.Blocks() as demo:
|
|
148 |
choices=["tiny", "small", "base_plus", "large"],
|
149 |
),
|
150 |
gr.Textbox(
|
151 |
-
label=
|
152 |
value=None,
|
153 |
lines=5,
|
154 |
placeholder='JSON list of dicts: [{"x0":..., "y0":..., "x1":..., "y1":...}, ...]',
|
155 |
),
|
156 |
gr.Textbox(
|
157 |
-
label=
|
158 |
-
|
159 |
-
|
160 |
-
label="Points Label (JSON list of integar)",
|
161 |
),
|
|
|
162 |
],
|
163 |
outputs=gr.JSON(label="Output JSON"),
|
164 |
title="SAM2 for Images",
|
|
|
87 |
logger.debug(f"bboxes type: {type(bboxes)}, value: {bboxes}")
|
88 |
has_bboxes = type(bboxes) != type(None) and bboxes != ""
|
89 |
has_points = type(points) != type(None) and points != ""
|
90 |
+
has_point_labels = type(point_labels) != type(None) and point_labels != ""
|
91 |
assert has_bboxes or has_points, f"either bboxes or points must be provided."
|
92 |
if has_points:
|
93 |
+
assert has_point_labels, f"point_labels is required if points are provided."
|
|
|
|
|
94 |
|
95 |
bboxes = json.loads(bboxes) if isinstance(bboxes, str) and has_bboxes else bboxes
|
96 |
points = json.loads(points) if isinstance(points, str) and has_points else points
|
97 |
point_labels = (
|
98 |
json.loads(point_labels)
|
99 |
+
if isinstance(point_labels, str) and has_point_labels
|
100 |
else point_labels
|
101 |
)
|
102 |
+
if has_points:
|
103 |
+
assert len(points) == len(
|
104 |
+
point_labels
|
105 |
+
), f"{len(points)} points provided but there are {len(point_labels)} labels."
|
106 |
+
|
107 |
model = load_im_model(variant=variant)
|
108 |
return run_sam_im_inference(
|
109 |
model,
|
|
|
152 |
choices=["tiny", "small", "base_plus", "large"],
|
153 |
),
|
154 |
gr.Textbox(
|
155 |
+
label="Bounding Boxes",
|
156 |
value=None,
|
157 |
lines=5,
|
158 |
placeholder='JSON list of dicts: [{"x0":..., "y0":..., "x1":..., "y1":...}, ...]',
|
159 |
),
|
160 |
gr.Textbox(
|
161 |
+
label="Points",
|
162 |
+
lines=3,
|
163 |
+
placeholder='JSON list of dicts: [{"x":..., "y":...}, ...]',
|
|
|
164 |
),
|
165 |
+
gr.Textbox(label="Points' Labels", placeholder="JSON List of Integars"),
|
166 |
],
|
167 |
outputs=gr.JSON(label="Output JSON"),
|
168 |
title="SAM2 for Images",
|