Spaces:
Runtime error
Runtime error
Hitesh Karunakara Shetty
commited on
Commit
·
bd13bdd
1
Parent(s):
827aa77
Initial files
Browse files- app.py +25 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import matplotlib.pyplot as plt
|
2 |
+
import gradio as gr
|
3 |
+
from transformers import AutoFeatureExtractor, SegformerForSemanticSegmentation
|
4 |
+
import torch
|
5 |
+
|
6 |
+
def classify(im):
|
7 |
+
inputs = extractor(images=im, return_tensors="pt").to("cuda")
|
8 |
+
outputs = model(**inputs)
|
9 |
+
logits = outputs.logits
|
10 |
+
classes = logits[0].detach().cpu().numpy().argmax(axis=0)
|
11 |
+
colors = np.array([[128,0,0], [128,128,0], [0, 0, 128], [128,0,128], [0, 0, 0]])
|
12 |
+
return colors[classes]
|
13 |
+
|
14 |
+
|
15 |
+
|
16 |
+
interface = gr.Interface(fn=classify,
|
17 |
+
inputs=gr.inputs.Image(type="pil"),
|
18 |
+
outputs=gr.Label(num_top_classes=3),
|
19 |
+
title="Self Driving Car App- Semantic Segmentation",
|
20 |
+
description="This is a self driving car app using Semantic Semendation as part of week 2 end to end vision application project on CoRise.",
|
21 |
+
examples=["https://datasets-server.huggingface.co/assets/segments/sidewalk-semantic/--/segments--sidewalk-semantic-2/train/3/pixel_values/image.jpg",
|
22 |
+
"https://datasets-server.huggingface.co/assets/segments/sidewalk-semantic/--/segments--sidewalk-semantic-2/train/5/pixel_values/image.jpg",
|
23 |
+
"https://datasets-server.huggingface.co/assets/segments/sidewalk-semantic/--/segments--sidewalk-semantic-2/train/20/pixel_values/image.jpg"])# FILL HERE
|
24 |
+
|
25 |
+
interface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
matplotlib
|
2 |
+
gradio
|
3 |
+
torch
|
4 |
+
transformers
|