Spaces:
Runtime error
Runtime error
JinHyeong99
commited on
Commit
ยท
3af3698
1
Parent(s):
cd60cf8
app.py
CHANGED
|
@@ -8,6 +8,28 @@ import numpy as np
|
|
| 8 |
feature_extractor = SegformerFeatureExtractor.from_pretrained("nvidia/segformer-b0-finetuned-cityscapes-512-1024")
|
| 9 |
model = SegformerForSemanticSegmentation.from_pretrained("nvidia/segformer-b0-finetuned-cityscapes-512-1024")
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
def segment_image(image):
|
| 12 |
# ์ด๋ฏธ์ง๋ฅผ ์ฒ๋ฆฌํ๊ณ ๋ชจ๋ธ์ ์ ๋ฌํ๊ธฐ
|
| 13 |
inputs = feature_extractor(images=image, return_tensors="pt")
|
|
@@ -18,9 +40,11 @@ def segment_image(image):
|
|
| 18 |
result = logits.argmax(dim=1)[0]
|
| 19 |
result = result.cpu().detach().numpy()
|
| 20 |
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
# ๊ฒฐ๊ณผ ๋ฐฐ์ด ๋ฐํ
|
| 24 |
return result_image
|
| 25 |
|
| 26 |
# Gradio ์ธํฐํ์ด์ค ์ ์
|
|
|
|
| 8 |
feature_extractor = SegformerFeatureExtractor.from_pretrained("nvidia/segformer-b0-finetuned-cityscapes-512-1024")
|
| 9 |
model = SegformerForSemanticSegmentation.from_pretrained("nvidia/segformer-b0-finetuned-cityscapes-512-1024")
|
| 10 |
|
| 11 |
+
colors = np.array([
|
| 12 |
+
[255, 0, 0], # ๋นจ๊ฐ
|
| 13 |
+
[255, 228, 0], # ๋
ธ๋
|
| 14 |
+
[171, 242, 0], # ์ฐ๋
|
| 15 |
+
[0, 216, 255], # ํ๋
|
| 16 |
+
[0, 0, 255], # ํ๋
|
| 17 |
+
[255, 0, 221], # ํํฌ
|
| 18 |
+
[116, 116, 116], # ํ์
|
| 19 |
+
[95, 0, 255], # ๋ณด๋ผ
|
| 20 |
+
[255, 94, 0], # ์ฃผํฉ
|
| 21 |
+
[71, 200, 62], # ์ด๋ก
|
| 22 |
+
[153, 0, 76], # ๋ง์ ํ
|
| 23 |
+
[67, 116, 217], # ์ ๋งคํํ๋+ํ๋
|
| 24 |
+
[153, 112, 0], # ๊ฒจ์
|
| 25 |
+
[87, 129, 0], # ๋
น์
|
| 26 |
+
[255, 169, 169], # ๋ถํ๋ถํ
|
| 27 |
+
[35, 30, 183], # ์ด๋์ด ํ๋
|
| 28 |
+
[225, 186, 133], # ์ด์
|
| 29 |
+
[206, 251, 201], # ์ฐํ์ด๋ก
|
| 30 |
+
[165, 102, 255] # ์ ๋งคํ๋ณด๋ผ
|
| 31 |
+
], dtype=np.uint8)
|
| 32 |
+
|
| 33 |
def segment_image(image):
|
| 34 |
# ์ด๋ฏธ์ง๋ฅผ ์ฒ๋ฆฌํ๊ณ ๋ชจ๋ธ์ ์ ๋ฌํ๊ธฐ
|
| 35 |
inputs = feature_extractor(images=image, return_tensors="pt")
|
|
|
|
| 40 |
result = logits.argmax(dim=1)[0]
|
| 41 |
result = result.cpu().detach().numpy()
|
| 42 |
|
| 43 |
+
# ์์ ํ๋ ํธ ์ ์ฉ
|
| 44 |
+
result_color = colors[result]
|
| 45 |
+
|
| 46 |
+
result_image = Image.fromarray(result_color.astype(np.uint8))
|
| 47 |
|
|
|
|
| 48 |
return result_image
|
| 49 |
|
| 50 |
# Gradio ์ธํฐํ์ด์ค ์ ์
|