Tobias Cornille
commited on
Commit
•
bb94750
1
Parent(s):
a884db1
Use image URL
Browse files
a2d2.png
DELETED
Git LFS Details
|
app.py
CHANGED
@@ -20,6 +20,7 @@ import argparse
|
|
20 |
import random
|
21 |
import warnings
|
22 |
import json
|
|
|
23 |
|
24 |
import gradio as gr
|
25 |
import numpy as np
|
@@ -62,6 +63,10 @@ def load_model_hf(model_config_path, repo_id, filename, device):
|
|
62 |
return model
|
63 |
|
64 |
|
|
|
|
|
|
|
|
|
65 |
def load_image_for_dino(image):
|
66 |
transform = T.Compose(
|
67 |
[
|
@@ -289,7 +294,7 @@ def inds_to_segments_format(
|
|
289 |
|
290 |
|
291 |
def generate_panoptic_mask(
|
292 |
-
|
293 |
thing_category_names_string,
|
294 |
stuff_category_names_string,
|
295 |
dino_box_threshold=0.3,
|
@@ -335,6 +340,7 @@ def generate_panoptic_mask(
|
|
335 |
category_name: i for i, category_name in enumerate(category_names)
|
336 |
}
|
337 |
|
|
|
338 |
image = image.convert("RGB")
|
339 |
image_array = np.asarray(image)
|
340 |
|
@@ -473,7 +479,7 @@ if __name__ == "__main__":
|
|
473 |
)
|
474 |
with gr.Row():
|
475 |
with gr.Column():
|
476 |
-
|
477 |
thing_category_names_string = gr.Textbox(
|
478 |
label="Thing categories (i.e. categories with instances), comma-separated",
|
479 |
placeholder="E.g. car, bus, person",
|
@@ -539,33 +545,10 @@ Because of the large dynamic range, these png images may appear black in an imag
|
|
539 |
label="Annotations JSON",
|
540 |
)
|
541 |
|
542 |
-
examples = gr.Examples(
|
543 |
-
examples=[
|
544 |
-
[
|
545 |
-
"a2d2.png",
|
546 |
-
"car, bus, person",
|
547 |
-
"road, sky, buildings, sidewalk",
|
548 |
-
],
|
549 |
-
[
|
550 |
-
"bxl.png",
|
551 |
-
"car, tram, motorcycle, person",
|
552 |
-
"road, buildings, sky",
|
553 |
-
],
|
554 |
-
],
|
555 |
-
fn=generate_panoptic_mask,
|
556 |
-
inputs=[
|
557 |
-
input_image,
|
558 |
-
thing_category_names_string,
|
559 |
-
stuff_category_names_string,
|
560 |
-
],
|
561 |
-
outputs=[segmentation_bitmap, annotations_json],
|
562 |
-
cache_examples=True,
|
563 |
-
)
|
564 |
-
|
565 |
run_button.click(
|
566 |
fn=generate_panoptic_mask,
|
567 |
inputs=[
|
568 |
-
|
569 |
thing_category_names_string,
|
570 |
stuff_category_names_string,
|
571 |
box_threshold,
|
|
|
20 |
import random
|
21 |
import warnings
|
22 |
import json
|
23 |
+
import requests
|
24 |
|
25 |
import gradio as gr
|
26 |
import numpy as np
|
|
|
63 |
return model
|
64 |
|
65 |
|
66 |
+
def download_image(url):
|
67 |
+
return Image.open(requests.get(url, stream=True).raw)
|
68 |
+
|
69 |
+
|
70 |
def load_image_for_dino(image):
|
71 |
transform = T.Compose(
|
72 |
[
|
|
|
294 |
|
295 |
|
296 |
def generate_panoptic_mask(
|
297 |
+
image_url,
|
298 |
thing_category_names_string,
|
299 |
stuff_category_names_string,
|
300 |
dino_box_threshold=0.3,
|
|
|
340 |
category_name: i for i, category_name in enumerate(category_names)
|
341 |
}
|
342 |
|
343 |
+
image = download_image(image_url)
|
344 |
image = image.convert("RGB")
|
345 |
image_array = np.asarray(image)
|
346 |
|
|
|
479 |
)
|
480 |
with gr.Row():
|
481 |
with gr.Column():
|
482 |
+
input_image_url = gr.Textbox(label="Image URL")
|
483 |
thing_category_names_string = gr.Textbox(
|
484 |
label="Thing categories (i.e. categories with instances), comma-separated",
|
485 |
placeholder="E.g. car, bus, person",
|
|
|
545 |
label="Annotations JSON",
|
546 |
)
|
547 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
548 |
run_button.click(
|
549 |
fn=generate_panoptic_mask,
|
550 |
inputs=[
|
551 |
+
input_image_url,
|
552 |
thing_category_names_string,
|
553 |
stuff_category_names_string,
|
554 |
box_threshold,
|
bxl.png
DELETED
Git LFS Details
|