File size: 1,681 Bytes
15f6601
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9e30515
15f6601
 
 
 
 
 
9e30515
 
 
 
 
15f6601
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
44
45
46
47
48
49
50
51
52
53
# AUTOGENERATED! DO NOT EDIT! File to edit: antelopeInference.ipynb.

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

# %% antelopeInference.ipynb 3
#Imports

import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

#hide
#[ -e /content ] 
#pip install -Uqq fastbook

# import fastbook
# fastbook.setup_book()

#hide
# from fastbook import *
# from fastai.vision.widgets import *

# pip install fastai


# %% antelopeInference.ipynb 4
from fastai.vision.all import *
import gradio as gr

# %% antelopeInference.ipynb 8
learn = load_learner('antelopeClassifier.pkl')

categories = ('Eland', 'Greater Kudu', 'Hartebeest', 'Oryx', 'Defassa Waterbuck', 'Sitatunga', 'Impala ', 'The lesser Kudu', 'Grant’s Gazelle','Reedbuck','Uganda Kob','Forest duiker','Harvery’s red duiker', 'Blue duiker', 'Peter’s duiker','Black fronted duiker','Grey duiker','Oribi','Klipspringer','Guenther’s')

# %% antelopeInference.ipynb 26
def classify_image(img):
  pred,idx,probs = learn.predict(img)
  return dict(zip(categories, map(float,probs)))


# %% antelopeInference.ipynb 31
#create gradio interface
image = gr.inputs.Image(shape=(128,128))
label = gr.outputs.Label()
examples = ['antelopeA.jpeg', 'antelopeB.jpeg', 'antelopeC.jpeg']

title = "East African Antelope classifier"
description = "A deep learning based image classifier that tells you what breed of antelope is in a picture"
interpretation = "default"

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