File size: 1,995 Bytes
34714cd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
pretty_name: ocr_data
task_categories:
- image-to-text
language:
- ar
tags:
- ocr
- arabic
- synthetic
- webdataset
---

# ocr_data

Synthetic Arabic document images with layout annotations, for OCR training.

## Layout

WebDataset `.tar` shards. Files sharing a basename are one sample, so the
image becomes the `image` column and the annotation the `json` column.

```
data/<contributor>_<NNN>.tar            originals (PNG + JSON)
data_aug/<contributor>_<NNN>_aug<K>.tar augmented variants (JPEG/PNG + JSON)
```

Each shard holds up to 9990 samples (~1.2 GB). `data/` and `data_aug/`
are separate so you can train on clean originals alone.

## Loading

```python
from datasets import load_dataset

# one shard
ds = load_dataset("webdataset",
                  data_files="hf://datasets/OCR-Data-new/ocr_data/data/<contributor>_001.tar",
                  split="train", streaming=True)

# a range of shards
ds = load_dataset("webdataset",
                  data_files="hf://datasets/OCR-Data-new/ocr_data/data/<contributor>_{001..010}.tar",
                  split="train", streaming=True)

# everything, originals + augmented
ds = load_dataset("webdataset", data_files={"train": [
        "hf://datasets/OCR-Data-new/ocr_data/data/*.tar",
        "hf://datasets/OCR-Data-new/ocr_data/data_aug/*.tar"]},
      split="train", streaming=True)
```

To get loose files back, use `unpack_shard.py` from the generator repo.

## Annotation schema

```json
{
  "dimensions": {"width": 0, "height": 0},
  "blocks":  [{"type": "...", "text": "...", "top_left_x": 0, "top_left_y": 0,
                "bottom_right_x": 0, "bottom_right_y": 0, "reading_index": 0}],
  "images":  [{"top_left_x": 0, "...": 0}],
  "meta":    {"template": "...", "hybrid": null, "page_font": "...",
               "language": "ar", "script": "arabic", "direction": "rtl",
               "augmentation": null}
}
```

`meta.augmentation` is `null` for originals and
`{"name": ..., "params": {...}}` for augmented variants.