doctr-synth-generator 0.2.1__tar.gz → 0.3.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {doctr_synth_generator-0.2.1 → doctr_synth_generator-0.3.1}/PKG-INFO +180 -83
- {doctr_synth_generator-0.2.1 → doctr_synth_generator-0.3.1}/README.md +179 -82
- {doctr_synth_generator-0.2.1 → doctr_synth_generator-0.3.1}/doctr_synth_generator.egg-info/PKG-INFO +180 -83
- {doctr_synth_generator-0.2.1 → doctr_synth_generator-0.3.1}/doctr_synth_generator.egg-info/SOURCES.txt +5 -1
- doctr_synth_generator-0.3.1/doctr_synth_generator.egg-info/entry_points.txt +2 -0
- {doctr_synth_generator-0.2.1 → doctr_synth_generator-0.3.1}/doctr_synth_generator.egg-info/top_level.txt +3 -0
- doctr_synth_generator-0.3.1/generator/__init__.py +8 -0
- doctr_synth_generator-0.3.1/generator/__main__.py +73 -0
- doctr_synth_generator-0.3.1/generator/api.py +53 -0
- {doctr_synth_generator-0.2.1 → doctr_synth_generator-0.3.1}/generator/components/__init__.py +12 -1
- doctr_synth_generator-0.3.1/generator/components/config.py +324 -0
- {doctr_synth_generator-0.2.1 → doctr_synth_generator-0.3.1}/generator/components/generator.py +11 -11
- {doctr_synth_generator-0.2.1 → doctr_synth_generator-0.3.1}/generator/components/page_generator.py +35 -35
- {doctr_synth_generator-0.2.1 → doctr_synth_generator-0.3.1}/generator/components/text_renderer.py +16 -13
- {doctr_synth_generator-0.2.1 → doctr_synth_generator-0.3.1}/generator/components/text_styling.py +13 -21
- {doctr_synth_generator-0.2.1 → doctr_synth_generator-0.3.1}/generator/components/vocab_coverage.py +89 -9
- {doctr_synth_generator-0.2.1 → doctr_synth_generator-0.3.1}/generator/dataset_generator.py +117 -73
- {doctr_synth_generator-0.2.1 → doctr_synth_generator-0.3.1}/generator/doctr_dataset.py +101 -23
- doctr_synth_generator-0.3.1/generator/version.py +1 -0
- {doctr_synth_generator-0.2.1 → doctr_synth_generator-0.3.1}/pyproject.toml +4 -0
- doctr_synth_generator-0.3.1/scripts/generate_grid.py +185 -0
- {doctr_synth_generator-0.2.1 → doctr_synth_generator-0.3.1}/setup.py +1 -1
- doctr_synth_generator-0.2.1/generator/__init__.py +0 -4
- doctr_synth_generator-0.2.1/generator/components/config.py +0 -272
- doctr_synth_generator-0.2.1/generator/version.py +0 -1
- {doctr_synth_generator-0.2.1 → doctr_synth_generator-0.3.1}/LICENSE +0 -0
- {doctr_synth_generator-0.2.1 → doctr_synth_generator-0.3.1}/doctr_synth_generator.egg-info/dependency_links.txt +0 -0
- {doctr_synth_generator-0.2.1 → doctr_synth_generator-0.3.1}/doctr_synth_generator.egg-info/requires.txt +0 -0
- {doctr_synth_generator-0.2.1 → doctr_synth_generator-0.3.1}/doctr_synth_generator.egg-info/zip-safe +0 -0
- {doctr_synth_generator-0.2.1 → doctr_synth_generator-0.3.1}/generator/augmentations/__init__.py +0 -0
- {doctr_synth_generator-0.2.1 → doctr_synth_generator-0.3.1}/generator/augmentations/augmentation_pipeline.py +0 -0
- {doctr_synth_generator-0.2.1 → doctr_synth_generator-0.3.1}/generator/augmentations/random_blur.py +0 -0
- {doctr_synth_generator-0.2.1 → doctr_synth_generator-0.3.1}/generator/augmentations/random_gaussian_noise.py +0 -0
- {doctr_synth_generator-0.2.1 → doctr_synth_generator-0.3.1}/generator/augmentations/random_jpeg_compression.py +0 -0
- {doctr_synth_generator-0.2.1 → doctr_synth_generator-0.3.1}/generator/augmentations/random_perspective.py +0 -0
- {doctr_synth_generator-0.2.1 → doctr_synth_generator-0.3.1}/generator/augmentations/random_pixel_dropout.py +0 -0
- {doctr_synth_generator-0.2.1 → doctr_synth_generator-0.3.1}/generator/augmentations/random_rotate.py +0 -0
- {doctr_synth_generator-0.2.1 → doctr_synth_generator-0.3.1}/generator/components/background_downloader.py +0 -0
- {doctr_synth_generator-0.2.1 → doctr_synth_generator-0.3.1}/generator/components/background_manager.py +0 -0
- {doctr_synth_generator-0.2.1 → doctr_synth_generator-0.3.1}/generator/components/corpus_downloader.py +0 -0
- {doctr_synth_generator-0.2.1 → doctr_synth_generator-0.3.1}/generator/components/dataset_balancer.py +0 -0
- {doctr_synth_generator-0.2.1 → doctr_synth_generator-0.3.1}/generator/components/dataset_splitter.py +0 -0
- {doctr_synth_generator-0.2.1 → doctr_synth_generator-0.3.1}/generator/components/font_downloader.py +0 -0
- {doctr_synth_generator-0.2.1 → doctr_synth_generator-0.3.1}/generator/components/font_selector.py +0 -0
- {doctr_synth_generator-0.2.1 → doctr_synth_generator-0.3.1}/generator/components/vocabs.py +0 -0
- {doctr_synth_generator-0.2.1 → doctr_synth_generator-0.3.1}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: doctr-synth-generator
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.1
|
|
4
4
|
Summary: A synthetic data generator for training OCR models
|
|
5
5
|
Author-email: Felix Dittrich <felixdittrich92@gmail.com>
|
|
6
6
|
Maintainer: Felix Dittrich
|
|
@@ -250,11 +250,13 @@ Dynamic: license-file
|
|
|
250
250
|

