suvash commited on
Commit
8decc79
1 Parent(s): 1cad85c

added the application files

Browse files
README.md CHANGED
@@ -1,10 +1,10 @@
1
  ---
2
- title: Usk Coffee Convnext Nano
3
- emoji: 👀
4
  colorFrom: purple
5
  colorTo: green
6
  sdk: gradio
7
- sdk_version: 3.17.0
8
  app_file: app.py
9
  pinned: false
10
  ---
 
1
  ---
2
+ title: USK-Coffee bean classifer (USK-Coffee|Convnext-nano|fast.ai)
3
+ emoji: ☕️
4
  colorFrom: purple
5
  colorTo: green
6
  sdk: gradio
7
+ sdk_version: 3.1.4
8
  app_file: app.py
9
  pinned: false
10
  ---
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio
2
+ from fastai.vision.all import *
3
+
4
+ MODELS_PATH = Path('./models')
5
+ EXAMPLES_PATH = Path('./examples')
6
+
7
+ # Required function expected by fastai learn object
8
+ # it wasn't exported as a part of the pickle
9
+ # as it was defined externally to the learner object
10
+ # during the training time dataloaders setup
11
+ def label_func(filepath):
12
+ return filepath.parent.name
13
+
14
+ LEARN = load_learner(MODELS_PATH/'usk-coffee-convnext_nano_935625.pkl')
15
+ LABELS = LEARN.dls.vocab
16
+
17
+ def gradio_predict(img):
18
+ img = PILImage.create(img)
19
+ _pred, _pred_idx, probs = LEARN.predict(img)
20
+ labels_probs = {LABELS[i]: float(probs[i]) for i, _ in enumerate(LABELS)}
21
+ return labels_probs
22
+
23
+ with open('gradio_article.md') as f:
24
+ article = f.read()
25
+
26
+ interface_options = {
27
+ "title": "USK-Coffee bean classifer (USK-Coffee|Convnext-nano|fast.ai)",
28
+ "description": "A coffee bean image classifier(ConvNext nano) fine tuned on the USK-Coffee (https://comvis.unsyiah.ac.id/usk-coffee/) dataset using fastai & timm.",
29
+ "article": article,
30
+ "examples" : [f'{EXAMPLES_PATH}/{f.name}' for f in EXAMPLES_PATH.iterdir()],
31
+ "interpretation": "default",
32
+ "layout": "horizontal",
33
+ "allow_flagging": "never",
34
+ "enable_queue": True
35
+ }
36
+
37
+ demo = gradio.Interface(fn=gradio_predict,
38
+ inputs=gradio.inputs.Image(shape=(512, 512)),
39
+ outputs=gradio.outputs.Label(num_top_classes=5),
40
+ **interface_options)
41
+
42
+ launch_options = {
43
+ "enable_queue": True,
44
+ "share": False,
45
+ }
46
+
47
+ demo.launch(**launch_options)
48
+
examples/defect_test_1684.jpg ADDED
examples/defect_test_1736.jpg ADDED
examples/defect_test_1867.jpg ADDED
examples/defect_test_1871.jpg ADDED
examples/defect_test_1949.jpg ADDED
examples/defect_test_1988.jpg ADDED
examples/longberry_test_1871.jpg ADDED
examples/longberry_test_1927.jpg ADDED
examples/longberry_test_1930.jpg ADDED
examples/peaberry_test_1735.jpg ADDED
examples/peaberry_test_1736.jpg ADDED
examples/peaberry_test_1840.jpg ADDED
examples/premium_test_1756.jpg ADDED
examples/premium_test_1804.jpg ADDED
examples/premium_test_1974.jpg ADDED
gradio_article.md ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## Dataset
2
+
3
+ The USK-Coffee dataset, made available at https://comvis.unsyiah.ac.id/usk-coffee/ is multi class image dataset derived from a coffee bean collection that includes 4 classes: peaberry, longberry, defect, and premium.
4
+
5
+ ## Training
6
+
7
+ Fast.ai was used to train this classifier with a Timm ConvNext nano vision learner, without heavy customization. The training was performed on the provided `train` split, and validation on the `val` split.
8
+
9
+ The final fine tuning of the training loop resulted in the following losses.
10
+
11
+ | epoch | train_loss | valid_loss | accuracy | time |
12
+ |-------|------------|------------|----------|-------|
13
+ | 0 | 0.238523 | 0.383621 | 0.869375 | 00:25 |
14
+ | 1 | 0.257938 | 0.293417 | 0.907500 | 00:25 |
15
+ | 2 | 0.205048 | 0.412420 | 0.847500 | 00:25 |
16
+ | 3 | 0.170284 | 0.308219 | 0.901875 | 00:25 |
17
+ | 4 | 0.154471 | 0.308811 | 0.894375 | 00:26 |
18
+ | 5 | 0.107862 | 0.480474 | 0.874375 | 00:26 |
19
+ | 6 | 0.075452 | 0.506489 | 0.843125 | 00:26 |
20
+ | 7 | 0.060802 | 0.317052 | 0.906875 | 00:26 |
21
+ | 8 | 0.049216 | 0.242317 | 0.932500 | 00:26 |
22
+ | 9 | 0.040890 | 0.233353 | 0.935625 | 00:26 |
23
+
24
+
25
+ ## Examples
26
+
27
+ The example images provided in the demo are from the `test` split in the dataset, which was never made available to the model in the training process.
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ fastai==2.7.9
2
+ gradio==3.1.4