File size: 964 Bytes
cae357b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# AUTOGENERATED! DO NOT EDIT! File to edit: ../00_core.ipynb.

# %% auto 0
__all__ = ['learn_inf', 'categories', 'image', 'label', 'examples', 'intf', 'classify_image']

# %% ../00_core.ipynb 3
from fastai.vision.all import *

# %% ../00_core.ipynb 17
learn_inf = load_learner('export.pkl')

# %% ../00_core.ipynb 21
import gradio as gr
categories = ['aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 
              'bus', 'car', 'cat', 'chair', 'cow', 'diningtable', 'dog', 
              'horse', 'motorbike', 'person', 'pottedplant', 'sheep', 
              'sofa', 'train', 'tvmonitor']
def classify_image(img):
    red, idx, probs = learn_inf.predict(img)
    return dict(zip(categories, map(float, probs)))

image = gr.inputs.Image(shape=(192,192))
label = gr.outputs.Label()
examples = ['sheep.PNG', 'chair_diningtable.PNG', 'car_person.PNG']

intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
intf.launch(inline=False)