|
|
251
251
|
[](https://codecov.io/gh/felixdittrich92/docTR-Synth-Generator)
|
|
252
252
|
[](https://www.codefactor.io/repository/github/felixdittrich92/doctr-synth-generator)
|
|
253
|
-
[](https://pypi.org/project/docTR-Synth-Generator/)
|
|
254
254
|
|
|
255
255
|
# docTR-Synth-Generator
|
|
256
256
|
A tool to generate synthetic OCR datasets - made for docTR
|
|
257
257
|
|
|
258
|
+

|
|
259
|
+
|
|
258
260
|
## Features
|
|
259
261
|
|
|
260
262
|
- **Zero-config**: generate a dataset with nothing but an output directory - real
|
|
@@ -275,87 +277,98 @@ A tool to generate synthetic OCR datasets - made for docTR
|
|
|
275
277
|
- **Fast & memory-bounded**: font objects and decoded backgrounds are cached, with
|
|
276
278
|
a configurable cache size.
|
|
277
279
|
|
|
278
|
-
## Quickstart
|
|
280
|
+
## Quickstart
|
|
279
281
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
requested language(s) and automatically fetches matching open-source fonts:
|
|
282
|
+
One call - the words, fonts and backgrounds it needs are downloaded and cached
|
|
283
|
+
automatically. English by default:
|
|
283
284
|
|
|
284
285
|
```python
|
|
285
|
-
from generator import
|
|
286
|
+
from generator import generate_dataset
|
|
286
287
|
|
|
287
|
-
|
|
288
|
-
SyntheticDatasetGenerator(config).generate_dataset()
|
|
288
|
+
generate_dataset("output_dataset", num_images=1000)
|
|
289
289
|
```
|
|
290
290
|
|
|
291
|
-
Multilingual is a
|
|
292
|
-
script, so
|
|
291
|
+
Multilingual is just a list of ISO 639-1 codes; each code selects its words *and*
|
|
292
|
+
its script, so matching fonts are pulled in and complex scripts are shaped
|
|
293
|
+
correctly:
|
|
293
294
|
|
|
294
295
|
```python
|
|
295
|
-
|
|
296
|
-
output_dir="output_dataset",
|
|
297
|
-
num_images=10000,
|
|
298
|
-
languages=["en", "de", "ru", "el", "ar"], # words + fonts resolved automatically
|
|
299
|
-
bg_image_dir="resources/background_images", # optional; blank backgrounds otherwise
|
|
300
|
-
)
|
|
301
|
-
SyntheticDatasetGenerator(config).generate_dataset()
|
|
296
|
+
generate_dataset("output_dataset", num_images=10000, languages=["en", "de", "ru", "el", "ar"])
|
|
302
297
|
```
|
|
303
298
|
|
|
304
|
-
|
|
305
|
-
> them (`corpus_cache_dir` / `font_cache_dir`). Subsequent runs are offline. To
|
|
306
|
-
> run fully offline from the start, supply your own `wordlist_path` and
|
|
307
|
-
> `font_dir`.
|
|
299
|
+
Detection pages instead of recognition crops:
|
|
308
300
|
|
|
309
|
-
|
|
301
|
+
```python
|
|
302
|
+
generate_dataset("pages", num_images=5000, task="detection", languages=["en", "de"])
|
|
303
|
+
```
|
|
310
304
|
|
|
311
|
-
|
|
312
|
-
over the automatic downloads:
|
|
305
|
+
...or straight from the command line (installs as `doctr-synth`, also runnable as `python -m generator`):
|
|
313
306
|
|
|
314
|
-
```
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
font_dir="resources/font", # e.g. the extracted fonts_v1 release
|
|
318
|
-
bg_image_dir="resources/background_images", # bundled with the repo
|
|
319
|
-
output_dir="output_dataset",
|
|
320
|
-
num_images=1000,
|
|
321
|
-
val_percent=0.2,
|
|
322
|
-
num_workers=6,
|
|
323
|
-
# If a word contains characters none of your local fonts cover, download a
|
|
324
|
-
# matching font instead of dropping the word (default: True):
|
|
325
|
-
auto_download_fonts=True,
|
|
326
|
-
)
|
|
327
|
-
SyntheticDatasetGenerator(config).generate_dataset()
|
|
307
|
+
```bash
|
|
308
|
+
doctr-synth output_dataset -n 10000 -l en de ru
|
|
309
|
+
doctr-synth pages -t detection -l en de --layout newspaper
|
|
328
310
|
```
|
|
329
311
|
|
|
330
|
-
|
|
312
|
+
> The first run downloads word lists, fonts and backgrounds from public mirrors
|
|
313
|
+
> and caches them; later runs are offline. To stay fully offline from the start,
|
|
314
|
+
> supply your own `wordlist_path` and `font_dir` (see below).
|
|
315
|
+
|
|
316
|
+
`generate_dataset(...)` is a thin wrapper over the `GenerationConfig` +
|
|
317
|
+
`SyntheticDatasetGenerator` pair you can still use directly for full control. The
|
|
318
|
+
config is organised into focused sub-configs (`core`, `resources`, `corpus`,
|
|
319
|
+
`balance`, `coverage`, `recognition`, `realism`, `detection`) - build it nested,
|
|
320
|
+
or use `GenerationConfig.flat(...)` to pass flat keyword names. Any of those
|
|
321
|
+
keywords can also be passed straight to `generate_dataset(...)`:
|
|
322
|
+
|
|
323
|
+
```python
|
|
324
|
+
from generator import GenerationConfig, CoreConfig, DetectionConfig
|
|
325
|
+
|
|
326
|
+
# nested - group related options together
|
|
327
|
+
cfg = GenerationConfig(
|
|
328
|
+
core=CoreConfig(num_images=10_000, task="detection", languages=["en", "de"]),
|
|
329
|
+
detection=DetectionConfig(layout="newspaper"),
|
|
330
|
+
)
|
|
331
331
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
Unicode range) is downloaded, verified for coverage and cached. This prevents
|
|
335
|
-
words from being silently skipped - the main cause of biased, latin-only
|
|
336
|
-
datasets. Disable with `auto_download_fonts=False`.
|
|
332
|
+
# ...or flat, routed into the sub-configs for you
|
|
333
|
+
cfg = GenerationConfig.flat(num_images=10_000, task="detection", det_layout="newspaper")
|
|
337
334
|
|
|
338
|
-
|
|
335
|
+
# ...or just the one-liner
|
|
336
|
+
generate_dataset("output_dataset", num_images=10_000, languages=["en", "de"], output_jpeg=True, num_workers=8)
|
|
337
|
+
```
|
|
339
338
|
|
|
340
|
-
|
|
341
|
-
are downloaded (from the open
|
|
342
|
-
[FrequencyWords](https://github.com/hermitdave/FrequencyWords) project, ~85
|
|
343
|
-
languages) and cleaned (script filtering, length bounds, punctuation removal).
|
|
344
|
-
Two realism helpers are applied by default and can be tuned or disabled:
|
|
339
|
+
### Bring your own resources
|
|
345
340
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
- `numeric_token_ratio` (0.05): mixes in realistic numbers, dates, prices and
|
|
349
|
-
codes - the kind of content real documents are full of.
|
|
341
|
+
`wordlist_path` and/or `font_dir` take precedence over the automatic downloads
|
|
342
|
+
(e.g. the bundled `resources/` or the `fonts_v1` release):
|
|
350
343
|
|
|
351
|
-
|
|
344
|
+
```python
|
|
345
|
+
generate_dataset(
|
|
346
|
+
"output_dataset",
|
|
347
|
+
num_images=1000,
|
|
348
|
+
wordlist_path="resources/corpus/latin_ext_balanced_words.txt",
|
|
349
|
+
font_dir="resources/font",
|
|
350
|
+
bg_image_dir="resources/background_images",
|
|
351
|
+
)
|
|
352
|
+
```
|
|
352
353
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
`
|
|
358
|
-
|
|
354
|
+
## Automatic resources
|
|
355
|
+
|
|
356
|
+
On the first run anything you don't provide is fetched from public mirrors and
|
|
357
|
+
cached (later runs are offline). Providing your own `font_dir` / `wordlist_path`
|
|
358
|
+
/ `bg_image_dir` takes precedence and skips the matching download.
|
|
359
|
+
|
|
360
|
+
- **Fonts** - when no local font covers every character of a word, a matching
|
|
361
|
+
open-source [Noto](https://fonts.google.com/noto) font is downloaded, verified
|
|
362
|
+
and cached, so words are never silently skipped (the usual cause of biased,
|
|
363
|
+
latin-only datasets). Disable with `auto_download_fonts=False`.
|
|
364
|
+
- **Words** - with no `wordlist_path`, real frequency-ranked words come from
|
|
365
|
+
[FrequencyWords](https://github.com/hermitdave/FrequencyWords) (~85 languages)
|
|
366
|
+
and are cleaned (script filter, length bounds, punctuation removal). Two realism
|
|
367
|
+
helpers are on by default: `casing_variant_prob` (0.3) adds Title/UPPERCASE
|
|
368
|
+
variants, and `numeric_token_ratio` (0.05) mixes in numbers, dates and prices.
|
|
369
|
+
- **Backgrounds** - with no `bg_image_dir`, a curated background set is downloaded
|
|
370
|
+
instead of blank pages. Disable with `auto_download_backgrounds=False`, or pass
|
|
371
|
+
a `background_manifest_url` for your own collection.
|
|
359
372
|
|
|
360
373
|
## Dataset balancing
|
|
361
374
|
|
|
@@ -363,7 +376,7 @@ For multilingual runs the language mix is explicit and controllable instead of
|
|
|
363
376
|
being dominated by whichever language has the most words:
|
|
364
377
|
|
|
365
378
|
```python
|
|
366
|
-
config = GenerationConfig(
|
|
379
|
+
config = GenerationConfig.flat(
|
|
367
380
|
output_dir="output_dataset",
|
|
368
381
|
num_images=30000,
|
|
369
382
|
languages=["en", "de", "ru"],
|
|
@@ -379,6 +392,51 @@ generation (per-language train/val counts, train/val overlap, distinct/rare
|
|
|
379
392
|
characters, word-length statistics); silence it with
|
|
380
393
|
`print_balance_report=False`.
|
|
381
394
|
|
|
395
|
+
## Supported languages
|
|
396
|
+
|
|
397
|
+
Pass ISO 639-1 codes in `languages=[...]`. Each code resolves three things
|
|
398
|
+
automatically: real words from a public frequency list (when one exists), a
|
|
399
|
+
script-matching open-source font (downloaded on demand), and the docTR vocab
|
|
400
|
+
used for coverage and for the recognition vocab restriction. Complex scripts are
|
|
401
|
+
shaped correctly - Arabic, Hebrew and Urdu run right-to-left, and Indic, Thai and
|
|
402
|
+
Myanmar clusters (consonant conjuncts, matras, medials, vowel signs and viramas)
|
|
403
|
+
are built as valid grapheme clusters, including in synthesised coverage tokens.
|
|
404
|
+
|
|
405
|
+
| Script | Languages (ISO 639-1 code) |
|
|
406
|
+
| --- | --- |
|
|
407
|
+
| Latin | Afrikaans (`af`), Azerbaijani (`az`), Catalan (`ca`), Czech (`cs`), Danish (`da`), Dutch (`nl`), English (`en`), Estonian (`et`), Basque (`eu`), Finnish (`fi`), French (`fr`), German (`de`), Hungarian (`hu`), Icelandic (`is`), Indonesian (`id`), Irish (`ga`), Italian (`it`), Latvian (`lv`), Lithuanian (`lt`), Maltese (`mt`), Norwegian (`no`/`nb`), Polish (`pl`), Portuguese (`pt`), Romanian (`ro`), Slovak (`sk`), Slovene (`sl`), Spanish (`es`), Albanian (`sq`), Swedish (`sv`), Croatian (`hr`), Turkish (`tr`), Vietnamese (`vi`) |
|
|
408
|
+
| Cyrillic | Belarusian (`be`), Bulgarian (`bg`), Macedonian (`mk`), Russian (`ru`), Ukrainian (`uk`) |
|
|
409
|
+
| Greek | Greek (`el`) |
|
|
410
|
+
| Perso-Arabic | Arabic (`ar`), Persian (`fa`), Urdu (`ur`) |
|
|
411
|
+
| Hebrew | Hebrew (`he`) |
|
|
412
|
+
| Armenian | Armenian (`hy`) |
|
|
413
|
+
| Georgian | Georgian (`ka`) |
|
|
414
|
+
| Devanagari | Hindi (`hi`), Marathi (`mr`) |
|
|
415
|
+
| Bengali | Bengali (`bn`) |
|
|
416
|
+
| Gujarati | Gujarati (`gu`) |
|
|
417
|
+
| Tamil | Tamil (`ta`) |
|
|
418
|
+
| Telugu | Telugu (`te`) |
|
|
419
|
+
| Kannada | Kannada (`kn`) |
|
|
420
|
+
| Malayalam | Malayalam (`ml`) |
|
|
421
|
+
| Oriya | Odia (`or`) |
|
|
422
|
+
| Sinhala | Sinhala (`si`) |
|
|
423
|
+
| Thai | Thai (`th`) |
|
|
424
|
+
| Myanmar | Burmese (`my`) |
|
|
425
|
+
| CJK | Japanese (`ja`), Korean (`ko`) - corpus-driven only (no fixed small vocab, so vocab-coverage synthesis is skipped) |
|
|
426
|
+
|
|
427
|
+
A few notes:
|
|
428
|
+
|
|
429
|
+
- A handful of languages have a vocab and a font but no public frequency list
|
|
430
|
+
(e.g. Burmese `my`, Odia `or`). They render correctly and their full character
|
|
431
|
+
set is still guaranteed through synthesised coverage tokens - you just won't
|
|
432
|
+
get a real-word corpus unless you supply your own via `wordlist_path`.
|
|
433
|
+
- For **recognition**, any of the 214 keys in ``VOCABS`` (e.g. `"german"`,
|
|
434
|
+
`"arabic"`, `"hindi"`) can be used as ``target_vocab`` / the ``vocab`` argument,
|
|
435
|
+
and several may be combined for a multilingual model
|
|
436
|
+
(`["german", "urdu", "odia"]`); every generated label is then restricted to
|
|
437
|
+
that exact character set so a docTR model trained on the matching vocab never
|
|
438
|
+
sees an un-encodable character (see the docTR training section).
|
|
439
|
+
|
|
382
440
|
## Vocabulary coverage (recognition)
|
|
383
441
|
|
|
384
442
|
A recognition model is trained against a fixed character set (docTR's `VOCABS`).
|
|
@@ -390,7 +448,7 @@ tokens are synthesised so **every renderable vocab character appears in both the
|
|
|
390
448
|
train and val splits**:
|
|
391
449
|
|
|
392
450
|
```python
|
|
393
|
-
config = GenerationConfig(
|
|
451
|
+
config = GenerationConfig.flat(
|
|
394
452
|
output_dir="dataset",
|
|
395
453
|
num_images=50000,
|
|
396
454
|
languages=["de"], # mapped to the "german" vocab automatically
|
|
@@ -430,7 +488,7 @@ polygon for every word, ready for
|
|
|
430
488
|
[docTR detection training](https://github.com/mindee/doctr/tree/main/references/detection):
|
|
431
489
|
|
|
432
490
|
```python
|
|
433
|
-
config = GenerationConfig(
|
|
491
|
+
config = GenerationConfig.flat(
|
|
434
492
|
task="detection",
|
|
435
493
|
output_dir="detection_dataset",
|
|
436
494
|
num_images=5000, # = number of pages
|
|
@@ -521,19 +579,16 @@ treat them the same: recognition yields the label string; detection yields
|
|
|
521
579
|
from generator.components import GenerationConfig
|
|
522
580
|
from generator.doctr_dataset import build_detection_datasets, synth_worker_init_fn
|
|
523
581
|
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
languages=["en", "de"],
|
|
527
|
-
num_images=50_000, # POOL size (word variety + vocab coverage)
|
|
528
|
-
auto_download_backgrounds=True,
|
|
529
|
-
)
|
|
582
|
+
# num_images is the total dataset size; val_percent carves out the val set.
|
|
583
|
+
cfg = GenerationConfig.flat(task="detection", num_images=50_000, val_percent=0.2)
|
|
530
584
|
train_set, val_set = build_detection_datasets(
|
|
531
585
|
cfg,
|
|
532
|
-
|
|
533
|
-
val_samples=2_000,
|
|
586
|
+
languages=["german", "english", "french", "italian", "spanish", "malay"], # VOCABS keys or ISO codes
|
|
534
587
|
use_polygons=args.rotation, # straight boxes unless --rotation
|
|
535
|
-
sample_transforms=
|
|
588
|
+
sample_transforms=sample_transforms, # the script's image+target transforms
|
|
589
|
+
img_transforms=img_transforms, # the script's image-only transforms
|
|
536
590
|
)
|
|
591
|
+
# len(train_set) == 40_000, len(val_set) == 10_000
|
|
537
592
|
```
|
|
538
593
|
|
|
539
594
|
**Recognition** - in `references/recognition/train.py`, replace the
|
|
@@ -543,15 +598,31 @@ train_set, val_set = build_detection_datasets(
|
|
|
543
598
|
from generator.components import GenerationConfig
|
|
544
599
|
from generator.doctr_dataset import build_recognition_datasets, synth_worker_init_fn
|
|
545
600
|
|
|
546
|
-
cfg = GenerationConfig(task="recognition",
|
|
601
|
+
cfg = GenerationConfig.flat(task="recognition", num_images=10_000, val_percent=0.2)
|
|
547
602
|
train_set, val_set = build_recognition_datasets(
|
|
548
603
|
cfg,
|
|
549
|
-
|
|
550
|
-
val_samples=5_000,
|
|
604
|
+
vocab=args.vocab, # e.g. ["multilingual"] - a VOCABS key / list = the model's vocab
|
|
551
605
|
img_transforms=img_transforms, # the script's existing resize/aug
|
|
552
606
|
)
|
|
607
|
+
# len(train_set) == 8_000, len(val_set) == 2_000
|
|
553
608
|
```
|
|
554
609
|
|
|
610
|
+
Pass `vocab` the **same vocab you train the model on** - a `VOCABS` key, a
|
|
611
|
+
literal charset, or a list of keys whose union is the model's vocab (e.g.
|
|
612
|
+
`["multilingual"]` or `["german", "urdu", "odia"]`). Every generated label is
|
|
613
|
+
then guaranteed to contain only characters in that vocab, so docTR's label
|
|
614
|
+
encoder never hits an out-of-vocab character (which would otherwise crash
|
|
615
|
+
training on the first batch). Corpus words outside the vocab are dropped,
|
|
616
|
+
character coverage is guaranteed *within* the vocab (missing characters are
|
|
617
|
+
synthesised so the set stays balanced), and the corpus languages are derived
|
|
618
|
+
from the vocab keys automatically (`german` -> `de`). For detection, pass
|
|
619
|
+
`languages=[...]` (VOCABS keys like `"german"`, `"malay"`, or ISO codes); for
|
|
620
|
+
recognition you can pass `languages=[...]` too. A combined vocab like
|
|
621
|
+
`"multilingual"` maps to no single language, so pass `languages=[...]` if you
|
|
622
|
+
want real multilingual words rather than mostly-synthesised coverage. The same
|
|
623
|
+
restriction applies to the offline generator via
|
|
624
|
+
`GenerationConfig.flat(target_vocab=[...])`.
|
|
625
|
+
|
|
555
626
|
The `DataLoader` lines stay as they are - just keep
|
|
556
627
|
`collate_fn=train_set.collate_fn` and add `worker_init_fn=synth_worker_init_fn`
|
|
557
628
|
so every worker gets an independent RNG stream:
|
|
@@ -571,10 +642,11 @@ train_loader = DataLoader(
|
|
|
571
642
|
|
|
572
643
|
Notes:
|
|
573
644
|
|
|
574
|
-
- **
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
645
|
+
- **Dataset size & split.** `num_images` is the total dataset size; `val_percent`
|
|
646
|
+
carves out the validation set, so `len(train_set)` / `len(val_set)` follow
|
|
647
|
+
directly (50k @ 0.2 -> 40k / 10k). Samples are generated fresh on every access,
|
|
648
|
+
so this is effectively the iterations per epoch. Pass `train_samples` /
|
|
649
|
+
`val_samples` only if you want to override the derived sizes.
|
|
578
650
|
- **Seeding.** The train set draws a fresh random sample on every access (new
|
|
579
651
|
data every epoch - the whole point of on-the-fly); the val set is a
|
|
580
652
|
reproducible fixed virtual set (seeded per index) so metrics stay comparable.
|
|
@@ -618,8 +690,33 @@ improvement over re-loading them per sample. Memory stays bounded and tunable:
|
|
|
618
690
|
|
|
619
691
|
## Configuration reference
|
|
620
692
|
|
|
621
|
-
|
|
622
|
-
|
|
693
|
+
The config is organised into focused sub-configs - `core`, `resources`,
|
|
694
|
+
`corpus`, `balance`, `coverage`, `recognition`, `realism` and `detection` -
|
|
695
|
+
each a small dataclass you can construct on its own. Build `GenerationConfig`
|
|
696
|
+
nested (`GenerationConfig(detection=DetectionConfig(layout="form"))`), or pass
|
|
697
|
+
flat keyword names via `GenerationConfig.flat(...)` / `generate_dataset(...)`,
|
|
698
|
+
which route each keyword into the right sub-config.
|
|
699
|
+
|
|
700
|
+
Most runs need only a handful of options - the ones you are most likely to set
|
|
701
|
+
(as flat keywords):
|
|
702
|
+
|
|
703
|
+
| Option | Sub-config | Default | What it does |
|
|
704
|
+
| --- | --- | --- | --- |
|
|
705
|
+
| `output_dir` | core | - | where the dataset is written (`train/`, `val/`) |
|
|
706
|
+
| `num_images` | core | `1000` | total samples (split by `val_percent`) |
|
|
707
|
+
| `task` | core | `"recognition"` | `"recognition"` crops or `"detection"` pages |
|
|
708
|
+
| `languages` | core | `["en"]` | ISO 639-1 codes; resolves words, fonts and shaping |
|
|
709
|
+
| `val_percent` | core | `0.2` | validation fraction |
|
|
710
|
+
| `num_workers` | core | `4` | parallel worker processes |
|
|
711
|
+
| `output_jpeg` | core | `False` | write JPEG instead of PNG |
|
|
712
|
+
| `target_vocab` | coverage | `None` | recognition: restrict labels to a `VOCABS` key / list (the `vocab=` arg) |
|
|
713
|
+
| `det_layout` | detection | `"mixed"` | detection: `mixed`/`paragraph`/`newspaper`/`form`/`id_card` |
|
|
714
|
+
| `language_balance` | balance | `"balanced"` | `"balanced"` or `"proportional"` allocation across languages |
|
|
715
|
+
| `min_char_coverage` | balance | `0` | ensure every character appears >= N times (0 = off) |
|
|
716
|
+
| `wordlist_path` / `font_dir` / `bg_image_dir` | resources | `None` | bring your own resources (skips the matching download) |
|
|
717
|
+
|
|
718
|
+
For the complete set of options (realism, augmentation and detection-layout
|
|
719
|
+
knobs), see the sub-config dataclasses in `generator/components/config.py`.
|
|
623
720
|
|
|
624
721
|
## Resources
|
|
625
722
|
|