suvash commited on
Commit
86cfa24
1 Parent(s): fdf4fb9

Initial commit. Let's see if this works.

Browse files
.gitattributes CHANGED
@@ -25,3 +25,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
25
  *.zip filter=lfs diff=lfs merge=lfs -text
26
  *.zstandard filter=lfs diff=lfs merge=lfs -text
27
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
25
  *.zip filter=lfs diff=lfs merge=lfs -text
26
  *.zstandard filter=lfs diff=lfs merge=lfs -text
27
  *tfevents* filter=lfs diff=lfs merge=lfs -text
28
+ *.pkl filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio
2
+ from fastai.vision.all import *
3
+
4
+ MODELS_PATH = Path('./models')
5
+ EXAMPLES_PATH = Path('./examples')
6
+
7
+ # Required function used by fastai learner (at training setup)
8
+ def label_func(filepath):
9
+ return filepath.parent.name
10
+
11
+ learn = load_learner(MODELS_PATH/'food-101-resnet50.pkl')
12
+
13
+ labels = learn.dls.vocab
14
+
15
+ def predict(img):
16
+ img = PILImage.create(img)
17
+ pred,pred_idx,probs = learn.predict(img)
18
+ return {labels[i]: float(probs[i]) for i in range(len(labels))}
19
+
20
+ with open('gradio_article.md') as f:
21
+ article = f.read()
22
+
23
+ interface_options = {
24
+ "title": "Food-101 Classifier",
25
+ "description": "A food image classifier trained on the Food-101 (https://data.vision.ee.ethz.ch/cvl/datasets_extra/food-101/) dataset with fastai with a ResNet50 CNN model.",
26
+ "article": article,
27
+ "examples" : [f'{EXAMPLES_PATH}/{f.name}' for f in EXAMPLES_PATH.iterdir()],
28
+ "interpretation": "default",
29
+ "layout": "horizontal",
30
+ "allow_flagging": "never",
31
+ "enable_queue": True
32
+ }
33
+
34
+ demo = gradio.Interface(fn=predict,
35
+ inputs=gradio.inputs.Image(shape=(512, 512)),
36
+ outputs=gradio.outputs.Label(num_top_classes=5),
37
+ **interface_options)
38
+
39
+ demo.launch()
examples/edamame.jpeg ADDED
examples/falafel.jpeg ADDED
examples/huevos_rancheros.jpeg ADDED
examples/momo.jpeg ADDED
examples/pad_thai.jpeg ADDED
examples/paella.jpeg ADDED
examples/ravioli.jpeg ADDED
examples/sushi.jpeg ADDED
examples/takoyaki.jpeg ADDED
gradio_article.md ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ # H1
2
+
3
+ Some text here
4
+
5
+ ## H2
6
+
7
+ Some more text here
models/food-101-resnet50.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b05abca6f36341d2da0cce628d15b65f544ce6ee6a09d39b659a35919826ac81
3
+ size 104817109
requirements.txt ADDED
@@ -0,0 +1 @@
 
1
+ fastai==2.6.0