File size: 1,489 Bytes
f99b819
aaa114f
 
f99b819
 
 
 
aaa114f
f99b819
 
caf175c
f99b819
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70dbb0e
aaa114f
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
import timm
from fastai.vision.all import *

import gradio as gr
from sys import platform
if platform == "win32":
    import pathlib

    pathlib.PosixPath = pathlib.WindowsPath
    path = Path()
    
learn = load_learner('fullset_conv_small_10ep_90p.pkl')
dic = open('dictionnary.txt').read().splitlines()
translation = {}
for line in dic:
    x,y = line.split(',')
    translation[x] = y

labels = learn.dls.vocab
def predict(img):
    img = PILImage.create(img)
    pred,pred_idx,probs = learn.predict(img)
    return {translation[labels[i]]: float(probs[i]) for i in range(len(labels))}

examples = ['rougequeue.PNG', 'bergeronnette.png', 'pic.png', 'chardonneret.png', 'cheveche.png']
title = "Birds from France classifier"
description = "This is a classifier for over 600 bird species observable in France.\nIt was trained to recognize a single bird, pictures with more birds yield unpredictable results. Try to frame the picture close for best results.\n\nIt uses a fine-tuned ConvNext small model and had 90\% accuracy on the validation set.\nIt is biased towards adult male birds due to the higher prevalence of male specimens in pictures and is most likely less accurate on females and juveniles.\n\nIt should get the family right but may fail to differentiate between close species."

intf = gr.Interface(fn=predict, inputs=gr.Image(shape=(512, 512)), title = title, description = description, outputs=gr.Label(num_top_classes=3), examples = examples)
intf.launch(inline=False)