yoon6173 commited on
Commit
433bf2b
ยท
1 Parent(s): 706f9eb
Files changed (1) hide show
  1. app.py +11 -1
app.py CHANGED
@@ -4,6 +4,8 @@ import torch
4
  from PIL import Image
5
  from transformers import AutoImageProcessor, Mask2FormerForUniversalSegmentation
6
  import numpy as np
 
 
7
 
8
 
9
  def greet(url):
@@ -27,7 +29,15 @@ def greet(url):
27
  predicted_semantic_map = processor.post_process_semantic_segmentation(outputs, target_sizes=[image.size[::-1]])[0]
28
  # we refer to the demo notebooks for visualization (see "Resources" section in the Mask2Former docs)
29
 
30
- return predicted_semantic_map
 
 
 
 
 
 
 
 
31
 
32
  url = "http://www.apparelnews.co.kr/upfiles/manage/202302/5d5f694177b26fc86e5db623bf7ae4b7.jpg"
33
  #greet(url)
 
4
  from PIL import Image
5
  from transformers import AutoImageProcessor, Mask2FormerForUniversalSegmentation
6
  import numpy as np
7
+ import torchvision.transforms as T
8
+ from PIL import Image
9
 
10
 
11
  def greet(url):
 
29
  predicted_semantic_map = processor.post_process_semantic_segmentation(outputs, target_sizes=[image.size[::-1]])[0]
30
  # we refer to the demo notebooks for visualization (see "Resources" section in the Mask2Former docs)
31
 
32
+ # predicted_semantic_map์„ 8๋น„ํŠธ ๋ถ€ํ˜ธ ์—†๋Š” ์ •์ˆ˜๋กœ ๋ณ€ํ™˜
33
+ # ์ด๋ฏธ์ง€๋ฅผ ๋ถ€ํ˜ธ ์—†๋Š” 8๋น„ํŠธ ์ •์ˆ˜๋กœ ๋ณ€ํ™˜ (0์—์„œ 255 ์‚ฌ์ด์˜ ๊ฐ’์œผ๋กœ ์Šค์ผ€์ผ๋ง)
34
+ predicted_semantic_map_scaled = (predicted_semantic_map - predicted_semantic_map.min()) / (predicted_semantic_map.max() - predicted_semantic_map.min()) * 255
35
+ predicted_semantic_map_uint8 = predicted_semantic_map_scaled.to(torch.uint8)
36
+
37
+ tensor_to_pil = T.ToPILImage()
38
+ image = tensor_to_pil(predicted_semantic_map_uint8)
39
+
40
+ return image
41
 
42
  url = "http://www.apparelnews.co.kr/upfiles/manage/202302/5d5f694177b26fc86e5db623bf7ae4b7.jpg"
43
  #greet(url)