yoon6173 commited on
Commit
8a40f69
Β·
1 Parent(s): 083d7ab
Files changed (1) hide show
  1. app.py +13 -24
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=[image.size[::-1]])[0]
25
-
26
- color_map = {
27
- 0: (0, 0, 0), # 클래슀 0: 검은색
28
- 1: (255, 255, 255), # 클래슀 1: 흰색
29
- 2: (255, 0, 0),
30
- 3: (0, 255, 0),
31
- 4: (0, 0, 255),
32
- 5: (255, 255, 0),
33
- 6: (255, 0, 255),
34
- 7: (0, 255, 255),
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)