|
from transformers import SegformerFeatureExtractor, SegformerForSemanticSegmentation |
|
from PIL import Image |
|
import requests |
|
import os |
|
os.environ['TF_ENABLE_ONEDNN_OPTS'] = '0' |
|
|
|
feature_extractor = SegformerFeatureExtractor.from_pretrained("nvidia/segformer-b0-finetuned-cityscapes-1024-1024") |
|
model = SegformerForSemanticSegmentation.from_pretrained("nvidia/segformer-b0-finetuned-cityscapes-1024-1024") |
|
|
|
url = "http://images.cocodataset.org/val2017/000000039769.jpg" |
|
image = Image.open(requests.get(url, stream=True).raw) |
|
|
|
inputs = feature_extractor(images=image, return_tensors="pt") |
|
outputs = model(**inputs) |
|
logits = outputs.logits |