File size: 1,566 Bytes
bd13bdd
 
 
 
7623705
bd13bdd
52b7465
 
a12990d
bd13bdd
afe1a22
bd13bdd
 
 
52b7465
bd13bdd
 
 
 
 
52b7465
 
bd13bdd
a8d2fde
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
31
import matplotlib.pyplot as plt
import gradio as gr
from transformers import AutoFeatureExtractor, SegformerForSemanticSegmentation
import torch
import numpy as np

extractor = AutoFeatureExtractor.from_pretrained("hshetty/segmentation-model-finetuned-on-semantic-sidewalk-3e-4-e5")
model = SegformerForSemanticSegmentation.from_pretrained("hshetty/segmentation-model-finetuned-on-semantic-sidewalk-3e-4-e5")

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="image",
             outputs="image",
             title="Self Driving Car App- Semantic Segmentation",
             description="This is a self driving car app using Semantic Segmentation as part of week 2 end to end vision application project on CoRise by Abubakar Abid!",
             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()