File size: 1,230 Bytes
390106f |
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 |
# AUTOGENERATED! DO NOT EDIT! File to edit: ../fastai_lesson_2_bearsInference_colab.ipynb.
# %% auto 0
__all__ = ['learn', 'image', 'label', 'examples', 'intf', 'classify_image']
# %% ../fastai_lesson_2_bearsInference_colab.ipynb 1
#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
# %% ../fastai_lesson_2_bearsInference_colab.ipynb 3
from fastai.vision.all import *
import gradio as gr
# %% ../fastai_lesson_2_bearsInference_colab.ipynb 12
learn = load_learner('/bearClassifier.pkl')
# %% ../fastai_lesson_2_bearsInference_colab.ipynb 15
def classify_image(img):
pred,idx,probs = learn.predict(img)
return dict(zip(categories, map(float,probs)))
# %% ../fastai_lesson_2_bearsInference_colab.ipynb 18
#create gradio interface
image = gr.inputs.Image(shape=(128,128))
label = gr.outputs.Label()
examples = ['grizzlyBearA.jpg', 'blackBearA.jpg', 'teddyBearA.jpg']
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples )
intf.launch(inline=False)
|