Flavio de Oliveira commited on
Commit
db681f0
·
1 Parent(s): 390a505

First commit

Browse files
.gitignore ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ __pycache__
2
+ .DS_Store
3
+ flagged/
4
+ tests/
5
+ *.yml
6
+ *.ipynb
README.md CHANGED
@@ -1,6 +1,6 @@
1
  ---
2
- title: Pylaia Htr
3
- emoji: 💻
4
  colorFrom: gray
5
  colorTo: indigo
6
  sdk: gradio
 
1
  ---
2
+ title: PyLaia HTR
3
+ emoji: ✍️
4
  colorFrom: gray
5
  colorTo: indigo
6
  sdk: gradio
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import subprocess
3
+ from PIL import Image
4
+ import tempfile
5
+ import os
6
+
7
+ def predict(input_image: Image.Image):
8
+ # Save the input image to a temporary file
9
+ temp_dir = tempfile.mkdtemp()
10
+ temp_image_path = os.path.join(temp_dir, 'temp_image.jpg')
11
+ input_image.save(temp_image_path)
12
+
13
+ # Update img_list to include the path of the temporary image
14
+ with open('test_img_list.txt', 'w') as f:
15
+ f.write(temp_image_path)
16
+
17
+ # Run the pylaia-htr-decode-ctc command
18
+ subprocess.run(['pylaia-htr-decode-ctc', '--config', 'my_decode_config.yaml'])
19
+
20
+ # Read the output from predict.txt
21
+ with open('predict.txt', 'r') as f:
22
+ output = f.read().strip().split('\n')[-1] # Assuming the last line of predict.txt contains the desired output
23
+
24
+ # Cleanup temporary files
25
+ os.remove(temp_image_path)
26
+ os.rmdir(temp_dir)
27
+
28
+ return output
29
+
30
+ # Gradio interface
31
+ title = "PyLaia HTR"
32
+ description = "Inference using PyLaia models."
33
+ examples =[["examples/example01.jpg"], ["examples/example02.jpg"]]
34
+
35
+ iface = gr.Interface(
36
+ fn=predict,
37
+ inputs=gr.inputs.Image(type="pil"),
38
+ outputs=gr.outputs.Textbox(),
39
+ title=title,
40
+ description=description,
41
+ examples=examples
42
+ )
43
+
44
+ iface.launch()
examples/example01.jpg ADDED
examples/example02.jpg ADDED
my_decode_config.yaml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ common:
2
+ experiment_dirname: pylaia-huginmunin
3
+ model_filename: pylaia-huginmunin/model
4
+ decode:
5
+ convert_spaces: true
6
+ join_string: ''
7
+ use_language_model: False
8
+ img_list: test_img_list.txt
9
+ syms: pylaia-huginmunin/syms.txt
pylaia-huginmunin/.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
35
+ model filter=lfs diff=lfs merge=lfs -text
pylaia-huginmunin/README.md ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: PyLaia
3
+ license: mit
4
+ tags:
5
+ - PyLaia
6
+ - PyTorch
7
+ - Handwritten text recognition
8
+ metrics:
9
+ - CER
10
+ - WER
11
+ language:
12
+ - 'no'
13
+ ---
14
+
15
+ # Hugin-Munin handwritten text recognition
16
+
17
+ This model performs Handwritten Text Recognition in Norwegian. It was developed during the [HUGIN-MUNIN project](https://hugin-munin-project.github.io/).
18
+
19
+ ## Model description
20
+
21
+ The model has been trained using the PyLaia library on the [NorHand](https://zenodo.org/record/6542056) document images.
22
+ Training images were resized with a fixed height of 128 pixels, keeping the original aspect ratio.
23
+
24
+ ## Evaluation results
25
+
26
+ The model achieves the following results:
27
+
28
+ | set | CER (%) | WER (%) |
29
+ | ----- | ---------- | --------- |
30
+ | train | 2.17 | 7.65 |
31
+ | val | 8.78 | 24.93 |
32
+ | test | 7.94 | 24.04 |
33
+
34
+
35
+ Results improve on validation and test sets when PyLaia is combined with a 6-gram language model.
36
+ The language model is trained on [this text corpus](https://www.nb.no/sprakbanken/en/resource-catalogue/oai-nb-no-sbr-73/) published by the National Library of Norway.
37
+
38
+ | set | CER (%) | WER (%) |
39
+ | ----- | ---------- | --------- |
40
+ | train | 2.40 | 8.10 |
41
+ | val | 7.45 | 19.75 |
42
+ | test | 6.55 | 18.2 |
43
+
44
+
45
+ ## How to use
46
+
47
+ Please refer to the PyLaia [library page](https://pypi.org/project/pylaia/) and [wiki](https://github.com/jpuigcerver/PyLaia/wiki/inference) to use this model.
48
+
49
+ # Cite us!
50
+
51
+ ```bibtex
52
+ @inproceedings{10.1007/978-3-031-06555-2_27,
53
+ author = {Maarand, Martin and Beyer, Yngvil and K\r{a}sen, Andre and Fosseide, Knut T. and Kermorvant, Christopher},
54
+ title = {A Comprehensive Comparison of Open-Source Libraries for Handwritten Text Recognition in Norwegian},
55
+ year = {2022},
56
+ isbn = {978-3-031-06554-5},
57
+ publisher = {Springer-Verlag},
58
+ address = {Berlin, Heidelberg},
59
+ url = {https://doi.org/10.1007/978-3-031-06555-2_27},
60
+ doi = {10.1007/978-3-031-06555-2_27},
61
+ booktitle = {Document Analysis Systems: 15th IAPR International Workshop, DAS 2022, La Rochelle, France, May 22–25, 2022, Proceedings},
62
+ pages = {399–413},
63
+ numpages = {15},
64
+ keywords = {Norwegian language, Open-source, Handwriting recognition},
65
+ location = {La Rochelle, France}
66
+ }
67
+ ```
pylaia-huginmunin/language_model.arpa.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d354aad04d3ed55cd4ca26c21f85a0ab30b0a5b5c538f9e58c4fe24566cfbca3
3
+ size 25536981
pylaia-huginmunin/lexicon.txt ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <ctc> <ctc>
2
+ ! !
3
+ " "
4
+ & &
5
+ ' '
6
+ ( (
7
+ ) )
8
+ + +
9
+ , ,
10
+ - -
11
+ . .
12
+ / /
13
+ 0 0
14
+ 1 1
15
+ 2 2
16
+ 3 3
17
+ 4 4
18
+ 5 5
19
+ 6 6
20
+ 7 7
21
+ 8 8
22
+ 9 9
23
+ : :
24
+ ; ;
25
+ < <
26
+ = =
27
+ > >
28
+ ? ?
29
+ A A
30
+ B B
31
+ C C
32
+ D D
33
+ E E
34
+ F F
35
+ G G
36
+ H H
37
+ I I
38
+ J J
39
+ K K
40
+ L L
41
+ M M
42
+ N N
43
+ O O
44
+ P P
45
+ Q Q
46
+ R R
47
+ S S
48
+ T T
49
+ U U
50
+ V V
51
+ W W
52
+ X X
53
+ Y Y
54
+ Z Z
55
+ [ [
56
+ ] ]
57
+ a a
58
+ b b
59
+ c c
60
+ d d
61
+ e e
62
+ f f
63
+ g g
64
+ h h
65
+ i i
66
+ j j
67
+ k k
68
+ l l
69
+ m m
70
+ n n
71
+ o o
72
+ p p
73
+ q q
74
+ r r
75
+ s s
76
+ t t
77
+ u u
78
+ v v
79
+ w w
80
+ x x
81
+ y y
82
+ z z
83
+ « «
84
+ ¬ ¬
85
+ » »
86
+ ¼ ¼
87
+ ½ ½
88
+ Å Å
89
+ Æ Æ
90
+ Ø Ø
91
+ à à
92
+ á á
93
+ â â
94
+ ä ä
95
+ å å
96
+ æ æ
97
+ ç ç
98
+ è è
99
+ é é
100
+ ê ê
101
+ ö ö
102
+ ø ø
103
+ ù ù
104
+ û û
105
+ ü ü
106
+ – –
107
+ — —
108
+ ’ ’
109
+ „ „
110
+ … …
111
+ <unk> <unk>
112
+ <space> <space>
pylaia-huginmunin/model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ea4872333c53946b1095d0099fdb762c9fe6dbf51b0a46a79ae4982e0af9c71d
3
+ size 1519
pylaia-huginmunin/syms.txt ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <ctc> 0
2
+ ! 1
3
+ " 2
4
+ & 3
5
+ ' 4
6
+ ( 5
7
+ ) 6
8
+ + 7
9
+ , 8
10
+ - 9
11
+ . 10
12
+ / 11
13
+ 0 12
14
+ 1 13
15
+ 2 14
16
+ 3 15
17
+ 4 16
18
+ 5 17
19
+ 6 18
20
+ 7 19
21
+ 8 20
22
+ 9 21
23
+ : 22
24
+ ; 23
25
+ < 24
26
+ = 25
27
+ > 26
28
+ ? 27
29
+ A 28
30
+ B 29
31
+ C 30
32
+ D 31
33
+ E 32
34
+ F 33
35
+ G 34
36
+ H 35
37
+ I 36
38
+ J 37
39
+ K 38
40
+ L 39
41
+ M 40
42
+ N 41
43
+ O 42
44
+ P 43
45
+ Q 44
46
+ R 45
47
+ S 46
48
+ T 47
49
+ U 48
50
+ V 49
51
+ W 50
52
+ X 51
53
+ Y 52
54
+ Z 53
55
+ [ 54
56
+ ] 55
57
+ a 56
58
+ b 57
59
+ c 58
60
+ d 59
61
+ e 60
62
+ f 61
63
+ g 62
64
+ h 63
65
+ i 64
66
+ j 65
67
+ k 66
68
+ l 67
69
+ m 68
70
+ n 69
71
+ o 70
72
+ p 71
73
+ q 72
74
+ r 73
75
+ s 74
76
+ t 75
77
+ u 76
78
+ v 77
79
+ w 78
80
+ x 79
81
+ y 80
82
+ z 81
83
+ « 82
84
+ ¬ 83
85
+ » 84
86
+ ¼ 85
87
+ ½ 86
88
+ Å 87
89
+ Æ 88
90
+ Ø 89
91
+ à 90
92
+ á 91
93
+ â 92
94
+ ä 93
95
+ å 94
96
+ æ 95
97
+ ç 96
98
+ è 97
99
+ é 98
100
+ ê 99
101
+ ö 100
102
+ ø 101
103
+ ù 102
104
+ û 103
105
+ ü 104
106
+ – 105
107
+ — 106
108
+ ’ 107
109
+ „ 108
110
+ … 109
111
+ <unk> 110
112
+ <space> 111
pylaia-huginmunin/tokens.txt ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <ctc>
2
+ !
3
+ "
4
+ &
5
+ '
6
+ (
7
+ )
8
+ +
9
+ ,
10
+ -
11
+ .
12
+ /
13
+ 0
14
+ 1
15
+ 2
16
+ 3
17
+ 4
18
+ 5
19
+ 6
20
+ 7
21
+ 8
22
+ 9
23
+ :
24
+ ;
25
+ <
26
+ =
27
+ >
28
+ ?
29
+ A
30
+ B
31
+ C
32
+ D
33
+ E
34
+ F
35
+ G
36
+ H
37
+ I
38
+ J
39
+ K
40
+ L
41
+ M
42
+ N
43
+ O
44
+ P
45
+ Q
46
+ R
47
+ S
48
+ T
49
+ U
50
+ V
51
+ W
52
+ X
53
+ Y
54
+ Z
55
+ [
56
+ ]
57
+ a
58
+ b
59
+ c
60
+ d
61
+ e
62
+ f
63
+ g
64
+ h
65
+ i
66
+ j
67
+ k
68
+ l
69
+ m
70
+ n
71
+ o
72
+ p
73
+ q
74
+ r
75
+ s
76
+ t
77
+ u
78
+ v
79
+ w
80
+ x
81
+ y
82
+ z
83
+ «
84
+ ¬
85
+ »
86
+ ¼
87
+ ½
88
+ Å
89
+ Æ
90
+ Ø
91
+ à
92
+ á
93
+ â
94
+ ä
95
+ å
96
+ æ
97
+ ç
98
+ è
99
+ é
100
+ ê
101
+ ö
102
+ ø
103
+ ù
104
+ û
105
+ ü
106
+
107
+
108
+
109
+
110
+
111
+ <unk>
112
+ <space>
pylaia-huginmunin/weights.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b3a6ece440293c25d0116438973c6b6ac5337d2ea30cf03953081445384f957f
3
+ size 42799260
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ git+https://github.com/jpuigcerver/PyLaia/
2
+ nnutils-pytorch
test_img_list.txt ADDED
@@ -0,0 +1 @@
 
 
1
+