In this paper we investigate the generalization capability of state-of-the-art object detection models (Hi-SAM, YOLO, and RT-DETR) for the automatic segmentation of text lines in historical documents. Generalization is needed because it is not practical for museums and archives to produce large amounts of labeled samples for each new collection. We also evaluate the few-shot setting by fine-tuning the networks with only a small number of training samples per target dataset. To this end, we use nine different datasets that differ significantly in visual layout and language. Additionally, we discuss why mean average precision (mAP), a classic evaluation metric for object detection, is insufficient for assessing the quality of a text line segmentation model. Depending on the dataset, our CRNN models achieve character error rates (CER) ranging from 2.48% to 7.07% per page for the segmented text lines. This is sufficient for reading comprehension and simple text searches. Finally, we quantify the resource and time requirements of training and inference in different use case settings. This forms the basis for more informed decisions about model and hardware choices based on available resources.
Figures & tables
English
Norwegian
Swedish
German
Mix Dataset
Bentham Sánchez (2016)
NorHand 72702 Beyer and Solberg (2023)
NorHand 331861 Beyer and Solberg (2023)
Riksarkivet BK 1 Riksarkivet (2024)
Riksarkivet BK 2 Riksarkivet (2024)
Riksarkivet GBG 1 Riksarkivet (2024)
Riksarkivet GBG 2 Riksarkivet (2024)
READ 2016 Sanchez et al. (2016)
Nuremberg LB 3 Mayr et al. (2025)
Mix
Time
19th century
19th/20th century
18th century
19th century
15th-19th century
15th century
Pages
Train
350
292
319
184
175
208
146
350
433
336
Val
50
37
40
23
22
26
18
50
55
47
Test
33
37
40
24
22
27
19
50
53
46
Total
433
366
399
231
219
261
183
450
541
429
Table 1: Dataset statistics for the ten datasets used in the study. The table reports the number of pages and text lines in the training, validation, test, and total splits. Underlined datasets have been used as source domains for training.
Figure 1: Visual overview of all used datasets. The documents vary in language, handwriting style, and paper color. Some documents are more prone to bleed-through effects than others.
Tested on
Training Dataset
Line Detector
Bentham
NorHand 72702
NorHand 331861
Riksarkivet BK 1
Riksarkivet BK 2
Riksarkivet GBG 1
Riksarkivet GBG 2
READ 2016
Nuremberg LB 3
NorHand-331861
Hi-SAM
49.64
58.00
75.53
68.05
62.02
55.62
47.15
28.77
41.29
YOLO
39.51
52.89
81.67
74.78
71.31
58.53
48.72
21.31
19.86
RT-DETR
12.05
15.81
37.22
16.58
27.50
15.85
13.10
07.41
05.27
READ 2016
Hi-SAM
32.17
35.85
41.74
29.22
33.85
38.43
33.75
79.01
49.08
YOLO
25.26
13.98
13.35
24.43
21.74
34.94
27.65
81.12
28.22
Table 2: Cross-dataset evaluation of three line detectors trained on four datasets and tested on nine datasets. Performance is reported as mAP, where higher value is better.
Figure 2: Qualitative comparison. The first row shows ground-truth bounding boxes; the remaining rows show the corresponding predictions from each line detection model on samples from the nine datasets used in this study.
Figure 3: Two ways IoU 0.5 overlap can occur. The blue box is the ground-truth bounding box. The red box is the predicted bounding box.
Tested on
Training Dataset
Line Detector
Bentham
NorHand 72702
NorHand 331861
Riksarkivet BK 1
Riksarkivet BK 2
Riksarkivet GBG 1
Riksarkivet GBG 2
READ 2016
Nuremberg LB 3
OOD AVG gap with Baseline
Baseline
GT-Boxes
2.22
1.61
3.09
3.40
2.48
4.60
2.96
3.99
5.02
NorHand-331861
Hi-SAM
5.03
3.56
3.65
4.72
3.53
8.81
13.82
13.46
14.05
5.09
YOLO
7.47
6.64
3.48
4.93
5.93
9.67
14.13
14.82
39.90
9.65
RT-DETR
26.59
48.81
24.12
56.77
44.37
63.90
64.67
70.25
86.14
54.40
READ 2016
Hi-SAM
5.34
4.08
6.52
4.74
3.73
8.81
12.39
4.40
8.35
3.57
Table 3: Cross-dataset evaluation of three line detectors trained on four datasets and tested on 9 datasets. Performance is reported as CER%, where lower values indicate better performance.
Tested on
Line Detector
Bentham
NorHand 72702
Riksarkivet BK
Riksarkivet BK 2
Riksarkivet GBG 1
Riksarkivet GBG 2
Zero-shot
Hi-SAM
45.32
54.04
40.64
42.16
44.18
37.08
Few-shot 10
Hi-SAM
64.32
54.64
73.91
71.75
62.77
53.99
Few-shot 50
Hi-SAM
68.10
60.64
75.44
72.81
65.50
59.12
Zero-shot
YOLO
30.44
48.46
51.41
60.40
61.24
50.04
Few-shot 10
YOLO
62.04
57.25
82.14
80.49
67.86
61.02
Table 4: Few-shot mAP% evaluation of Hi-SAM and YOLO line detectors pre-trained on the Mix dataset and fine-tuned on six target datasets. Zero-shot rows report the corresponding results from Table 2 . Higher values indicate better performance.
Tested on
Line Detector
Bentham
NorHand 72702
Riksarkivet BK 1
Riksarkivet BK 2
Riksarkivet GBG 1
Riksarkivet GBG 2
OOD AVG gap with Baseline
Baseline
GT-Boxes
2.22
1.61
3.40
2.48
4.60
2.96
Zero-shot
Hi-SAM
4.44
3.36
4.20
3.14
7.77
11.76
2.90
Few-shot 10
Hi-SAM
3.31
2.72
3.89
2.64
6.59
8.25
1.69
Few-shot 50
Hi-SAM
3.22
2.56
3.57
2.69
6.50
5.89
1.19
Zero-shot
YOLO
5.48
10.81
4.09
3.67
7.53
11.87
4.36
Table 5: Few-shot CER% evaluation of line detectors pre-trained on the Mix dataset and fine-tuned on six OOD datasets. Zero-shot rows report the corresponding results from Table 3 . Lower values indicate better performance. The GT row reports the performance of the HTR model when trained using ground-truth line bounding boxes.
Training
Inference
GPU Memory
# Param.
Training in (GPU) hours
GPU Memory
Model Load Time
Inference per Page Batch Size = 1
A100
Hi-SAM
40 GB
699.2 M (62.2 trainable)
690 GPUh (with SAM weights) 380 GPUh (with Hi-SAM weights)
13 GB
9.75 s
1.6 s
YOLO
26 GB
46.0 M
2.5 GPUh (avg 3100 epochs)
1.5 GB
0.5 s
0.12 s
RT-DETR
23 GB
32.8 M
2.0 GPUh (avg 2500 epochs)
1.2 GB
0.5 s
0.13 s
RTX 4080
Hi-SAM
-
699.2 M (62.2 trainable)
-
-
4.97 s
1.5 s
YOLO
-
46.0 M
50 h (for 3100 epochs)
-
0.10 s
0.11 s
Table 6: Overview of run times of the tested models in different use case environments, investigating the loading time for models as well as training and inference performance.