Spaces:
Sleeping
Sleeping
Added examples
Browse files- .gitattributes +2 -0
- app.py +23 -15
- demo/Pleiades_HD15_Miami_Marina.jpg +3 -0
- demo/Pleiades_Neo_Tucson_USA.jpg +0 -0
- demo/SPOT_Storage.jpg +3 -0
- demo/Satellite_Image_Marina_New_Zealand.jpg +0 -0
.gitattributes
CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
35 |
this_is_fine.png filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
33 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
35 |
this_is_fine.png filter=lfs diff=lfs merge=lfs -text
|
36 |
+
demo/Pleiades_HD15_Miami_Marina.jpg filter=lfs diff=lfs merge=lfs -text
|
37 |
+
demo/SPOT_Storage.jpg filter=lfs diff=lfs merge=lfs -text
|
app.py
CHANGED
@@ -3,6 +3,7 @@ from functools import partial
|
|
3 |
import cv2
|
4 |
import requests
|
5 |
import os
|
|
|
6 |
from io import BytesIO
|
7 |
from PIL import Image
|
8 |
import numpy as np
|
@@ -27,8 +28,8 @@ import groundingdino.datasets.transforms as T
|
|
27 |
from huggingface_hub import hf_hub_download
|
28 |
|
29 |
# check if GPU if available
|
30 |
-
|
31 |
-
device = 'cpu'
|
32 |
|
33 |
# Use this command for evaluate the GLIP-T model
|
34 |
config_file = "groundingdino/config/GroundingDINO_SwinT_OGC.py"
|
@@ -74,12 +75,22 @@ def run_grounding(input_image, grounding_caption, box_threshold, text_threshold)
|
|
74 |
image_pil: Image = image_transform_grounding_for_vis(init_image)
|
75 |
|
76 |
# run grounidng
|
|
|
77 |
boxes, logits, phrases = predict(model, image_tensor, grounding_caption, box_threshold, text_threshold, device=device)
|
|
|
78 |
annotated_frame = annotate(image_source=np.asarray(image_pil), boxes=boxes, logits=logits, phrases=phrases)
|
79 |
image_with_box = Image.fromarray(cv2.cvtColor(annotated_frame, cv2.COLOR_BGR2RGB))
|
80 |
|
|
|
81 |
|
82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
|
84 |
if __name__ == "__main__":
|
85 |
|
@@ -108,23 +119,20 @@ if __name__ == "__main__":
|
|
108 |
with gr.Accordion("Advanced options", open=False):
|
109 |
box_threshold = gr.Slider(label="Box Threshold", minimum=0.0, maximum=1.0, value=0.25, step=0.001)
|
110 |
text_threshold = gr.Slider(label="Text Threshold", minimum=0.0, maximum=1.0, value=0.25, step=0.001)
|
111 |
-
|
|
|
112 |
stopwatch = gr.Number(label="Execution time (sec.)", interactive=False, precision=3)
|
113 |
|
114 |
with gr.Column(scale=1):
|
115 |
-
gallery = gr.outputs.Image(
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
# grid=[1], height="auto", container=True, full_width=True, full_height=True)
|
121 |
-
|
122 |
-
run_button.click(fn=run_grounding, inputs=[
|
123 |
-
input_image, grounding_caption, box_threshold, text_threshold], outputs=[gallery])
|
124 |
gr.Examples(
|
125 |
-
|
126 |
inputs = [input_image, grounding_caption, box_threshold, text_threshold],
|
127 |
-
outputs = [gallery],
|
128 |
fn=run_grounding,
|
129 |
cache_examples=False,
|
130 |
label='Try this example input!'
|
|
|
3 |
import cv2
|
4 |
import requests
|
5 |
import os
|
6 |
+
import time
|
7 |
from io import BytesIO
|
8 |
from PIL import Image
|
9 |
import numpy as np
|
|
|
28 |
from huggingface_hub import hf_hub_download
|
29 |
|
30 |
# check if GPU if available
|
31 |
+
device = torch.device("cuda:0" if torch.cuda.is_available() else "mps" if torch.backends.mps.is_available() else "cpu")
|
32 |
+
#device = 'cpu'
|
33 |
|
34 |
# Use this command for evaluate the GLIP-T model
|
35 |
config_file = "groundingdino/config/GroundingDINO_SwinT_OGC.py"
|
|
|
75 |
image_pil: Image = image_transform_grounding_for_vis(init_image)
|
76 |
|
77 |
# run grounidng
|
78 |
+
start_time = time.time()
|
79 |
boxes, logits, phrases = predict(model, image_tensor, grounding_caption, box_threshold, text_threshold, device=device)
|
80 |
+
end_time = time.time()
|
81 |
annotated_frame = annotate(image_source=np.asarray(image_pil), boxes=boxes, logits=logits, phrases=phrases)
|
82 |
image_with_box = Image.fromarray(cv2.cvtColor(annotated_frame, cv2.COLOR_BGR2RGB))
|
83 |
|
84 |
+
return image_with_box, str(image_pil.size), len(boxes), end_time - start_time
|
85 |
|
86 |
+
# Define example images and their true labels for users to choose from
|
87 |
+
example_data = [
|
88 |
+
["./demo/airport01.jpg", "aircraft", 0.25, 0.25]
|
89 |
+
["./demo/Pleiades_Neo_Tucson_USA.jpg", 0.25, 0.25],
|
90 |
+
["./demo/SPOT_Storage.jpg", 0.25, 0.25],
|
91 |
+
["./demo/Satellite_Image_Marina_New_Zealand.jpg", 0.25, 0.25],
|
92 |
+
["./demo/Pleiades_HD15_Miami_Marina.jpg", 0.25, 0.25],
|
93 |
+
]
|
94 |
|
95 |
if __name__ == "__main__":
|
96 |
|
|
|
119 |
with gr.Accordion("Advanced options", open=False):
|
120 |
box_threshold = gr.Slider(label="Box Threshold", minimum=0.0, maximum=1.0, value=0.25, step=0.001)
|
121 |
text_threshold = gr.Slider(label="Text Threshold", minimum=0.0, maximum=1.0, value=0.25, step=0.001)
|
122 |
+
dimensions = gr.Textbox(label="Image size", interactive=False)
|
123 |
+
detections = gr.Number(label="Predicted objects", interactive=False)
|
124 |
stopwatch = gr.Number(label="Execution time (sec.)", interactive=False, precision=3)
|
125 |
|
126 |
with gr.Column(scale=1):
|
127 |
+
gallery = gr.outputs.Image(type="pil").style(full_width=True, full_height=True)
|
128 |
+
|
129 |
+
run_button.click(fn=run_grounding,
|
130 |
+
inputs=[input_image, grounding_caption, box_threshold, text_threshold],
|
131 |
+
outputs=[gallery, dimensions, detections, stopwatch])
|
|
|
|
|
|
|
|
|
132 |
gr.Examples(
|
133 |
+
examples=example_data,
|
134 |
inputs = [input_image, grounding_caption, box_threshold, text_threshold],
|
135 |
+
outputs = [gallery, dimensions, detections, stopwatch],
|
136 |
fn=run_grounding,
|
137 |
cache_examples=False,
|
138 |
label='Try this example input!'
|
demo/Pleiades_HD15_Miami_Marina.jpg
ADDED
![]() |
Git LFS Details
|
demo/Pleiades_Neo_Tucson_USA.jpg
ADDED
![]() |
demo/SPOT_Storage.jpg
ADDED
![]() |
Git LFS Details
|
demo/Satellite_Image_Marina_New_Zealand.jpg
ADDED
![]() |