Spaces:
Sleeping
Sleeping
Commit
·
b5b2077
1
Parent(s):
c5e44c2
space app 🐦
Browse files- app.py +58 -0
- examples/merle-noir.jpg +0 -0
- examples/mesange-charbonniere.jpg +0 -0
- examples/tourterelle-turque.jpg +0 -0
- model/model_ep=1_acc=0.8909620610367893.pt +3 -0
app.py
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from gradio import inputs
|
2 |
+
import torch
|
3 |
+
import numpy as np
|
4 |
+
import torchvision as tv
|
5 |
+
import gradio as gr
|
6 |
+
|
7 |
+
model = tv.models.efficientnet_b0()
|
8 |
+
num_ftrs = model.classifier[1].in_features
|
9 |
+
model.classifier[1] = torch.nn.Linear(num_ftrs, 21)
|
10 |
+
model.load_state_dict(torch.load('model/model_ep=1_acc=0.8909620610367893.pt', map_location = torch.device('cpu')))
|
11 |
+
model.eval()
|
12 |
+
|
13 |
+
classes_to_idx = {'Accenteur mouchet': 0,
|
14 |
+
'Bouvreuil pivoine': 1,
|
15 |
+
'Chardonneret élégant': 2,
|
16 |
+
'Ecureuil roux': 3,
|
17 |
+
'Geai des chênes': 4,
|
18 |
+
'Grosbec casse-noyaux': 5,
|
19 |
+
'Merle noir': 6,
|
20 |
+
'Moineau domestique': 7,
|
21 |
+
'Moineau friquet': 8,
|
22 |
+
'Mésange Nonnette': 9,
|
23 |
+
'Mésange bleue': 10,
|
24 |
+
'Mésange charbonnière': 11,
|
25 |
+
'Mésange huppée': 12,
|
26 |
+
'Mésange noire': 13,
|
27 |
+
'Pic épeiche': 14,
|
28 |
+
'Pinson des arbres': 15,
|
29 |
+
'Pinson du Nord': 16,
|
30 |
+
'Rougegorge familier': 17,
|
31 |
+
'Sittelle torchepot': 18,
|
32 |
+
'Tourterelle turque': 19,
|
33 |
+
"Verdier d'Europe": 20}
|
34 |
+
|
35 |
+
classes = list(classes_to_idx.keys())
|
36 |
+
|
37 |
+
preprocess = tv.transforms.Compose([
|
38 |
+
tv.transforms.Resize((270, 359)),
|
39 |
+
tv.transforms.ToTensor()
|
40 |
+
#tv.transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
|
41 |
+
])
|
42 |
+
|
43 |
+
from PIL import Image
|
44 |
+
|
45 |
+
def classidy_bird(image):
|
46 |
+
|
47 |
+
inputs = preprocess(image).unsqueeze(0)
|
48 |
+
inputs = inputs.to(torch.device('cpu'))
|
49 |
+
|
50 |
+
pred = torch.nn.functional.softmax(model(inputs), dim = 1).detach().numpy()[0]
|
51 |
+
return {classes[i] : float(pred[i]) for i in range(21)}
|
52 |
+
|
53 |
+
image = gr.inputs.Image(type="pil", shape=(270, 359))
|
54 |
+
label = gr.outputs.Label(num_top_classes=3)
|
55 |
+
title = "Poids Plume Classifier"
|
56 |
+
examples = ['examples/mesange-charbonniere.jpg', 'examples/merle-noir.jpg', 'examples/tourterelle-turque.jpg']
|
57 |
+
|
58 |
+
gr.Interface(fn = classidy_bird, inputs=image, outputs=label, capture_session=True, examples=examples, title=title).launch()
|
examples/merle-noir.jpg
ADDED
![]() |
examples/mesange-charbonniere.jpg
ADDED
![]() |
examples/tourterelle-turque.jpg
ADDED
![]() |
model/model_ep=1_acc=0.8909620610367893.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0ae2ca74aef980ab47a865654129df1b57e84de5d7da9746862f4f590f82c920
|
3 |
+
size 16434993
|