Spaces:
Running
Running
File size: 2,850 Bytes
f4ff2f8 32fdc42 f4ff2f8 0161340 f4ff2f8 192ea1a f4ff2f8 192ea1a f4ff2f8 192ea1a f4ff2f8 192ea1a f4ff2f8 192ea1a f4ff2f8 192ea1a f4ff2f8 192ea1a f4ff2f8 192ea1a f4ff2f8 192ea1a f4ff2f8 192ea1a f4ff2f8 192ea1a f4ff2f8 192ea1a f4ff2f8 192ea1a f4ff2f8 64fca96 0161340 f4ff2f8 e866e6d 192ea1a 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 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
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-v10.pkl"
model = load_learner(model_dir)
parrot_species = ['african grey parrot',
'australian king parrot',
'australian night parrot',
'bare eyed cockatoo',
'blue and yellow macaw',
'blue headed parrot',
'blue lorikeet',
'brown hooded parrot',
'budgerigar',
'burrowing parrot',
'caique parrot',
'catalina macaw',
'chestnut-fronted macaw',
'citron cockatoo',
'cockatiels',
'crimson rosella',
'cuban amazon',
'eclectus parrot',
'galah cockatoo',
'gang gang cockatoo',
'golden parakeet',
'great green macaw',
'great hanging parrot',
'greater vasa parrot',
'hahn_s macaws',
'hooded parrot',
'hyacinth macaw',
'kea',
'kākāpō',
'lovebirds',
'major mitchell_s cockatoo',
'monk parakeet',
'musk lorikeet',
'palm cockatoo',
'parrotlet',
'plum headed parakeet',
'puerto rican amazon',
'rainbow lorikeet',
'red breasted parakeet',
'red crowned amazon',
'red crowned parakeet',
'red fan parrot',
'red lory',
'red rumped parrot',
'red shouldered macaw',
'red tailed black cockatoos',
'rose ringed parakeet',
'saint vincent amazon',
'salmon crested cockatoo',
'scarlet macaw',
'senegal parrot',
'spixs macaw',
'sulpher crested cockatoo',
'sun conure',
'thick billed parrot',
'turquoise fronted amazon',
'umbrella cockatoo',
'vernal hanging parrot',
'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",
"test_images/unknown_15.jpg",
"test_images/unknown_16.jpg",
"test_images/unknown_17.jpg",
"test_images/unknown_18.jpg",
"test_images/unknown_19.jpg",
]
iface = gr.Interface(fn=recognize_image, inputs=image, outputs=label, examples=examples)
iface.launch(inline=False)
|