Thiago Hersan
commited on
Commit
•
39a4454
1
Parent(s):
13b6d4d
adds examples
Browse files- app.py +12 -4
- examples/map-000.jpg +0 -0
- examples/map-007.jpg +0 -0
- examples/map-010.jpg +0 -0
- examples/map-018.jpg +0 -0
- examples/map-111.jpg +0 -0
- examples/map-114.jpg +0 -0
- requirements.txt +1 -0
app.py
CHANGED
@@ -1,10 +1,15 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
3 |
from os import environ
|
|
|
|
|
4 |
from torchvision import transforms as T
|
5 |
from transformers import MaskFormerForInstanceSegmentation, MaskFormerImageProcessor
|
6 |
|
7 |
|
|
|
|
|
8 |
ade_mean=[0.485, 0.456, 0.406]
|
9 |
ade_std=[0.229, 0.224, 0.225]
|
10 |
|
@@ -57,9 +62,10 @@ def visualize_instance_seg_mask(img_in, mask, id2label):
|
|
57 |
return image_res, dataframe
|
58 |
|
59 |
|
60 |
-
def query_image(
|
|
|
61 |
img_size = (img.shape[0], img.shape[1])
|
62 |
-
inputs = preprocessor(images=test_transform(
|
63 |
|
64 |
outputs = model(**inputs)
|
65 |
|
@@ -70,14 +76,16 @@ def query_image(img):
|
|
70 |
|
71 |
demo = gr.Interface(
|
72 |
query_image,
|
73 |
-
inputs=[gr.Image(label="Input Image")],
|
74 |
outputs=[
|
75 |
gr.Image(label="Vegetation"),
|
76 |
gr.DataFrame(label="Info", headers=["Object Label", "Pixel Percent", "Square Length"])
|
77 |
],
|
78 |
title="Maskformer Satellite+Trees",
|
79 |
allow_flagging="never",
|
80 |
-
analytics_enabled=None
|
|
|
|
|
81 |
)
|
82 |
|
83 |
demo.launch(show_api=False)
|
|
|
1 |
+
import glob
|
2 |
import gradio as gr
|
3 |
import numpy as np
|
4 |
from os import environ
|
5 |
+
from pathlib import Path
|
6 |
+
from PIL import Image
|
7 |
from torchvision import transforms as T
|
8 |
from transformers import MaskFormerForInstanceSegmentation, MaskFormerImageProcessor
|
9 |
|
10 |
|
11 |
+
example_images = sorted(glob.glob('examples/map*.jpg'))
|
12 |
+
|
13 |
ade_mean=[0.485, 0.456, 0.406]
|
14 |
ade_std=[0.229, 0.224, 0.225]
|
15 |
|
|
|
62 |
return image_res, dataframe
|
63 |
|
64 |
|
65 |
+
def query_image(image_path):
|
66 |
+
img = np.array(Image.open(Path(image_path)))
|
67 |
img_size = (img.shape[0], img.shape[1])
|
68 |
+
inputs = preprocessor(images=test_transform(img), return_tensors="pt")
|
69 |
|
70 |
outputs = model(**inputs)
|
71 |
|
|
|
76 |
|
77 |
demo = gr.Interface(
|
78 |
query_image,
|
79 |
+
inputs=[gr.Image(type="filepath", label="Input Image")],
|
80 |
outputs=[
|
81 |
gr.Image(label="Vegetation"),
|
82 |
gr.DataFrame(label="Info", headers=["Object Label", "Pixel Percent", "Square Length"])
|
83 |
],
|
84 |
title="Maskformer Satellite+Trees",
|
85 |
allow_flagging="never",
|
86 |
+
analytics_enabled=None,
|
87 |
+
examples=example_images,
|
88 |
+
cache_examples=True
|
89 |
)
|
90 |
|
91 |
demo.launch(show_api=False)
|
examples/map-000.jpg
ADDED
examples/map-007.jpg
ADDED
examples/map-010.jpg
ADDED
examples/map-018.jpg
ADDED
examples/map-111.jpg
ADDED
examples/map-114.jpg
ADDED
requirements.txt
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
scipy
|
2 |
torch
|
3 |
torchvision
|
|
|
1 |
+
Pillow
|
2 |
scipy
|
3 |
torch
|
4 |
torchvision
|