File size: 1,270 Bytes
e8746a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
!pip install gradio

from fastai.vision.all import *
import gradio as gr

#im1 = PILImage.create('/kaggle/input/flowersdata/balsamroot/02d06c11-5738-47f0-bfaf-af79eb1d4405.jpg')
#im2 = PILImage.create('/kaggle/input/flowersdata/brittlebrush/ed0dc07f-49b3-48f0-9663-aefee1d3096b.jpg')

learn = load_learner('/kaggle/input/save-your-neural-network-as-a-pkl-file/export.pkl')

pred_class,pred_idx,probabilities = learn.predict(im1)
pred_class, pred_idx, probabilities

pred_class,pred_idx,probabilities = learn.predict(im2)
pred_class, pred_idx, probabilities

categories = ('balsamroot', 'bladderpod', 'blazing star', 'bristlecone pine flowers', 'brittlebrush')
def classify_image(img):
    pred, idx, probs = learn.predict(img)
    return dict(zip(categories, map(float, probs)))


classify_image(im1), classify_image(im2)

image=gr.Image(height = 192, width = 192)
label = gr.Label()
#examples = ['/kaggle/input/example-images/Ronan_Grizzly_Bear_1.jpg','/kaggle/input/example-images/blackbear.jpg',
            '/kaggle/input/example-images/blackbear2.jpg','/kaggle/input/example-images/brownbear.jpg',
           '/kaggle/input/example-images/polar.jpg']
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
intf.launch(inline=False)