File size: 592 Bytes
4ae8579
 
 
 
 
 
 
 
 
 
9ab897d
4ae8579
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio
import numpy

from pathlib import Path

from fastai.vision.all import load_learner, PILImage


MODEL_PATH = Path('.') / 'models'
TEST_IMAGES_PATH = Path('.') / 'test'
LEARNER = load_learner(MODEL_PATH / 'car-segmentation_v1.pkl')


def segment_image(image):
    image = PILImage.create(image)
    prediction, _, _ = LEARNER.predict(image)
    return numpy.array(prediction)

demo = gradio.Interface(
    segment_image,
    inputs=gradio.Image(type='pil'),
    outputs=gradio.Image(type='numpy'),
    examples=[str(image) for image in TEST_IMAGES_PATH.iterdir()]
)
demo.launch()