segment3 / app.py
akman12914
application revise
434d48f
raw
history blame
820 Bytes
import gradio as gr
from PIL import Image
import tensorflow as tf
import numpy as np
import requests
from transformers import SegformerImageProcessor, SegformerForSemanticSegmentation, SegformerFeatureExtractor
feature_extractor = SegformerFeatureExtractor.from_pretrained(
"nvidia/segformer-b0-finetuned-ade-512-512"
)
processor = SegformerImageProcessor.from_pretrained(
"nvidia/segformer-b0-finetuned-ade-512-512"
)
model = SegformerForSemanticSegmentation.from_pretrained("nvidia/segformer-b0-finetuned-ade-512-512")
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 # shape (batch_size, num_labels, height/4, width/4)