rakeenarya commited on
Commit
6f599ce
·
verified ·
1 Parent(s): ae348d3

Upload 4 files

Browse files
Files changed (4) hide show
  1. README +68 -0
  2. best_accuracy.pth +3 -0
  3. craft_mlt_25k.pth +3 -0
  4. opt.txt +40 -0
README ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - en
5
+ library_name: pytorch
6
+ pipeline_tag: image-to-text
7
+ tags:
8
+ - ocr
9
+ - scene-text-recognition
10
+ - craft
11
+ - crnn
12
+ - food-labels
13
+ ---
14
+
15
+ # Ingredient Reader: OCR weights for food ingredient labels
16
+
17
+ These are the weights behind [Ingredient Reader](https://ingredient-reader.streamlit.app), which reads the ingredient list on a food label from a photo. They come from the undergraduate thesis *Pengembangan Sistem OCR Berbasis CRAFT dan CRNN untuk Pengenalan Teks Daftar Bahan pada Label Makanan* by Rakeen Aria Alireza. The code is at [github.com/rakeenaria/food-ingredient-ocr-craft-crnn](https://github.com/rakeenaria/food-ingredient-ocr-craft-crnn).
18
+
19
+ ## Files
20
+
21
+ | File | What it is | SHA-256 |
22
+ |---|---|---|
23
+ | `best_accuracy.pth` | Word recognizer: CRNN (TPS-ResNet-BiLSTM-Attn) fine-tuned on food-label word images (run `FT_801010_off`) | `405389e61a024a1d807b6438d3add77e1a50735da42cbbedafc72a34200710a6` |
24
+ | `opt.txt` | The recognizer's training settings: case-sensitive characters, grayscale 32 × 100 input, no PAD, maximum length 60 | `63540fcee6c9a2e01bcb88276f3aaf7ff5bee48b5dacffe7cc7402eba3d7c330` |
25
+ | `craft_mlt_25k.pth` | Text detector: CRAFT, the original pretrained weights from Clova AI, unchanged | `4a5efbfb48b4081100544e75e1e2b57f8de3d84f213004b14b85fd4b3748db17` |
26
+
27
+ ## Results
28
+
29
+ These are the thesis results.
30
+
31
+ - **Test split, word images:** 94.693% word accuracy, CER 0.015, WER 0.053. The split holds 10% of 6,081 curated word images (80:10:10).
32
+ - **The same split before fine-tuning:** 90.381%, using the pretrained `TPS-ResNet-BiLSTM-Attn-case-sensitive`.
33
+ - **Five real product photos, end to end (detection and recognition):** 92.248% word accuracy.
34
+
35
+ ## Usage
36
+
37
+ Clone the GitHub repository and run this from its root:
38
+
39
+ ```python
40
+ import cv2
41
+ from huggingface_hub import hf_hub_download
42
+
43
+ from src.ocr_engine import OCREngine
44
+
45
+ repo = "rakeenaria/ingredient-reader"
46
+ recognizer = hf_hub_download(repo, "best_accuracy.pth")
47
+ hf_hub_download(repo, "opt.txt") # settings, read next to the checkpoint
48
+ detector = hf_hub_download(repo, "craft_mlt_25k.pth")
49
+
50
+ engine = OCREngine(recognizer, detector)
51
+ result = engine.process(cv2.imread("label.jpg"))
52
+ print(result.text)
53
+ ```
54
+
55
+ ## Training data
56
+
57
+ The recognizer was fine-tuned on word crops from the Kaggle dataset *Ingredients Image from Food Label*. The crops were curated into 6,081 word images.
58
+
59
+ ## Limitations
60
+
61
+ - Printed English ingredient lists only. Handwriting and other languages are not supported.
62
+ - Small, blurry, glossy or curved text lowers accuracy.
63
+ - OCR can be wrong. Always check the physical label, especially if you have an allergy.
64
+
65
+ ## Credits and licenses
66
+
67
+ - **Recognizer:** the architecture, the training code and the pretrained starting point come from [deep-text-recognition-benchmark](https://github.com/clovaai/deep-text-recognition-benchmark) by Clova AI Research, NAVER (Apache 2.0).
68
+ - **Detector:** [CRAFT](https://github.com/clovaai/CRAFT-pytorch) by Clova AI Research, NAVER (MIT). The weights are unchanged.
best_accuracy.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:405389e61a024a1d807b6438d3add77e1a50735da42cbbedafc72a34200710a6
3
+ size 199012802
craft_mlt_25k.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4a5efbfb48b4081100544e75e1e2b57f8de3d84f213004b14b85fd4b3748db17
3
+ size 83152330
opt.txt ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ------------ Options -------------
2
+ exp_name: FT_801010_off
3
+ train_data: .\data\train_lmdb_801010_gt2
4
+ valid_data: .\data\valid_lmdb_801010_gt2
5
+ manualSeed: 1111
6
+ workers: 0
7
+ batch_size: 64
8
+ num_iter: 2000
9
+ valInterval: 200
10
+ saved_model: .\saved_models\TPS-ResNet-BiLSTM-Attn-case-sensitive.pth
11
+ FT: True
12
+ adam: True
13
+ lr: 0.0001
14
+ beta1: 0.9
15
+ rho: 0.95
16
+ eps: 1e-08
17
+ grad_clip: 5
18
+ baiduCTC: False
19
+ select_data: ['/']
20
+ batch_ratio: ['1']
21
+ total_data_usage_ratio: 1.0
22
+ batch_max_length: 60
23
+ imgH: 32
24
+ imgW: 100
25
+ rgb: False
26
+ character: 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
27
+ sensitive: True
28
+ PAD: False
29
+ data_filtering_off: False
30
+ Transformation: TPS
31
+ FeatureExtraction: ResNet
32
+ SequenceModeling: BiLSTM
33
+ Prediction: Attn
34
+ num_fiducial: 20
35
+ input_channel: 1
36
+ output_channel: 512
37
+ hidden_size: 256
38
+ num_gpu: 1
39
+ num_class: 96
40
+ ---------------------------------------