DDingcheol commited on
Commit
5a104f4
ยท
1 Parent(s): 22ff5dc

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
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๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ์ €์žฅํ•˜๊ฑฐ๋‚˜ ์ถœ๋ ฅํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.