Spaces:
Configuration error
Configuration error
| from transformers import AutoModelForSemanticSegmentation, AutoTokenizer | |
| from PIL import Image | |
| import requests | |
| from io import BytesIO | |
| # Hugging Face ๋ชจ๋ธ ์ด๋ฆ | |
| model_name = "nvidia/segformer-b0-finetuned-cityscapes-1024-1024" | |
| # ๋ชจ๋ธ ๋ฐ ํ ํฌ๋์ด์ ๋ก๋ | |
| model = AutoModelForSemanticSegmentation.from_pretrained(model_name) | |
| tokenizer = AutoTokenizer.from_pretrained(model_name) | |
| # ์ด๋ฏธ์ง ๋ค์ด๋ก๋ ๋ฐ ์ ์ฒ๋ฆฌ | |
| image_url = "https://example.com/your_image.jpg" # ์ด๋ฏธ์ง URL์ ์ค์ ์ด๋ฏธ์ง URL๋ก ๋ฐ๊ฟ์ฃผ์ธ์. | |
| image = Image.open(BytesIO(requests.get(image_url).content)) | |
| # ์ด๋ฏธ์ง๋ฅผ ๋ชจ๋ธ ์ ๋ ฅ ํ์์ผ๋ก ๋ณํ | |
| inputs = tokenizer(image, return_tensors="pt") | |
| # ๋ชจ๋ธ ์คํ | |
| outputs = model(**inputs) | |
| predictions = outputs.logits | |
| # ์ฌ๊ธฐ์ predictions๋ segmentation ๋งต์ ๋๋ค. | |
| # ์ด๋ฅผ ์ํ๋ ํ์์ผ๋ก ์ฒ๋ฆฌํ๊ณ ์๊ฐํํ ์ ์์ต๋๋ค. | |
| # ์๋ฅผ ๋ค์ด, PIL Image๋ก ๋ณํํ์ฌ ์ ์ฅํ๊ฑฐ๋ ์ถ๋ ฅํ ์ ์์ต๋๋ค. | |