File size: 1,501 Bytes
9935a4c
 
 
4f32a60
 
9935a4c
 
 
1633182
9935a4c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1633182
9935a4c
 
 
 
 
 
 
 
 
1633182
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
41
42
43
# AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.

# %% auto 0
__all__ = ['title', 'description', 'learners', 'models', 'image', 'model', 'label', 'example_images', 'example_models', 'intf',
           'classify_image']

# %% app.ipynb 1
from fastai.vision.all import *
import gradio as gr
title = "FastAI - Big Cats Classifier"
description = "Classify big cats using all Resnet models available pre-trained in FastAI"

# %% app.ipynb 2
learners = {
    "resnet-18" : 'models/resnet18-model.pkl',
    "resnet-34" : 'models/resnet34-model.pkl',
    "resnet-50" : 'models/resnet50-model.pkl',
    "resnet-101": 'models/resnet101-model.pkl',
    "resnet-152": 'models/resnet152-model.pkl'
}
models = list(learners.keys())

    

# %% app.ipynb 3
def classify_image(img, model_file="resnet-101"):
    learn = load_learner(learners[model_file])
    pred,idx,probs = learn.predict(img)
    print(pred, idx, probs)
    return dict(zip(learn.dls.vocab, map(float, probs)))


# %% app.ipynb 5
image = gr.inputs.Image(shape=(192.192))
model = gr.inputs.Dropdown(choices=models)
label = gr.outputs.Label()
example_images = [ 'cheetah.jpg', 'jaguar.jpg', 'tiger.jpg', 'cougar.jpg', 'lion.jpg', 'african leopard.jpg', 'clouded leopard.jpg', 'snow leopard.jpg' ]
example_models = [] #list(learners.values())
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=example_images, title=title, description=description )
if __name__ == "__main__":
    intf.launch(debug=True, inline=False)