File size: 956 Bytes
ab6be4c
4bc9f0d
04ff44d
 
e4928ff
 
 
04ff44d
ab6be4c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e4928ff
 
 
 
 
ab6be4c
 
 
 
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
32
33
34
35
36
37
38
39
40
from fastai.vision.all import *
from fastai.vision.all import load_learner
import gradio as gr

import pathlib
temp = pathlib.PosixPath
pathlib.PosixPath = pathlib.WindowsPath

#!export
pollutant_labels = (
    "antennas",
    "billboard",
    "broken roads",
    "construction sites",
    "electric pole",
    "garbage can",
    "graffiti",
    "smog",
    "street litter"
)

model = load_learner('models/vispol-1-recognizer-v0.pkl')

def recognize_image(image):
  pred, idx, probs = model.predict(image)
  return dict(zip(pollutant_labels, map(float, probs)))

#!export
image = gr.inputs.Image(shape=(256,256))
label = gr.outputs.Label()
examples = [
    'test_images/unknown_00.jpg',
    'test_images/unknown_01.jpg',
    'test_images/unknown_02.jpg',
    'test_images/unknown_03.jpg',
    'test_images/unknown_04.jpg'
    ]

iface = gr.Interface(fn=recognize_image, inputs=image, outputs=label, examples=examples)
iface.launch(inline=False, share=True)