Spaces:
Runtime error
Runtime error
Updated from colab
Browse files- app.py +28 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoFeatureExtractor, AutoModelForImageClassification
|
| 3 |
+
import torch
|
| 4 |
+
import matplotlib.pyplot as plt
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
feature_extractor = AutoFeatureExtractor.from_pretrained("brendenc/my-segmentation-model")
|
| 8 |
+
model = AutoModelForImageClassification.from_pretrained("brendenc/my-segmentation-model")
|
| 9 |
+
|
| 10 |
+
labels = dataset['train'].features['labels'].names
|
| 11 |
+
|
| 12 |
+
def classify(im):
|
| 13 |
+
inputs = extractor(images=im, return_tensors="pt").to("cuda")
|
| 14 |
+
outputs = model(**inputs)
|
| 15 |
+
logits = outputs.logits
|
| 16 |
+
classes = logits[0].detach().cpu().numpy().argmax(axis=0)
|
| 17 |
+
colors = np.array([[128,0,0], [128,128,0], [0, 0, 128], [128,0,128], [0, 0, 0]])
|
| 18 |
+
return colors[classes]
|
| 19 |
+
|
| 20 |
+
example_imgs = [f"example_{i}.jpg" for i in range(3)]
|
| 21 |
+
interface = gr.Interface(classify,
|
| 22 |
+
inputs="image",
|
| 23 |
+
outputs="image",
|
| 24 |
+
examples = example_imgs,
|
| 25 |
+
title = "Street Image Segmentation",
|
| 26 |
+
description = """Below is a simple app for image segmentation. This model was trained using""")
|
| 27 |
+
|
| 28 |
+
interface.launch(debug=True)
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch
|
| 2 |
+
transformers
|
| 3 |
+
matplotlib
|