Spaces:
Sleeping
Sleeping
added files
Browse files- README.md +3 -3
- app.py +55 -0
- models/model.pkl +3 -0
- models/model_1.pth +3 -0
- requirements.txt +3 -0
- sample_images/day.jpg +0 -0
- sample_images/market.jpg +0 -0
- sample_images/street.jpg +0 -0
README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
---
|
2 |
title: Traffic Segmentation
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.42.0
|
8 |
app_file: app.py
|
|
|
1 |
---
|
2 |
title: Traffic Segmentation
|
3 |
+
emoji: 🛣️🧠
|
4 |
+
colorFrom: blue
|
5 |
+
colorTo: red
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.42.0
|
8 |
app_file: app.py
|
app.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from fastai.vision.all import *
|
3 |
+
from PIL import Image, ImageDraw, ImageFont
|
4 |
+
import matplotlib.pyplot as plt
|
5 |
+
import numpy as np
|
6 |
+
import matplotlib.colors as mcolors
|
7 |
+
|
8 |
+
# import os
|
9 |
+
# Load a pre-trained image classification model
|
10 |
+
import pathlib
|
11 |
+
plt = platform.system()
|
12 |
+
if plt == 'Windows': pathlib.PosixPath = pathlib.WindowsPath
|
13 |
+
if plt == 'Linux': pathlib.WindowsPath = pathlib.PosixPath
|
14 |
+
|
15 |
+
root = os.path.dirname(__file__)
|
16 |
+
|
17 |
+
|
18 |
+
model = load_learner("./models/model.pkl")
|
19 |
+
|
20 |
+
def process(imagep):
|
21 |
+
# Predict and create the image as before
|
22 |
+
pred = model.predict(imagep)
|
23 |
+
a = pred[0]
|
24 |
+
i = np.stack([(a**17) % 255, (a**11) % 255, (a**9) % 255], axis=2)
|
25 |
+
img = Image.fromarray(i.astype('uint8'), mode='RGB')
|
26 |
+
|
27 |
+
imagep = Image.open(imagep)
|
28 |
+
# imagep = Image.fromarray(imagep)
|
29 |
+
|
30 |
+
imagep = imagep.convert("RGBA")
|
31 |
+
img = img.convert("RGBA")
|
32 |
+
img = img.resize(imagep.size)
|
33 |
+
alpha = Image.new('L', img.size, int(0.6 * 255))
|
34 |
+
img.putalpha(alpha)
|
35 |
+
combined = Image.alpha_composite(imagep, img)
|
36 |
+
|
37 |
+
return combined.convert("RGB")
|
38 |
+
|
39 |
+
|
40 |
+
|
41 |
+
# Sample images for user to choose from
|
42 |
+
sample_images = ["./sample_images/street.jpg", "./sample_images/market.jpg","./sample_images/day.jpg"]
|
43 |
+
|
44 |
+
iface = gr.Interface(
|
45 |
+
fn=process,
|
46 |
+
inputs=gr.Image(label="Select an image", type="filepath"),
|
47 |
+
outputs='image',
|
48 |
+
live=False,
|
49 |
+
title="Traffic image - semantic segmentation",
|
50 |
+
description="Upload a road traffic image or select one of the examples below",
|
51 |
+
examples=sample_images
|
52 |
+
)
|
53 |
+
|
54 |
+
|
55 |
+
iface.launch()
|
models/model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:2901da8f72dfda0fbad5975cf28278ef44df1501d9c7c7b4488181028cfaba7f
|
3 |
+
size 182564054
|
models/model_1.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f786ea24b7df31f4948a26f5617e124b678868fee63c5c7f9b4ae22a61075da5
|
3 |
+
size 662857152
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
fastai==2.7.14
|
3 |
+
spacy==3.7.4
|
sample_images/day.jpg
ADDED
sample_images/market.jpg
ADDED
sample_images/street.jpg
ADDED