Spaces:
Running
Running
Upload with huggingface_hub
Browse files- DESCRIPTION.md +1 -0
- README.md +1 -1
- app.py +0 -9
DESCRIPTION.md
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
Image segmentation using DETR. Takes in both an inputu image and the desired confidence, and returns a segmented image.
|
README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
|
2 |
---
|
3 |
title: image_segmentation
|
4 |
-
emoji:
|
5 |
colorFrom: indigo
|
6 |
colorTo: indigo
|
7 |
sdk: gradio
|
|
|
1 |
|
2 |
---
|
3 |
title: image_segmentation
|
4 |
+
emoji: 🔥
|
5 |
colorFrom: indigo
|
6 |
colorTo: indigo
|
7 |
sdk: gradio
|
app.py
CHANGED
@@ -1,20 +1,14 @@
|
|
1 |
-
# URL: https://huggingface.co/spaces/gradio/image_segmentation/
|
2 |
-
# DESCRIPTION: Image segmentation using DETR. Takes in both an inputu image and the desired confidence, and returns a segmented image.
|
3 |
-
# imports
|
4 |
import gradio as gr
|
5 |
import torch
|
6 |
import random
|
7 |
import numpy as np
|
8 |
from transformers import MaskFormerFeatureExtractor, MaskFormerForInstanceSegmentation
|
9 |
|
10 |
-
|
11 |
-
# load model
|
12 |
device = torch.device("cpu")
|
13 |
model = MaskFormerForInstanceSegmentation.from_pretrained("facebook/maskformer-swin-tiny-ade").to(device)
|
14 |
model.eval()
|
15 |
preprocessor = MaskFormerFeatureExtractor.from_pretrained("facebook/maskformer-swin-tiny-ade")
|
16 |
|
17 |
-
# define core and helper fns
|
18 |
def visualize_instance_seg_mask(mask):
|
19 |
image = np.zeros((mask.shape[0], mask.shape[1], 3))
|
20 |
labels = np.unique(mask)
|
@@ -37,8 +31,6 @@ def query_image(img):
|
|
37 |
results = visualize_instance_seg_mask(results)
|
38 |
return results
|
39 |
|
40 |
-
# define interface
|
41 |
-
|
42 |
demo = gr.Interface(
|
43 |
query_image,
|
44 |
inputs=[gr.Image()],
|
@@ -47,5 +39,4 @@ demo = gr.Interface(
|
|
47 |
examples=[["example_2.png"]]
|
48 |
)
|
49 |
|
50 |
-
# launch
|
51 |
demo.launch()
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
import random
|
4 |
import numpy as np
|
5 |
from transformers import MaskFormerFeatureExtractor, MaskFormerForInstanceSegmentation
|
6 |
|
|
|
|
|
7 |
device = torch.device("cpu")
|
8 |
model = MaskFormerForInstanceSegmentation.from_pretrained("facebook/maskformer-swin-tiny-ade").to(device)
|
9 |
model.eval()
|
10 |
preprocessor = MaskFormerFeatureExtractor.from_pretrained("facebook/maskformer-swin-tiny-ade")
|
11 |
|
|
|
12 |
def visualize_instance_seg_mask(mask):
|
13 |
image = np.zeros((mask.shape[0], mask.shape[1], 3))
|
14 |
labels = np.unique(mask)
|
|
|
31 |
results = visualize_instance_seg_mask(results)
|
32 |
return results
|
33 |
|
|
|
|
|
34 |
demo = gr.Interface(
|
35 |
query_image,
|
36 |
inputs=[gr.Image()],
|
|
|
39 |
examples=[["example_2.png"]]
|
40 |
)
|
41 |
|
|
|
42 |
demo.launch()
|