Spaces:
Sleeping
Sleeping
add example into the demo
Browse files
app.py
CHANGED
@@ -6,7 +6,21 @@ from torch import nn
|
|
6 |
from torchvision import transforms
|
7 |
from transformers import SegformerForSemanticSegmentation
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
MODEL_PATH="./best_model_mixto/"
|
11 |
|
12 |
device = torch.device("cpu")
|
@@ -18,7 +32,7 @@ preprocessor = transforms.Compose([
|
|
18 |
model = SegformerForSemanticSegmentation.from_pretrained(MODEL_PATH)
|
19 |
model.eval()
|
20 |
|
21 |
-
|
22 |
def upscale_logits(logit_outputs, size):
|
23 |
"""Escala los logits a (4W)x(4H) para recobrar dimensiones originales del input"""
|
24 |
return nn.functional.interpolate(
|
@@ -53,13 +67,15 @@ def query_image(img):
|
|
53 |
result = predict_label[0,:,:].detach().cpu().numpy()
|
54 |
return visualize_instance_seg_mask(result)
|
55 |
|
56 |
-
|
57 |
demo = gr.Interface(
|
58 |
query_image,
|
59 |
inputs=[gr.Image(type="pil").style(full_width=True, height=256, width=256)],
|
60 |
outputs=[gr.Image().style(full_width=True, height=256, width=256)],
|
61 |
title="Skyguard: segmentador de glaciares de roca 🛰️ +️ 🛡️ ️",
|
62 |
-
description="Modelo de segmentación de imágenes para detectar glaciares de roca.<br> Se entrenó un modelo [nvidia/SegFormer](https://huggingface.co/nvidia/mit-b0) con _fine-tuning_ en el [rock-glacier-dataset](https://huggingface.co/datasets/alkzar90/rock-glacier-dataset)"
|
|
|
|
|
63 |
)
|
64 |
|
65 |
demo.launch()
|
|
|
6 |
from torchvision import transforms
|
7 |
from transformers import SegformerForSemanticSegmentation
|
8 |
|
9 |
+
# examples
|
10 |
+
os.system("wget -O 073.png https://huggingface.co/spaces/alkzar90/rock-glacier-segmentation/resolve/main/example_images/buenos_resultados/073.png")
|
11 |
+
os.system("wget -O 356.png https://huggingface.co/spaces/alkzar90/rock-glacier-segmentation/resolve/main/example_images/buenos_resultados/356.png")
|
12 |
+
os.system("wget -O 599.png https://huggingface.co/spaces/alkzar90/rock-glacier-segmentation/resolve/main/example_images/buenos_resultados/599.png")
|
13 |
+
os.system("wget -O 630.png https://huggingface.co/spaces/alkzar90/rock-glacier-segmentation/resolve/main/example_images/buenos_resultados/630.png")
|
14 |
+
os.system("wget -O 673.png https://huggingface.co/spaces/alkzar90/rock-glacier-segmentation/resolve/main/example_images/buenos_resultados/673.png")
|
15 |
|
16 |
+
|
17 |
+
os.system("wget -O 019.png https://huggingface.co/spaces/alkzar90/rock-glacier-segmentation/resolve/main/example_images/malos_resultados/019.png")
|
18 |
+
os.system("wget -o 261.png https://huggingface.co/spaces/alkzar90/rock-glacier-segmentation/resolve/main/example_images/malos_resultados/261.png")
|
19 |
+
os.system("wget -o 524.png https://huggingface.co/spaces/alkzar90/rock-glacier-segmentation/resolve/main/example_images/malos_resultados/524.png")
|
20 |
+
os.system("wget -o 716.png https://huggingface.co/spaces/alkzar90/rock-glacier-segmentation/resolve/main/example_images/malos_resultados/716.png")
|
21 |
+
os.system("wget -o 898.png https://huggingface.co/spaces/alkzar90/rock-glacier-segmentation/resolve/main/example_images/malos_resultados/898.png")
|
22 |
+
|
23 |
+
# model-setting
|
24 |
MODEL_PATH="./best_model_mixto/"
|
25 |
|
26 |
device = torch.device("cpu")
|
|
|
32 |
model = SegformerForSemanticSegmentation.from_pretrained(MODEL_PATH)
|
33 |
model.eval()
|
34 |
|
35 |
+
# inference-functions
|
36 |
def upscale_logits(logit_outputs, size):
|
37 |
"""Escala los logits a (4W)x(4H) para recobrar dimensiones originales del input"""
|
38 |
return nn.functional.interpolate(
|
|
|
67 |
result = predict_label[0,:,:].detach().cpu().numpy()
|
68 |
return visualize_instance_seg_mask(result)
|
69 |
|
70 |
+
# demo
|
71 |
demo = gr.Interface(
|
72 |
query_image,
|
73 |
inputs=[gr.Image(type="pil").style(full_width=True, height=256, width=256)],
|
74 |
outputs=[gr.Image().style(full_width=True, height=256, width=256)],
|
75 |
title="Skyguard: segmentador de glaciares de roca 🛰️ +️ 🛡️ ️",
|
76 |
+
description="Modelo de segmentación de imágenes para detectar glaciares de roca.<br> Se entrenó un modelo [nvidia/SegFormer](https://huggingface.co/nvidia/mit-b0) con _fine-tuning_ en el [rock-glacier-dataset](https://huggingface.co/datasets/alkzar90/rock-glacier-dataset)",
|
77 |
+
examples=[["073.png", "356.png", "599.png", "630.png", "673.png", "019.png", "261.png", "524.png", "716.png", "898.png"]],
|
78 |
+
cache_examples=False
|
79 |
)
|
80 |
|
81 |
demo.launch()
|