File size: 3,957 Bytes
6d1698d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
---
language:
- bo
license: agpl-3.0
library_name: ultralytics
pipeline_tag: image-segmentation
datasets:
- openpecha/OCR-Tibetan_line_segmentation_coordinate_annotation
tags:
- tibetan
- document-ai
- line-segmentation
- instance-segmentation
- yolo11
- ultralytics
---

# PechaBridgeLineSegmentation

YOLO11n instance-segmentation model for detecting individual Tibetan text
lines on traditional pecha page scans. The model is the line-layout stage used
by [PechaBridge](https://github.com/CodexAITeam/PechaBridge) before OCR.

> **Important:** The supported PechaBridge inference pipeline applies the
> `gray` preprocessing mode (minimum RGB channel, no binarization) before YOLO
> inference. Raw Ultralytics inference can produce different results.

## Recommended usage — PechaBridge CLI

```bash
git clone https://github.com/CodexAITeam/PechaBridge.git
cd PechaBridge
pip install -r requirements.txt

# Downloads this model and the PechaBridge OCR model.
python cli.py download-models

python cli.py batch-ocr \
    --input-dir /path/to/pecha/pages \
    --ocr-model models/ocr/PechaBridgeOCR \
    --line-model models/line_segmentation/PechaBridgeLineSegmentation.pt \
    --layout-engine yolo_line \
    --line-preprocess gray \
    --ocr-engine donut
```

## Python usage

```python
from pathlib import Path

from huggingface_hub import snapshot_download
from PIL import Image
from ultralytics import YOLO

from pechabridge.ocr.line_segmentation import (
    apply_line_segmentation_preprocess,
)

model_dir = Path(snapshot_download(
    "TibetanCodexAITeam/PechaBridgeLineSegmentation"
))
weights = next(model_dir.glob("*.pt"))
model = YOLO(str(weights))

image = Image.open("page.jpg").convert("RGB")
prepared = apply_line_segmentation_preprocess(image, pipeline="gray")
results = model.predict(
    source=prepared,
    imgsz=1280,
    conf=0.25,
    verbose=False,
)

for result in results:
    print(result.boxes.xyxy)  # line bounding boxes
    print(result.masks.xy)    # line polygons
```

## Model details

- **Architecture:** Ultralytics YOLO11n segmentation
- **Task:** single-class instance segmentation
- **Class:** `line`
- **Weights:** `yolo_line_seg.pt` (about 6.0 MB)
- **Recommended input size:** `1280`
- **Recommended confidence threshold:** `0.25`
- **Recommended preprocessing:** PechaBridge `gray`
- **Ultralytics version used for the exported checkpoint:** `8.4.14`

## Training data

The training corpus was derived from
[`openpecha/OCR-Tibetan_line_segmentation_coordinate_annotation`](https://huggingface.co/datasets/openpecha/OCR-Tibetan_line_segmentation_coordinate_annotation),
converted to YOLO polygons, padded, filtered, and split locally:

| Split | Images | Label files |
|---|---:|---:|
| Train | 3,487 | 3,487 |
| Validation | 519 | 519 |
| Test | 503 | 503 |

## Validation results

Metrics stored in the released checkpoint:

| Output | Precision | Recall | mAP50 | mAP50–95 |
|---|---:|---:|---:|---:|
| Bounding boxes | 0.97736 | 0.96768 | 0.99138 | 0.61298 |
| Segmentation masks | 0.90993 | 0.90055 | 0.89697 | 0.41885 |

These numbers describe the local validation split and should not be treated as
an independent cross-collection benchmark.

## Intended use and limitations

- Intended for locating horizontal Tibetan text lines in traditional pecha scans.
- Not an OCR model; detected line crops must be passed to a text recognizer.
- Performance may degrade on modern book layouts, handwriting, vertical text,
  heavy page curvature, severe blur, unusual ornaments, or unseen collections.
- Closely spaced or touching lines may be merged; damaged lines may be fragmented.
- Predictions should be reviewed before scholarly or archival publication.

## License

AGPL-3.0. The checkpoint was trained with Ultralytics YOLO, whose open-source
software and trained model weights are distributed under AGPL-3.0 by default.
Commercial or closed-source use may require an Ultralytics Enterprise License.