dd
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ import requests
|
|
3 |
import torch
|
4 |
from PIL import Image
|
5 |
from transformers import AutoImageProcessor, Mask2FormerForUniversalSegmentation
|
|
|
6 |
|
7 |
|
8 |
def greet(url):
|
@@ -21,29 +22,17 @@ def greet(url):
|
|
21 |
masks_queries_logits = outputs.masks_queries_logits
|
22 |
|
23 |
# you can pass them to processor for postprocessing
|
24 |
-
predicted_semantic_map = processor.post_process_semantic_segmentation(outputs, target_sizes=[
|
25 |
-
|
26 |
-
|
27 |
-
0
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
# λ€λ₯Έ ν΄λμ€μ λν μμ μ§μ
|
36 |
-
}
|
37 |
-
#semantic_image = Image.new('RGB', predicted_semantic_map.shape[1:][::-1])[0]
|
38 |
-
semantic_image = Image.new('RGB', (predicted_semantic_map.shape[1], predicted_semantic_map.shape[0]))
|
39 |
-
pixels = semantic_image.load()
|
40 |
-
for y in range(predicted_semantic_map.shape[0]):
|
41 |
-
for x in range(predicted_semantic_map.shape[1]):
|
42 |
-
class_id = predicted_semantic_map[y, x].item()
|
43 |
-
color = color_map.get(class_id, (0, 0, 0))
|
44 |
-
pixels[x, y] = color
|
45 |
-
|
46 |
-
return pixels
|
47 |
|
48 |
|
49 |
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
|
@@ -55,4 +44,4 @@ iface = gr.Interface(
|
|
55 |
outputs="image"
|
56 |
)
|
57 |
|
58 |
-
iface.launch()
|
|
|
3 |
import torch
|
4 |
from PIL import Image
|
5 |
from transformers import AutoImageProcessor, Mask2FormerForUniversalSegmentation
|
6 |
+
import numpy as np
|
7 |
|
8 |
|
9 |
def greet(url):
|
|
|
22 |
masks_queries_logits = outputs.masks_queries_logits
|
23 |
|
24 |
# you can pass them to processor for postprocessing
|
25 |
+
predicted_semantic_map = processor.post_process_semantic_segmentation(outputs, target_sizes=[url.size])[0]
|
26 |
+
|
27 |
+
sepia_filter = np.array([
|
28 |
+
[0.393, 0.769, 0.189],
|
29 |
+
[0.349, 0.686, 0.168],
|
30 |
+
[0.272, 0.534, 0.131]
|
31 |
+
])
|
32 |
+
sepia_img = predicted_semantic_map.dot(sepia_filter.T)
|
33 |
+
sepia_img /= sepia_img.max()
|
34 |
+
|
35 |
+
return sepia_img
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
|
38 |
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
|
|
|
44 |
outputs="image"
|
45 |
)
|
46 |
|
47 |
+
iface.launch(debug = True)
|