doctr-synth-generator 0.3.0__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.3.0 → doctr_synth_generator-0.3.1}/PKG-INFO +28 -27
- {doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/README.md +27 -26
- {doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/doctr_synth_generator.egg-info/PKG-INFO +28 -27
- {doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/generator/dataset_generator.py +11 -0
- {doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/generator/doctr_dataset.py +71 -42
- doctr_synth_generator-0.3.1/generator/version.py +1 -0
- {doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/scripts/generate_grid.py +6 -1
- {doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/setup.py +1 -1
- doctr_synth_generator-0.3.0/generator/version.py +0 -1
- {doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/LICENSE +0 -0
- {doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/doctr_synth_generator.egg-info/SOURCES.txt +0 -0
- {doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/doctr_synth_generator.egg-info/dependency_links.txt +0 -0
- {doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/doctr_synth_generator.egg-info/entry_points.txt +0 -0
- {doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/doctr_synth_generator.egg-info/requires.txt +0 -0
- {doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/doctr_synth_generator.egg-info/top_level.txt +0 -0
- {doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/doctr_synth_generator.egg-info/zip-safe +0 -0
- {doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/generator/__init__.py +0 -0
- {doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/generator/__main__.py +0 -0
- {doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/generator/api.py +0 -0
- {doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/generator/augmentations/__init__.py +0 -0
- {doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/generator/augmentations/augmentation_pipeline.py +0 -0
- {doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/generator/augmentations/random_blur.py +0 -0
- {doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/generator/augmentations/random_gaussian_noise.py +0 -0
- {doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/generator/augmentations/random_jpeg_compression.py +0 -0
- {doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/generator/augmentations/random_perspective.py +0 -0
- {doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/generator/augmentations/random_pixel_dropout.py +0 -0
- {doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/generator/augmentations/random_rotate.py +0 -0
- {doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/generator/components/__init__.py +0 -0
- {doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/generator/components/background_downloader.py +0 -0
- {doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/generator/components/background_manager.py +0 -0
- {doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/generator/components/config.py +0 -0
- {doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/generator/components/corpus_downloader.py +0 -0
- {doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/generator/components/dataset_balancer.py +0 -0
- {doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/generator/components/dataset_splitter.py +0 -0
- {doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/generator/components/font_downloader.py +0 -0
- {doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/generator/components/font_selector.py +0 -0
- {doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/generator/components/generator.py +0 -0
- {doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/generator/components/page_generator.py +0 -0
- {doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/generator/components/text_renderer.py +0 -0
- {doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/generator/components/text_styling.py +0 -0
- {doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/generator/components/vocab_coverage.py +0 -0
- {doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/generator/components/vocabs.py +0 -0
- {doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/pyproject.toml +0 -0
- {doctr_synth_generator-0.3.0 → 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.
|
|
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,7 +250,7 @@ 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
|
|
@@ -579,19 +579,16 @@ treat them the same: recognition yields the label string; detection yields
|
|
|
579
579
|
from generator.components import GenerationConfig
|
|
580
580
|
from generator.doctr_dataset import build_detection_datasets, synth_worker_init_fn
|
|
581
581
|
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
languages=["en", "de"],
|
|
585
|
-
num_images=50_000, # POOL size (word variety + vocab coverage)
|
|
586
|
-
auto_download_backgrounds=True,
|
|
587
|
-
)
|
|
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)
|
|
588
584
|
train_set, val_set = build_detection_datasets(
|
|
589
585
|
cfg,
|
|
590
|
-
|
|
591
|
-
val_samples=2_000,
|
|
586
|
+
languages=["german", "english", "french", "italian", "spanish", "malay"], # VOCABS keys or ISO codes
|
|
592
587
|
use_polygons=args.rotation, # straight boxes unless --rotation
|
|
593
|
-
sample_transforms=
|
|
588
|
+
sample_transforms=sample_transforms, # the script's image+target transforms
|
|
589
|
+
img_transforms=img_transforms, # the script's image-only transforms
|
|
594
590
|
)
|
|
591
|
+
# len(train_set) == 40_000, len(val_set) == 10_000
|
|
595
592
|
```
|
|
596
593
|
|
|
597
594
|
**Recognition** - in `references/recognition/train.py`, replace the
|
|
@@ -601,26 +598,29 @@ train_set, val_set = build_detection_datasets(
|
|
|
601
598
|
from generator.components import GenerationConfig
|
|
602
599
|
from generator.doctr_dataset import build_recognition_datasets, synth_worker_init_fn
|
|
603
600
|
|
|
604
|
-
cfg = GenerationConfig.flat(task="recognition", num_images=
|
|
601
|
+
cfg = GenerationConfig.flat(task="recognition", num_images=10_000, val_percent=0.2)
|
|
605
602
|
train_set, val_set = build_recognition_datasets(
|
|
606
603
|
cfg,
|
|
607
|
-
|
|
608
|
-
val_samples=5_000,
|
|
609
|
-
vocab=args.vocab, # e.g. ["german", "urdu", "odia"] - the model's vocab
|
|
604
|
+
vocab=args.vocab, # e.g. ["multilingual"] - a VOCABS key / list = the model's vocab
|
|
610
605
|
img_transforms=img_transforms, # the script's existing resize/aug
|
|
611
606
|
)
|
|
607
|
+
# len(train_set) == 8_000, len(val_set) == 2_000
|
|
612
608
|
```
|
|
613
609
|
|
|
614
610
|
Pass `vocab` the **same vocab you train the model on** - a `VOCABS` key, a
|
|
615
611
|
literal charset, or a list of keys whose union is the model's vocab (e.g.
|
|
616
|
-
`["german", "urdu", "odia"]`). Every generated label is
|
|
617
|
-
contain only characters in that vocab, so docTR's label
|
|
618
|
-
out-of-vocab character (which would otherwise crash
|
|
619
|
-
Corpus words outside the vocab are dropped,
|
|
620
|
-
*within* the vocab
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
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
624
|
`GenerationConfig.flat(target_vocab=[...])`.
|
|
625
625
|
|
|
626
626
|
The `DataLoader` lines stay as they are - just keep
|
|
@@ -642,10 +642,11 @@ train_loader = DataLoader(
|
|
|
642
642
|
|
|
643
643
|
Notes:
|
|
644
644
|
|
|
645
|
-
- **
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
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.
|
|
649
650
|
- **Seeding.** The train set draws a fresh random sample on every access (new
|
|
650
651
|
data every epoch - the whole point of on-the-fly); the val set is a
|
|
651
652
|
reproducible fixed virtual set (seeded per index) so metrics stay comparable.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|

|
|
3
3
|
[](https://codecov.io/gh/felixdittrich92/docTR-Synth-Generator)
|
|
4
4
|
[](https://www.codefactor.io/repository/github/felixdittrich92/doctr-synth-generator)
|
|
5
|
-
[](https://pypi.org/project/docTR-Synth-Generator/)
|
|
6
6
|
|
|
7
7
|
# docTR-Synth-Generator
|
|
8
8
|
A tool to generate synthetic OCR datasets - made for docTR
|
|
@@ -331,19 +331,16 @@ treat them the same: recognition yields the label string; detection yields
|
|
|
331
331
|
from generator.components import GenerationConfig
|
|
332
332
|
from generator.doctr_dataset import build_detection_datasets, synth_worker_init_fn
|
|
333
333
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
languages=["en", "de"],
|
|
337
|
-
num_images=50_000, # POOL size (word variety + vocab coverage)
|
|
338
|
-
auto_download_backgrounds=True,
|
|
339
|
-
)
|
|
334
|
+
# num_images is the total dataset size; val_percent carves out the val set.
|
|
335
|
+
cfg = GenerationConfig.flat(task="detection", num_images=50_000, val_percent=0.2)
|
|
340
336
|
train_set, val_set = build_detection_datasets(
|
|
341
337
|
cfg,
|
|
342
|
-
|
|
343
|
-
val_samples=2_000,
|
|
338
|
+
languages=["german", "english", "french", "italian", "spanish", "malay"], # VOCABS keys or ISO codes
|
|
344
339
|
use_polygons=args.rotation, # straight boxes unless --rotation
|
|
345
|
-
sample_transforms=
|
|
340
|
+
sample_transforms=sample_transforms, # the script's image+target transforms
|
|
341
|
+
img_transforms=img_transforms, # the script's image-only transforms
|
|
346
342
|
)
|
|
343
|
+
# len(train_set) == 40_000, len(val_set) == 10_000
|
|
347
344
|
```
|
|
348
345
|
|
|
349
346
|
**Recognition** - in `references/recognition/train.py`, replace the
|
|
@@ -353,26 +350,29 @@ train_set, val_set = build_detection_datasets(
|
|
|
353
350
|
from generator.components import GenerationConfig
|
|
354
351
|
from generator.doctr_dataset import build_recognition_datasets, synth_worker_init_fn
|
|
355
352
|
|
|
356
|
-
cfg = GenerationConfig.flat(task="recognition", num_images=
|
|
353
|
+
cfg = GenerationConfig.flat(task="recognition", num_images=10_000, val_percent=0.2)
|
|
357
354
|
train_set, val_set = build_recognition_datasets(
|
|
358
355
|
cfg,
|
|
359
|
-
|
|
360
|
-
val_samples=5_000,
|
|
361
|
-
vocab=args.vocab, # e.g. ["german", "urdu", "odia"] - the model's vocab
|
|
356
|
+
vocab=args.vocab, # e.g. ["multilingual"] - a VOCABS key / list = the model's vocab
|
|
362
357
|
img_transforms=img_transforms, # the script's existing resize/aug
|
|
363
358
|
)
|
|
359
|
+
# len(train_set) == 8_000, len(val_set) == 2_000
|
|
364
360
|
```
|
|
365
361
|
|
|
366
362
|
Pass `vocab` the **same vocab you train the model on** - a `VOCABS` key, a
|
|
367
363
|
literal charset, or a list of keys whose union is the model's vocab (e.g.
|
|
368
|
-
`["german", "urdu", "odia"]`). Every generated label is
|
|
369
|
-
contain only characters in that vocab, so docTR's label
|
|
370
|
-
out-of-vocab character (which would otherwise crash
|
|
371
|
-
Corpus words outside the vocab are dropped,
|
|
372
|
-
*within* the vocab
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
364
|
+
`["multilingual"]` or `["german", "urdu", "odia"]`). Every generated label is
|
|
365
|
+
then guaranteed to contain only characters in that vocab, so docTR's label
|
|
366
|
+
encoder never hits an out-of-vocab character (which would otherwise crash
|
|
367
|
+
training on the first batch). Corpus words outside the vocab are dropped,
|
|
368
|
+
character coverage is guaranteed *within* the vocab (missing characters are
|
|
369
|
+
synthesised so the set stays balanced), and the corpus languages are derived
|
|
370
|
+
from the vocab keys automatically (`german` -> `de`). For detection, pass
|
|
371
|
+
`languages=[...]` (VOCABS keys like `"german"`, `"malay"`, or ISO codes); for
|
|
372
|
+
recognition you can pass `languages=[...]` too. A combined vocab like
|
|
373
|
+
`"multilingual"` maps to no single language, so pass `languages=[...]` if you
|
|
374
|
+
want real multilingual words rather than mostly-synthesised coverage. The same
|
|
375
|
+
restriction applies to the offline generator via
|
|
376
376
|
`GenerationConfig.flat(target_vocab=[...])`.
|
|
377
377
|
|
|
378
378
|
The `DataLoader` lines stay as they are - just keep
|
|
@@ -394,10 +394,11 @@ train_loader = DataLoader(
|
|
|
394
394
|
|
|
395
395
|
Notes:
|
|
396
396
|
|
|
397
|
-
- **
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
397
|
+
- **Dataset size & split.** `num_images` is the total dataset size; `val_percent`
|
|
398
|
+
carves out the validation set, so `len(train_set)` / `len(val_set)` follow
|
|
399
|
+
directly (50k @ 0.2 -> 40k / 10k). Samples are generated fresh on every access,
|
|
400
|
+
so this is effectively the iterations per epoch. Pass `train_samples` /
|
|
401
|
+
`val_samples` only if you want to override the derived sizes.
|
|
401
402
|
- **Seeding.** The train set draws a fresh random sample on every access (new
|
|
402
403
|
data every epoch - the whole point of on-the-fly); the val set is a
|
|
403
404
|
reproducible fixed virtual set (seeded per index) so metrics stay comparable.
|
{doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/doctr_synth_generator.egg-info/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: doctr-synth-generator
|
|
3
|
-
Version: 0.3.
|
|
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,7 +250,7 @@ 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
|
|
@@ -579,19 +579,16 @@ treat them the same: recognition yields the label string; detection yields
|
|
|
579
579
|
from generator.components import GenerationConfig
|
|
580
580
|
from generator.doctr_dataset import build_detection_datasets, synth_worker_init_fn
|
|
581
581
|
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
languages=["en", "de"],
|
|
585
|
-
num_images=50_000, # POOL size (word variety + vocab coverage)
|
|
586
|
-
auto_download_backgrounds=True,
|
|
587
|
-
)
|
|
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)
|
|
588
584
|
train_set, val_set = build_detection_datasets(
|
|
589
585
|
cfg,
|
|
590
|
-
|
|
591
|
-
val_samples=2_000,
|
|
586
|
+
languages=["german", "english", "french", "italian", "spanish", "malay"], # VOCABS keys or ISO codes
|
|
592
587
|
use_polygons=args.rotation, # straight boxes unless --rotation
|
|
593
|
-
sample_transforms=
|
|
588
|
+
sample_transforms=sample_transforms, # the script's image+target transforms
|
|
589
|
+
img_transforms=img_transforms, # the script's image-only transforms
|
|
594
590
|
)
|
|
591
|
+
# len(train_set) == 40_000, len(val_set) == 10_000
|
|
595
592
|
```
|
|
596
593
|
|
|
597
594
|
**Recognition** - in `references/recognition/train.py`, replace the
|
|
@@ -601,26 +598,29 @@ train_set, val_set = build_detection_datasets(
|
|
|
601
598
|
from generator.components import GenerationConfig
|
|
602
599
|
from generator.doctr_dataset import build_recognition_datasets, synth_worker_init_fn
|
|
603
600
|
|
|
604
|
-
cfg = GenerationConfig.flat(task="recognition", num_images=
|
|
601
|
+
cfg = GenerationConfig.flat(task="recognition", num_images=10_000, val_percent=0.2)
|
|
605
602
|
train_set, val_set = build_recognition_datasets(
|
|
606
603
|
cfg,
|
|
607
|
-
|
|
608
|
-
val_samples=5_000,
|
|
609
|
-
vocab=args.vocab, # e.g. ["german", "urdu", "odia"] - the model's vocab
|
|
604
|
+
vocab=args.vocab, # e.g. ["multilingual"] - a VOCABS key / list = the model's vocab
|
|
610
605
|
img_transforms=img_transforms, # the script's existing resize/aug
|
|
611
606
|
)
|
|
607
|
+
# len(train_set) == 8_000, len(val_set) == 2_000
|
|
612
608
|
```
|
|
613
609
|
|
|
614
610
|
Pass `vocab` the **same vocab you train the model on** - a `VOCABS` key, a
|
|
615
611
|
literal charset, or a list of keys whose union is the model's vocab (e.g.
|
|
616
|
-
`["german", "urdu", "odia"]`). Every generated label is
|
|
617
|
-
contain only characters in that vocab, so docTR's label
|
|
618
|
-
out-of-vocab character (which would otherwise crash
|
|
619
|
-
Corpus words outside the vocab are dropped,
|
|
620
|
-
*within* the vocab
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
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
624
|
`GenerationConfig.flat(target_vocab=[...])`.
|
|
625
625
|
|
|
626
626
|
The `DataLoader` lines stay as they are - just keep
|
|
@@ -642,10 +642,11 @@ train_loader = DataLoader(
|
|
|
642
642
|
|
|
643
643
|
Notes:
|
|
644
644
|
|
|
645
|
-
- **
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
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.
|
|
649
650
|
- **Seeding.** The train set draws a fresh random sample on every access (new
|
|
650
651
|
data every epoch - the whole point of on-the-fly); the val set is a
|
|
651
652
|
reproducible fixed virtual set (seeded per index) so metrics stay comparable.
|
|
@@ -172,6 +172,7 @@ class SyntheticDatasetGenerator:
|
|
|
172
172
|
reproduces the same balance and per-split character coverage without
|
|
173
173
|
ever touching disk. ``config.core.num_images`` controls the pool size.
|
|
174
174
|
"""
|
|
175
|
+
self._resolve_background_dir() # so on-the-fly crops get real (downloaded) backgrounds
|
|
175
176
|
return self._prepare_train_val()
|
|
176
177
|
|
|
177
178
|
def build_detection_pool(self) -> list[str]:
|
|
@@ -184,6 +185,16 @@ class SyntheticDatasetGenerator:
|
|
|
184
185
|
self._resolve_background_dir()
|
|
185
186
|
return self._resolve_word_pool()
|
|
186
187
|
|
|
188
|
+
def resolve_backgrounds(self) -> str | None:
|
|
189
|
+
"""Resolve (downloading if needed) the background dir and return it.
|
|
190
|
+
|
|
191
|
+
Mutates ``config.resources.bg_image_dir`` to the resolved directory.
|
|
192
|
+
Useful when rendering pages directly via ``PageGenerator`` instead of
|
|
193
|
+
going through :meth:`generate_dataset` or the dataset factories.
|
|
194
|
+
"""
|
|
195
|
+
self._resolve_background_dir()
|
|
196
|
+
return self.config.resources.bg_image_dir
|
|
197
|
+
|
|
187
198
|
def _vocab_charset(self) -> set[str] | None:
|
|
188
199
|
"""Characters recognition labels must stay within (the model's vocab).
|
|
189
200
|
|
|
@@ -8,7 +8,6 @@ from __future__ import annotations
|
|
|
8
8
|
import os
|
|
9
9
|
import random
|
|
10
10
|
import time
|
|
11
|
-
import warnings
|
|
12
11
|
from dataclasses import replace
|
|
13
12
|
from typing import Any, Callable
|
|
14
13
|
|
|
@@ -321,58 +320,76 @@ class SyntheticDetectionDataset(_BaseSynthDataset):
|
|
|
321
320
|
# --------------------------------------------------------------------------- #
|
|
322
321
|
# Convenience factories: build matched (train, val) datasets in one call.
|
|
323
322
|
# --------------------------------------------------------------------------- #
|
|
323
|
+
def _to_corpus_languages(languages: list[str]) -> list[str]:
|
|
324
|
+
"""Map human-readable VOCABS keys (``"german"``) to corpus ISO codes (``"de"``).
|
|
325
|
+
|
|
326
|
+
Anything already an ISO code (or unknown) is passed through unchanged.
|
|
327
|
+
"""
|
|
328
|
+
return [VOCAB_TO_LANGUAGE.get(lang, lang) for lang in languages]
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
def _split_sizes(config: GenerationConfig, train_samples: int | None, val_samples: int | None) -> tuple[int, int]:
|
|
332
|
+
"""Per-epoch ``(train, val)`` sizes derived from ``num_images`` and ``val_percent``.
|
|
333
|
+
|
|
334
|
+
Explicit ``train_samples`` / ``val_samples`` override the derived values.
|
|
335
|
+
"""
|
|
336
|
+
total = max(1, int(config.core.num_images))
|
|
337
|
+
val = val_samples if val_samples is not None else max(1, round(total * config.core.val_percent))
|
|
338
|
+
train = train_samples if train_samples is not None else max(1, total - round(total * config.core.val_percent))
|
|
339
|
+
return int(train), int(val)
|
|
340
|
+
|
|
341
|
+
|
|
324
342
|
def build_recognition_datasets(
|
|
325
343
|
config: GenerationConfig,
|
|
326
344
|
*,
|
|
327
|
-
train_samples: int,
|
|
328
|
-
val_samples: int,
|
|
329
345
|
vocab: str | list[str] | None = None,
|
|
346
|
+
languages: list[str] | None = None,
|
|
330
347
|
img_transforms: Callable | None = None,
|
|
331
348
|
sample_transforms: Callable | None = None,
|
|
349
|
+
train_samples: int | None = None,
|
|
350
|
+
val_samples: int | None = None,
|
|
332
351
|
val_seed: int = 1234,
|
|
333
352
|
) -> tuple[SyntheticRecognitionDataset, SyntheticRecognitionDataset]:
|
|
334
|
-
"""Build ``(train, val)`` on-the-fly recognition datasets
|
|
353
|
+
"""Build ``(train, val)`` on-the-fly recognition datasets from a config.
|
|
335
354
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
``
|
|
339
|
-
|
|
355
|
+
Sizes come straight from the config: ``num_images`` total, split into
|
|
356
|
+
``len(train)`` / ``len(val)`` by ``val_percent`` (override with the optional
|
|
357
|
+
``train_samples`` / ``val_samples``). The train set draws fresh crops every
|
|
358
|
+
access; the val set is reproducible. Words, fonts and (any) backgrounds are
|
|
359
|
+
downloaded/cached once in the parent process.
|
|
340
360
|
|
|
341
361
|
Pass ``vocab`` to pin the docTR vocab to train against - a ``VOCABS`` key, a
|
|
342
|
-
literal charset, or a list such as ``["german", "urdu"
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
``--vocab`` never hits
|
|
346
|
-
|
|
347
|
-
|
|
362
|
+
literal charset, or a list such as ``["german", "urdu"]`` (their union).
|
|
363
|
+
Every label is restricted to that character set, and characters missing from
|
|
364
|
+
the corpus are synthesised so coverage stays balanced - a model trained on
|
|
365
|
+
the matching ``--vocab`` never hits an un-encodable label.
|
|
366
|
+
|
|
367
|
+
Corpus languages come from ``languages`` (ISO codes or VOCABS keys) when
|
|
368
|
+
given, else the language(s) the ``vocab`` keys map to, else
|
|
369
|
+
``config.core.languages``. Combined vocabs such as ``"multilingual"`` have no
|
|
370
|
+
single language, so pass ``languages=[...]`` for real multilingual words
|
|
371
|
+
rather than mostly-synthesised coverage.
|
|
348
372
|
"""
|
|
349
|
-
if
|
|
373
|
+
if languages is not None:
|
|
374
|
+
langs = _to_corpus_languages(languages)
|
|
375
|
+
elif vocab is not None:
|
|
350
376
|
keys = [vocab] if isinstance(vocab, str) else list(vocab)
|
|
351
377
|
derived = [VOCAB_TO_LANGUAGE[k] for k in keys if k in VOCAB_TO_LANGUAGE]
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
user_chose = bool(config.core.languages) and list(config.core.languages) != ["en"] # type: ignore[arg-type]
|
|
356
|
-
languages = list(config.core.languages) if user_chose else (derived or config.core.languages) # type: ignore[arg-type]
|
|
357
|
-
if unmapped and not user_chose:
|
|
358
|
-
warnings.warn(
|
|
359
|
-
f"No corpus language mapping for vocab key(s) {unmapped}; their characters "
|
|
360
|
-
"will still be covered via synthesis, but pass an explicit `languages=[...]` "
|
|
361
|
-
"on the config to also pull real words for them.",
|
|
362
|
-
stacklevel=2,
|
|
363
|
-
)
|
|
364
|
-
config = replace(
|
|
365
|
-
config,
|
|
366
|
-
core=replace(config.core, languages=languages),
|
|
367
|
-
coverage=replace(config.coverage, target_vocab=vocab, restrict_to_vocab=True),
|
|
368
|
-
)
|
|
378
|
+
langs = derived or list(config.core.languages or ["en"])
|
|
379
|
+
else:
|
|
380
|
+
langs = list(config.core.languages or ["en"])
|
|
369
381
|
|
|
382
|
+
config = replace(config, core=replace(config.core, languages=langs))
|
|
383
|
+
if vocab is not None:
|
|
384
|
+
config = replace(config, coverage=replace(config.coverage, target_vocab=vocab, restrict_to_vocab=True))
|
|
385
|
+
|
|
386
|
+
train_n, val_n = _split_sizes(config, train_samples, val_samples)
|
|
370
387
|
pipeline = SyntheticDatasetGenerator(config)
|
|
371
388
|
train_pool, val_pool = pipeline.build_recognition_pools()
|
|
372
389
|
train_set = SyntheticRecognitionDataset(
|
|
373
390
|
train_pool,
|
|
374
391
|
config,
|
|
375
|
-
|
|
392
|
+
train_n,
|
|
376
393
|
vocab=vocab,
|
|
377
394
|
img_transforms=img_transforms,
|
|
378
395
|
sample_transforms=sample_transforms,
|
|
@@ -381,7 +398,7 @@ def build_recognition_datasets(
|
|
|
381
398
|
val_set = SyntheticRecognitionDataset(
|
|
382
399
|
val_pool,
|
|
383
400
|
config,
|
|
384
|
-
|
|
401
|
+
val_n,
|
|
385
402
|
vocab=vocab,
|
|
386
403
|
img_transforms=img_transforms,
|
|
387
404
|
sample_transforms=sample_transforms,
|
|
@@ -393,24 +410,36 @@ def build_recognition_datasets(
|
|
|
393
410
|
def build_detection_datasets(
|
|
394
411
|
config: GenerationConfig,
|
|
395
412
|
*,
|
|
396
|
-
|
|
397
|
-
val_samples: int,
|
|
413
|
+
languages: list[str] | None = None,
|
|
398
414
|
use_polygons: bool = False,
|
|
399
415
|
img_transforms: Callable | None = None,
|
|
400
416
|
sample_transforms: Callable | None = None,
|
|
417
|
+
train_samples: int | None = None,
|
|
418
|
+
val_samples: int | None = None,
|
|
401
419
|
val_seed: int = 1234,
|
|
402
420
|
) -> tuple[SyntheticDetectionDataset, SyntheticDetectionDataset]:
|
|
403
|
-
"""Build ``(train, val)`` on-the-fly detection datasets
|
|
421
|
+
"""Build ``(train, val)`` on-the-fly detection datasets from a config.
|
|
422
|
+
|
|
423
|
+
Like :func:`build_recognition_datasets`, sizes come from the config
|
|
424
|
+
(``num_images`` total, split by ``val_percent``; override with
|
|
425
|
+
``train_samples`` / ``val_samples``). Backgrounds, words and fonts are
|
|
426
|
+
downloaded/cached once in the parent process, so auto-download just works.
|
|
404
427
|
|
|
405
|
-
|
|
406
|
-
|
|
428
|
+
``languages`` accepts ISO codes or VOCABS keys (e.g. ``"german"``,
|
|
429
|
+
``"english"``, ``"malay"``); when omitted ``config.core.languages`` is used.
|
|
430
|
+
Set ``use_polygons=True`` to keep rotated quads (matches the training
|
|
431
|
+
script's ``--rotation`` flag); otherwise axis-aligned boxes are returned.
|
|
407
432
|
"""
|
|
433
|
+
if languages is not None:
|
|
434
|
+
config = replace(config, core=replace(config.core, languages=_to_corpus_languages(languages)))
|
|
435
|
+
|
|
436
|
+
train_n, val_n = _split_sizes(config, train_samples, val_samples)
|
|
408
437
|
pipeline = SyntheticDatasetGenerator(config)
|
|
409
|
-
pool = pipeline.build_detection_pool()
|
|
438
|
+
pool = pipeline.build_detection_pool() # resolves backgrounds + builds the word pool
|
|
410
439
|
train_set = SyntheticDetectionDataset(
|
|
411
440
|
pool,
|
|
412
441
|
config,
|
|
413
|
-
|
|
442
|
+
train_n,
|
|
414
443
|
use_polygons=use_polygons,
|
|
415
444
|
img_transforms=img_transforms,
|
|
416
445
|
sample_transforms=sample_transforms,
|
|
@@ -419,7 +448,7 @@ def build_detection_datasets(
|
|
|
419
448
|
val_set = SyntheticDetectionDataset(
|
|
420
449
|
pool,
|
|
421
450
|
config,
|
|
422
|
-
|
|
451
|
+
val_n,
|
|
423
452
|
use_polygons=use_polygons,
|
|
424
453
|
img_transforms=img_transforms,
|
|
425
454
|
sample_transforms=sample_transforms,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = '0.3.1'
|
|
@@ -104,7 +104,12 @@ def recognition_crop(corpus, languages, seed, bg_dir=None):
|
|
|
104
104
|
words = corpus.build_vocabulary(languages, words_per_language=6000)
|
|
105
105
|
gen = TextImageGenerator(
|
|
106
106
|
GenerationConfig.flat(
|
|
107
|
-
task="recognition",
|
|
107
|
+
task="recognition",
|
|
108
|
+
languages=languages,
|
|
109
|
+
auto_download_fonts=True,
|
|
110
|
+
auto_download_backgrounds=False,
|
|
111
|
+
bg_image_dir=bg_dir,
|
|
112
|
+
**CACHE,
|
|
108
113
|
)
|
|
109
114
|
)
|
|
110
115
|
random.seed(seed * 13)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = '0.3.0'
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/doctr_synth_generator.egg-info/zip-safe
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/generator/augmentations/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/generator/augmentations/random_blur.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/generator/augmentations/random_rotate.py
RENAMED
|
File without changes
|
{doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/generator/components/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/generator/components/dataset_balancer.py
RENAMED
|
File without changes
|
{doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/generator/components/dataset_splitter.py
RENAMED
|
File without changes
|
{doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/generator/components/font_downloader.py
RENAMED
|
File without changes
|
{doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/generator/components/font_selector.py
RENAMED
|
File without changes
|
{doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/generator/components/generator.py
RENAMED
|
File without changes
|
{doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/generator/components/page_generator.py
RENAMED
|
File without changes
|
{doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/generator/components/text_renderer.py
RENAMED
|
File without changes
|
{doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/generator/components/text_styling.py
RENAMED
|
File without changes
|
{doctr_synth_generator-0.3.0 → doctr_synth_generator-0.3.1}/generator/components/vocab_coverage.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|