Spaces:
Runtime error
Runtime error
DDingcheol
commited on
Commit
ยท
5a104f4
1
Parent(s):
22ff5dc
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoModelForSemanticSegmentation, AutoTokenizer
|
2 |
+
from PIL import Image
|
3 |
+
import requests
|
4 |
+
from io import BytesIO
|
5 |
+
|
6 |
+
# Hugging Face ๋ชจ๋ธ ์ด๋ฆ
|
7 |
+
model_name = "nvidia/segformer-b0-finetuned-cityscapes-1024-1024"
|
8 |
+
|
9 |
+
# ๋ชจ๋ธ ๋ฐ ํ ํฌ๋์ด์ ๋ก๋
|
10 |
+
model = AutoModelForSemanticSegmentation.from_pretrained(model_name)
|
11 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
12 |
+
|
13 |
+
# ์ด๋ฏธ์ง ๋ค์ด๋ก๋ ๋ฐ ์ ์ฒ๋ฆฌ
|
14 |
+
image_url = "https://example.com/your_image.jpg" # ์ด๋ฏธ์ง URL์ ์ค์ ์ด๋ฏธ์ง URL๋ก ๋ฐ๊ฟ์ฃผ์ธ์.
|
15 |
+
image = Image.open(BytesIO(requests.get(image_url).content))
|
16 |
+
|
17 |
+
# ์ด๋ฏธ์ง๋ฅผ ๋ชจ๋ธ ์
๋ ฅ ํ์์ผ๋ก ๋ณํ
|
18 |
+
inputs = tokenizer(image, return_tensors="pt")
|
19 |
+
|
20 |
+
# ๋ชจ๋ธ ์คํ
|
21 |
+
outputs = model(**inputs)
|
22 |
+
predictions = outputs.logits
|
23 |
+
|
24 |
+
# ์ฌ๊ธฐ์ predictions๋ segmentation ๋งต์
๋๋ค.
|
25 |
+
# ์ด๋ฅผ ์ํ๋ ํ์์ผ๋ก ์ฒ๋ฆฌํ๊ณ ์๊ฐํํ ์ ์์ต๋๋ค.
|
26 |
+
# ์๋ฅผ ๋ค์ด, PIL Image๋ก ๋ณํํ์ฌ ์ ์ฅํ๊ฑฐ๋ ์ถ๋ ฅํ ์ ์์ต๋๋ค.
|