File size: 2,434 Bytes
f4ff2f8
 
 
32fdc42
f4ff2f8
0161340
f4ff2f8
 
 
 
 
 
 
 
 
e866e6d
f4ff2f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64fca96
0161340
f4ff2f8
e866e6d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f4ff2f8
0161340
f4ff2f8
14ef371
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108

from fastai.vision.all import *
from fastai.vision.all import load_learner
import fastai
import os
import gradio as gr
import pathlib


# from google.colab import drive
# drive.mount('/content/drive/')

temp = pathlib.WindowsPath
pathlib.WindowsPath = pathlib.PosixPath

model_dir = "models/parrot-recognizer-v3.pkl"

model = load_learner(model_dir)

parrot_species = ['african grey parrot',
 'australian king parrot',
 'blue lorikeet',
 'blue-and-yellow macaw',
 'blue-headed parrot',
 'budgerigar',
 'burrowing parrot',
 'caique parrot',
 'catalina macaw',
 'chestnut-fronted macaw',
 'cockatiels',
 'crimson rosella',
 'cuban amazon',
 'eclectus parrot',
 'galah',
 'golden parakeet',
 'great green macaw',
 'great hanging parrot',
 'greater vasa parrot',
 'hahn_s macaws',
 'hooded parrot',
 'hyacinth macaw',
 'kea',
 'kākāpō',
 'lovebirds',
 'monk parakeet',
 'orange-winged amazon',
 'palm cockatoo',
 'parrotlet',
 'plum-headed parakeet',
 'puerto rican amazon',
 'rainbow lorikeet',
 'red-breasted parakeet',
 'red-crowned amazon',
 'red-crowned parakeet',
 'red-fan parrot',
 'red-shouldered macaw',
 'red-tailed black cockatoos',
 'rose-ringed parakeet',
 'saint vincent amazon',
 'scarlet macaw',
 'senegal parrot',
 'spixs macaw',
 'sun conure',
 'thick-billed parrot',
 'turquoise-fronted amazon',
 'vernal hanging parrot',
 'white cockatoo',
 'yellow-collared macaws',
 'yellow-headed amazon']

def recognize_image(image):
  pred, idx, probs = model.predict(image)
  return dict(zip(parrot_species, map(float, probs)))


# im =  "/content/drive/MyDrive/Learnings/fai/test_images/unknown_12.jpg"
# img = PILImage.create(im)
# img.thumbnail((192,192))
# img

# recognize_image(img)



image = gr.inputs.Image(shape=(192,192))
label = gr.outputs.Label(num_top_classes=5)

examples = [
    "test_images/unknown_00.jpg",
    "test_images/unknown_01.jpg",
    "test_images/unknown_02.jpg",
    "test_images/unknown_03.jpg",
    "test_images/unknown_04.jpg",
    "test_images/unknown_05.jpg",
    "test_images/unknown_06.jpg",
    "test_images/unknown_07.jpg",
    "test_images/unknown_08.jpg",
    "test_images/unknown_09.jpg",
    "test_images/unknown_10.jpg",
    "test_images/unknown_11.jpg",
    "test_images/unknown_12.jpg",
    "test_images/unknown_13.jpg",
    "test_images/unknown_14.jpg",
    ]

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