Spaces:
Build error
Build error
Upload 4 files
Browse files- app.py +34 -0
- convnext_nano_4freeze_5epochs_on_jpg_26error.pkl +3 -0
- gamename_dict.pkl +3 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from fastai.vision.all import *
|
3 |
+
import timm
|
4 |
+
import random
|
5 |
+
import pickle
|
6 |
+
|
7 |
+
|
8 |
+
infile = open('gamename_dict.pkl','rb')
|
9 |
+
game_name_dict = pickle.load(infile)
|
10 |
+
infile.close()
|
11 |
+
|
12 |
+
learn=load_learner('convnext_nano_4freeze_5epochs_on_jpg_26error.pkl')
|
13 |
+
categories=learn.dls.vocab
|
14 |
+
categories=[game_name_dict[gn] for gn in categories]
|
15 |
+
|
16 |
+
def recognize_game(img):
|
17 |
+
img= PILImage.create(img)
|
18 |
+
pred,idx,probs=learn.predict(img)
|
19 |
+
return pred,str(100*float(dict(zip(categories, probs))[pred]))[:4]+"%"
|
20 |
+
|
21 |
+
def recognize_game_all(img):
|
22 |
+
img= PILImage.create(img)
|
23 |
+
pred,idx,probs=learn.predict(img)
|
24 |
+
img.save(pred+str(random.randrange(1,10000))+'.jpg')
|
25 |
+
return dict(zip(categories, map(float,probs)))
|
26 |
+
|
27 |
+
|
28 |
+
image = gr.inputs.Image(shape=(224,224))
|
29 |
+
label = gr.outputs.Label(num_top_classes=48)
|
30 |
+
title= 'Boardgame recognizer'
|
31 |
+
examples = ['bloodrage.jpg','nemesis.jpg','root.jpg','scythe.jpg' ]
|
32 |
+
|
33 |
+
iface = gr.Interface(fn=recognize_game_all, inputs=image, outputs=label,title=title, examples=examples)
|
34 |
+
iface.launch(inline=False)
|
convnext_nano_4freeze_5epochs_on_jpg_26error.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1bd67c691c1df93eac4323d900187b5b41f855ebf7f2f7808d7c46059e277f88
|
3 |
+
size 62802417
|
gamename_dict.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:173e69dde614d3e437fa470b6bc33d7e515af47a7514dd0e881bd2e1b415c44a
|
3 |
+
size 4150
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
fastai
|
2 |
+
scikit-image
|
3 |
+
timm
|