Spaces:
Runtime error
Runtime error
File size: 1,530 Bytes
bd13bdd 7623705 bd13bdd a02e9cb 73a7350 bd13bdd afe1a22 bd13bdd a02e9cb bd13bdd da518b0 bd13bdd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import matplotlib.pyplot as plt
import gradio as gr
from transformers import AutoFeatureExtractor, SegformerForSemanticSegmentation
import torch
import numpy as np
extractor = AutoFeatureExtractor.from_pretrained("nvidia/segformer-b0-finetuned-ade-512-512")
model = SegformerForSemanticSegmentation.from_pretrained("hshetty/my-segmentation-model")
def classify(im):
inputs = extractor(images=im, return_tensors="pt")
outputs = model(**inputs)
logits = outputs.logits
classes = logits[0].detach().cpu().numpy().argmax(axis=0)
colors = np.array([[128,0,0], [128,128,0], [0, 0, 128], [128,0,128], [0, 0, 0]])
return colors[classes]
interface = gr.Interface(fn=classify,
inputs=gr.inputs.Image(type="pil"),
outputs=gr.inputs.Image(type="pil"),
title="Self Driving Car App- Semantic Segmentation",
description="This is a self driving car app using Semantic Semendation as part of week 2 end to end vision application project on CoRise.",
examples=["https://datasets-server.huggingface.co/assets/segments/sidewalk-semantic/--/segments--sidewalk-semantic-2/train/3/pixel_values/image.jpg",
"https://datasets-server.huggingface.co/assets/segments/sidewalk-semantic/--/segments--sidewalk-semantic-2/train/5/pixel_values/image.jpg",
"https://datasets-server.huggingface.co/assets/segments/sidewalk-semantic/--/segments--sidewalk-semantic-2/train/20/pixel_values/image.jpg"])
# FILL HERE
interface.launch()
|