Oiseaux / app.py
darkgiggsxx's picture
Update app.py
caf175c
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)