python-doctr 0.10.0__tar.gz → 0.11.0__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.
- {python_doctr-0.10.0 → python_doctr-0.11.0}/PKG-INFO +22 -20
- {python_doctr-0.10.0 → python_doctr-0.11.0}/README.md +14 -14
- python_doctr-0.11.0/doctr/contrib/__init__.py +1 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/contrib/artefacts.py +7 -9
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/contrib/base.py +8 -17
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/datasets/cord.py +8 -7
- python_doctr-0.11.0/doctr/datasets/datasets/__init__.py +6 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/datasets/datasets/base.py +16 -16
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/datasets/datasets/pytorch.py +12 -12
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/datasets/datasets/tensorflow.py +10 -10
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/datasets/detection.py +6 -9
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/datasets/doc_artefacts.py +3 -4
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/datasets/funsd.py +7 -6
- python_doctr-0.11.0/doctr/datasets/generator/__init__.py +6 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/datasets/generator/base.py +16 -17
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/datasets/generator/pytorch.py +1 -3
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/datasets/generator/tensorflow.py +1 -3
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/datasets/ic03.py +4 -5
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/datasets/ic13.py +4 -5
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/datasets/iiit5k.py +6 -5
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/datasets/iiithws.py +4 -5
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/datasets/imgur5k.py +6 -5
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/datasets/loader.py +4 -7
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/datasets/mjsynth.py +6 -5
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/datasets/ocr.py +3 -4
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/datasets/orientation.py +3 -4
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/datasets/recognition.py +3 -4
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/datasets/sroie.py +6 -5
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/datasets/svhn.py +6 -5
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/datasets/svt.py +4 -5
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/datasets/synthtext.py +4 -5
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/datasets/utils.py +34 -29
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/datasets/vocabs.py +17 -7
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/datasets/wildreceipt.py +14 -10
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/file_utils.py +2 -7
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/io/elements.py +59 -79
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/io/html.py +1 -3
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/io/image/__init__.py +3 -3
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/io/image/base.py +2 -5
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/io/image/pytorch.py +3 -12
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/io/image/tensorflow.py +2 -11
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/io/pdf.py +5 -7
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/io/reader.py +5 -11
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/_utils.py +14 -22
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/builder.py +30 -48
- {python_doctr-0.10.0/doctr/models/classification/mobilenet → python_doctr-0.11.0/doctr/models/classification/magc_resnet}/__init__.py +3 -3
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/classification/magc_resnet/pytorch.py +10 -13
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/classification/magc_resnet/tensorflow.py +8 -11
- {python_doctr-0.10.0/doctr/models/classification/vgg → python_doctr-0.11.0/doctr/models/classification/mobilenet}/__init__.py +3 -3
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/classification/mobilenet/pytorch.py +5 -17
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/classification/mobilenet/tensorflow.py +8 -21
- python_doctr-0.11.0/doctr/models/classification/predictor/__init__.py +6 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/classification/predictor/pytorch.py +6 -8
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/classification/predictor/tensorflow.py +6 -8
- python_doctr-0.11.0/doctr/models/classification/resnet/__init__.py +6 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/classification/resnet/pytorch.py +21 -31
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/classification/resnet/tensorflow.py +20 -31
- {python_doctr-0.10.0/doctr/transforms/functional → python_doctr-0.11.0/doctr/models/classification/textnet}/__init__.py +3 -3
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/classification/textnet/pytorch.py +10 -17
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/classification/textnet/tensorflow.py +8 -15
- python_doctr-0.11.0/doctr/models/classification/vgg/__init__.py +6 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/classification/vgg/pytorch.py +5 -7
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/classification/vgg/tensorflow.py +9 -12
- python_doctr-0.11.0/doctr/models/classification/vit/__init__.py +6 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/classification/vit/pytorch.py +8 -14
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/classification/vit/tensorflow.py +6 -12
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/classification/zoo.py +19 -14
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/core.py +3 -3
- python_doctr-0.11.0/doctr/models/detection/_utils/__init__.py +7 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/detection/_utils/base.py +4 -7
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/detection/_utils/pytorch.py +1 -5
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/detection/_utils/tensorflow.py +1 -5
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/detection/core.py +2 -8
- python_doctr-0.11.0/doctr/models/detection/differentiable_binarization/__init__.py +6 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/detection/differentiable_binarization/base.py +7 -17
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/detection/differentiable_binarization/pytorch.py +27 -30
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/detection/differentiable_binarization/tensorflow.py +15 -25
- python_doctr-0.11.0/doctr/models/detection/fast/__init__.py +6 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/detection/fast/base.py +6 -14
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/detection/fast/pytorch.py +24 -31
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/detection/fast/tensorflow.py +14 -26
- python_doctr-0.11.0/doctr/models/detection/linknet/__init__.py +6 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/detection/linknet/base.py +6 -15
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/detection/linknet/pytorch.py +24 -27
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/detection/linknet/tensorflow.py +14 -23
- python_doctr-0.11.0/doctr/models/detection/predictor/__init__.py +6 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/detection/predictor/pytorch.py +6 -7
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/detection/predictor/tensorflow.py +5 -6
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/detection/zoo.py +27 -7
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/factory/hub.py +3 -7
- python_doctr-0.11.0/doctr/models/kie_predictor/__init__.py +6 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/kie_predictor/base.py +4 -5
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/kie_predictor/pytorch.py +18 -19
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/kie_predictor/tensorflow.py +13 -14
- python_doctr-0.11.0/doctr/models/modules/layers/__init__.py +6 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/modules/layers/pytorch.py +6 -9
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/modules/layers/tensorflow.py +5 -7
- python_doctr-0.11.0/doctr/models/modules/transformer/__init__.py +6 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/modules/transformer/pytorch.py +12 -13
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/modules/transformer/tensorflow.py +9 -10
- python_doctr-0.11.0/doctr/models/modules/vision_transformer/__init__.py +6 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/modules/vision_transformer/pytorch.py +2 -3
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/modules/vision_transformer/tensorflow.py +3 -3
- python_doctr-0.11.0/doctr/models/predictor/__init__.py +6 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/predictor/base.py +28 -29
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/predictor/pytorch.py +12 -13
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/predictor/tensorflow.py +8 -9
- python_doctr-0.11.0/doctr/models/preprocessor/__init__.py +6 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/preprocessor/pytorch.py +13 -17
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/preprocessor/tensorflow.py +10 -14
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/recognition/core.py +3 -7
- python_doctr-0.11.0/doctr/models/recognition/crnn/__init__.py +6 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/recognition/crnn/pytorch.py +20 -28
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/recognition/crnn/tensorflow.py +11 -23
- python_doctr-0.11.0/doctr/models/recognition/master/__init__.py +6 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/recognition/master/base.py +3 -7
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/recognition/master/pytorch.py +22 -24
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/recognition/master/tensorflow.py +12 -22
- python_doctr-0.11.0/doctr/models/recognition/parseq/__init__.py +6 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/recognition/parseq/base.py +3 -7
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/recognition/parseq/pytorch.py +26 -26
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/recognition/parseq/tensorflow.py +16 -22
- python_doctr-0.11.0/doctr/models/recognition/predictor/__init__.py +6 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/recognition/predictor/_utils.py +7 -10
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/recognition/predictor/pytorch.py +6 -6
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/recognition/predictor/tensorflow.py +5 -6
- python_doctr-0.11.0/doctr/models/recognition/sar/__init__.py +6 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/recognition/sar/pytorch.py +20 -21
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/recognition/sar/tensorflow.py +12 -21
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/recognition/utils.py +5 -10
- python_doctr-0.11.0/doctr/models/recognition/vitstr/__init__.py +6 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/recognition/vitstr/base.py +3 -7
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/recognition/vitstr/pytorch.py +18 -20
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/recognition/vitstr/tensorflow.py +12 -20
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/recognition/zoo.py +22 -11
- python_doctr-0.11.0/doctr/models/utils/__init__.py +6 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/utils/pytorch.py +14 -17
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/utils/tensorflow.py +17 -16
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/zoo.py +1 -5
- python_doctr-0.11.0/doctr/transforms/functional/__init__.py +6 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/transforms/functional/base.py +4 -11
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/transforms/functional/pytorch.py +20 -28
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/transforms/functional/tensorflow.py +10 -22
- python_doctr-0.11.0/doctr/transforms/modules/__init__.py +8 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/transforms/modules/base.py +48 -55
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/transforms/modules/pytorch.py +58 -22
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/transforms/modules/tensorflow.py +18 -32
- python_doctr-0.11.0/doctr/utils/common_types.py +17 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/utils/data.py +8 -12
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/utils/fonts.py +2 -7
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/utils/geometry.py +16 -47
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/utils/metrics.py +17 -37
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/utils/multithreading.py +4 -6
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/utils/reconstitution.py +9 -13
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/utils/repr.py +2 -3
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/utils/visualization.py +16 -29
- python_doctr-0.11.0/doctr/version.py +1 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/pyproject.toml +8 -6
- {python_doctr-0.10.0 → python_doctr-0.11.0}/python_doctr.egg-info/PKG-INFO +22 -20
- {python_doctr-0.10.0 → python_doctr-0.11.0}/python_doctr.egg-info/requires.txt +12 -2
- {python_doctr-0.10.0 → python_doctr-0.11.0}/setup.py +2 -2
- python_doctr-0.10.0/doctr/contrib/__init__.py +0 -0
- python_doctr-0.10.0/doctr/datasets/datasets/__init__.py +0 -6
- python_doctr-0.10.0/doctr/datasets/generator/__init__.py +0 -6
- python_doctr-0.10.0/doctr/models/classification/magc_resnet/__init__.py +0 -6
- python_doctr-0.10.0/doctr/models/classification/predictor/__init__.py +0 -6
- python_doctr-0.10.0/doctr/models/classification/resnet/__init__.py +0 -6
- python_doctr-0.10.0/doctr/models/classification/textnet/__init__.py +0 -6
- python_doctr-0.10.0/doctr/models/classification/vit/__init__.py +0 -6
- python_doctr-0.10.0/doctr/models/detection/_utils/__init__.py +0 -7
- python_doctr-0.10.0/doctr/models/detection/differentiable_binarization/__init__.py +0 -6
- python_doctr-0.10.0/doctr/models/detection/fast/__init__.py +0 -6
- python_doctr-0.10.0/doctr/models/detection/linknet/__init__.py +0 -6
- python_doctr-0.10.0/doctr/models/detection/predictor/__init__.py +0 -6
- python_doctr-0.10.0/doctr/models/kie_predictor/__init__.py +0 -6
- python_doctr-0.10.0/doctr/models/modules/layers/__init__.py +0 -6
- python_doctr-0.10.0/doctr/models/modules/transformer/__init__.py +0 -6
- python_doctr-0.10.0/doctr/models/modules/vision_transformer/__init__.py +0 -6
- python_doctr-0.10.0/doctr/models/predictor/__init__.py +0 -6
- python_doctr-0.10.0/doctr/models/preprocessor/__init__.py +0 -6
- python_doctr-0.10.0/doctr/models/recognition/crnn/__init__.py +0 -6
- python_doctr-0.10.0/doctr/models/recognition/master/__init__.py +0 -6
- python_doctr-0.10.0/doctr/models/recognition/parseq/__init__.py +0 -6
- python_doctr-0.10.0/doctr/models/recognition/predictor/__init__.py +0 -6
- python_doctr-0.10.0/doctr/models/recognition/sar/__init__.py +0 -6
- python_doctr-0.10.0/doctr/models/recognition/vitstr/__init__.py +0 -6
- python_doctr-0.10.0/doctr/models/utils/__init__.py +0 -6
- python_doctr-0.10.0/doctr/transforms/modules/__init__.py +0 -8
- python_doctr-0.10.0/doctr/utils/common_types.py +0 -18
- python_doctr-0.10.0/doctr/version.py +0 -1
- {python_doctr-0.10.0 → python_doctr-0.11.0}/LICENSE +0 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/__init__.py +0 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/datasets/__init__.py +0 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/io/__init__.py +0 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/__init__.py +0 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/classification/__init__.py +0 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/detection/__init__.py +0 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/factory/__init__.py +0 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/modules/__init__.py +0 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/models/recognition/__init__.py +0 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/py.typed +0 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/transforms/__init__.py +0 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/doctr/utils/__init__.py +0 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/python_doctr.egg-info/SOURCES.txt +0 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/python_doctr.egg-info/dependency_links.txt +0 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/python_doctr.egg-info/top_level.txt +0 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/python_doctr.egg-info/zip-safe +0 -0
- {python_doctr-0.10.0 → python_doctr-0.11.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
2
|
Name: python-doctr
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.11.0
|
|
4
4
|
Summary: Document Text Recognition (docTR): deep Learning for high-performance OCR on documents.
|
|
5
5
|
Author-email: Mindee <contact@mindee.com>
|
|
6
6
|
Maintainer: François-Guillaume Fernandez, Charles Gaillard, Olivier Dulcy, Felix Dittrich
|
|
@@ -219,11 +219,11 @@ Classifier: License :: OSI Approved :: Apache Software License
|
|
|
219
219
|
Classifier: Natural Language :: English
|
|
220
220
|
Classifier: Operating System :: OS Independent
|
|
221
221
|
Classifier: Programming Language :: Python :: 3
|
|
222
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
223
222
|
Classifier: Programming Language :: Python :: 3.10
|
|
224
223
|
Classifier: Programming Language :: Python :: 3.11
|
|
224
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
225
225
|
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
226
|
-
Requires-Python: <4,>=3.
|
|
226
|
+
Requires-Python: <4,>=3.10.0
|
|
227
227
|
Description-Content-Type: text/markdown
|
|
228
228
|
License-File: LICENSE
|
|
229
229
|
Requires-Dist: numpy<3.0.0,>=1.16.0
|
|
@@ -241,7 +241,8 @@ Requires-Dist: defusedxml>=0.7.0
|
|
|
241
241
|
Requires-Dist: anyascii>=0.3.2
|
|
242
242
|
Requires-Dist: tqdm>=4.30.0
|
|
243
243
|
Provides-Extra: tf
|
|
244
|
-
Requires-Dist: tensorflow<3.0.0,>=2.15.0; extra == "tf"
|
|
244
|
+
Requires-Dist: tensorflow[and-cuda]<3.0.0,>=2.15.0; sys_platform == "linux" and extra == "tf"
|
|
245
|
+
Requires-Dist: tensorflow<3.0.0,>=2.15.0; sys_platform != "linux" and extra == "tf"
|
|
245
246
|
Requires-Dist: tf-keras<3.0.0,>=2.15.0; extra == "tf"
|
|
246
247
|
Requires-Dist: tf2onnx<2.0.0,>=1.16.0; extra == "tf"
|
|
247
248
|
Provides-Extra: torch
|
|
@@ -275,7 +276,8 @@ Requires-Dist: sphinx-markdown-tables>=0.0.15; extra == "docs"
|
|
|
275
276
|
Requires-Dist: sphinx-tabs>=3.3.0; extra == "docs"
|
|
276
277
|
Requires-Dist: furo>=2022.3.4; extra == "docs"
|
|
277
278
|
Provides-Extra: dev
|
|
278
|
-
Requires-Dist: tensorflow<3.0.0,>=2.15.0; extra == "dev"
|
|
279
|
+
Requires-Dist: tensorflow[and-cuda]<3.0.0,>=2.15.0; sys_platform == "linux" and extra == "dev"
|
|
280
|
+
Requires-Dist: tensorflow<3.0.0,>=2.15.0; sys_platform != "linux" and extra == "dev"
|
|
279
281
|
Requires-Dist: tf-keras<3.0.0,>=2.15.0; extra == "dev"
|
|
280
282
|
Requires-Dist: tf2onnx<2.0.0,>=1.16.0; extra == "dev"
|
|
281
283
|
Requires-Dist: torch<3.0.0,>=2.0.0; extra == "dev"
|
|
@@ -305,7 +307,7 @@ Requires-Dist: furo>=2022.3.4; extra == "dev"
|
|
|
305
307
|
<img src="https://github.com/mindee/doctr/raw/main/docs/images/Logo_doctr.gif" width="40%">
|
|
306
308
|
</p>
|
|
307
309
|
|
|
308
|
-
[](https://slack.mindee.com) [](LICENSE)  [](https://github.com/mindee/doctr/pkgs/container/doctr) [](https://codecov.io/gh/mindee/doctr) [](https://www.codefactor.io/repository/github/mindee/doctr) [](https://app.codacy.com/gh/mindee/doctr?utm_source=github.com&utm_medium=referral&utm_content=mindee/doctr&utm_campaign=Badge_Grade) [](https://mindee.github.io/doctr) [](https://slack.mindee.com) [](LICENSE)  [](https://github.com/mindee/doctr/pkgs/container/doctr) [](https://codecov.io/gh/mindee/doctr) [](https://www.codefactor.io/repository/github/mindee/doctr) [](https://app.codacy.com/gh/mindee/doctr?utm_source=github.com&utm_medium=referral&utm_content=mindee/doctr&utm_campaign=Badge_Grade) [](https://mindee.github.io/doctr) [](https://pypi.org/project/python-doctr/) [](https://huggingface.co/spaces/mindee/doctr) [](https://colab.research.google.com/github/mindee/notebooks/blob/main/doctr/quicktour.ipynb) [](https://gurubase.io/g/doctr)
|
|
309
311
|
|
|
310
312
|
|
|
311
313
|
**Optical Character Recognition made seamless & accessible to anyone, powered by TensorFlow 2 & PyTorch**
|
|
@@ -438,7 +440,7 @@ The KIE predictor results per page are in a dictionary format with each key repr
|
|
|
438
440
|
|
|
439
441
|
### Prerequisites
|
|
440
442
|
|
|
441
|
-
Python 3.
|
|
443
|
+
Python 3.10 (or higher) and [pip](https://pip.pypa.io/en/stable/) are required to install docTR.
|
|
442
444
|
|
|
443
445
|
### Latest release
|
|
444
446
|
|
|
@@ -557,37 +559,37 @@ Check out our [TensorFlow.js demo](https://github.com/mindee/doctr-tfjs-demo) to
|
|
|
557
559
|
|
|
558
560
|
### Docker container
|
|
559
561
|
|
|
560
|
-
|
|
562
|
+
We offer Docker container support for easy testing and deployment. [Here are the available docker tags.](https://github.com/mindee/doctr/pkgs/container/doctr).
|
|
561
563
|
|
|
562
564
|
#### Using GPU with docTR Docker Images
|
|
563
565
|
|
|
564
|
-
The docTR Docker images are GPU-ready and based on CUDA `
|
|
565
|
-
|
|
566
|
+
The docTR Docker images are GPU-ready and based on CUDA `12.2`. Make sure your host is **at least `12.2`**, otherwise Torch or TensorFlow won't be able to initialize the GPU.
|
|
567
|
+
Please ensure that Docker is configured to use your GPU.
|
|
566
568
|
|
|
567
569
|
To verify and configure GPU support for Docker, please follow the instructions provided in the [NVIDIA Container Toolkit Installation Guide](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html).
|
|
568
570
|
|
|
569
571
|
Once Docker is configured to use GPUs, you can run docTR Docker containers with GPU support:
|
|
570
572
|
|
|
571
573
|
```shell
|
|
572
|
-
docker run -it --gpus all ghcr.io/mindee/doctr:
|
|
574
|
+
docker run -it --gpus all ghcr.io/mindee/doctr:torch-py3.9.18-2024-10 bash
|
|
573
575
|
```
|
|
574
576
|
|
|
575
577
|
#### Available Tags
|
|
576
578
|
|
|
577
|
-
The Docker images for docTR follow a specific tag nomenclature: `<
|
|
579
|
+
The Docker images for docTR follow a specific tag nomenclature: `<deps>-py<python_version>-<doctr_version|YYYY-MM>`. Here's a breakdown of the tag structure:
|
|
578
580
|
|
|
579
|
-
- `<
|
|
580
|
-
- `<python_version>`: `3.
|
|
581
|
-
- `<
|
|
582
|
-
- `<
|
|
583
|
-
- `<YYYY-MM>`: e.g. `2023-09`
|
|
581
|
+
- `<deps>`: `tf`, `torch`, `tf-viz-html-contrib` or `torch-viz-html-contrib`.
|
|
582
|
+
- `<python_version>`: `3.9.18`, `3.10.13` or `3.11.8`.
|
|
583
|
+
- `<doctr_version>`: a tag >= `v0.11.0`
|
|
584
|
+
- `<YYYY-MM>`: e.g. `2014-10`
|
|
584
585
|
|
|
585
586
|
Here are examples of different image tags:
|
|
586
587
|
|
|
587
588
|
| Tag | Description |
|
|
588
589
|
|----------------------------|---------------------------------------------------|
|
|
589
|
-
| `tf-py3.
|
|
590
|
-
| `torch-py3.
|
|
590
|
+
| `tf-py3.10.13-v0.11.0` | TensorFlow version `3.10.13` with docTR `v0.11.0`. |
|
|
591
|
+
| `torch-viz-html-contrib-py3.11.8-2024-10` | Torch with extra dependencies version `3.11.8` from latest commit on `main` in `2024-10`. |
|
|
592
|
+
| `torch-py3.11.8-2024-10`| PyTorch version `3.11.8` from latest commit on `main` in `2024-10`. |
|
|
591
593
|
|
|
592
594
|
#### Building Docker Images Locally
|
|
593
595
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<img src="https://github.com/mindee/doctr/raw/main/docs/images/Logo_doctr.gif" width="40%">
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
|
-
[](https://slack.mindee.com) [](LICENSE)  [](https://github.com/mindee/doctr/pkgs/container/doctr) [](https://codecov.io/gh/mindee/doctr) [](https://www.codefactor.io/repository/github/mindee/doctr) [](https://app.codacy.com/gh/mindee/doctr?utm_source=github.com&utm_medium=referral&utm_content=mindee/doctr&utm_campaign=Badge_Grade) [](https://mindee.github.io/doctr) [](https://slack.mindee.com) [](LICENSE)  [](https://github.com/mindee/doctr/pkgs/container/doctr) [](https://codecov.io/gh/mindee/doctr) [](https://www.codefactor.io/repository/github/mindee/doctr) [](https://app.codacy.com/gh/mindee/doctr?utm_source=github.com&utm_medium=referral&utm_content=mindee/doctr&utm_campaign=Badge_Grade) [](https://mindee.github.io/doctr) [](https://pypi.org/project/python-doctr/) [](https://huggingface.co/spaces/mindee/doctr) [](https://colab.research.google.com/github/mindee/notebooks/blob/main/doctr/quicktour.ipynb) [](https://gurubase.io/g/doctr)
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
**Optical Character Recognition made seamless & accessible to anyone, powered by TensorFlow 2 & PyTorch**
|
|
@@ -135,7 +135,7 @@ The KIE predictor results per page are in a dictionary format with each key repr
|
|
|
135
135
|
|
|
136
136
|
### Prerequisites
|
|
137
137
|
|
|
138
|
-
Python 3.
|
|
138
|
+
Python 3.10 (or higher) and [pip](https://pip.pypa.io/en/stable/) are required to install docTR.
|
|
139
139
|
|
|
140
140
|
### Latest release
|
|
141
141
|
|
|
@@ -254,37 +254,37 @@ Check out our [TensorFlow.js demo](https://github.com/mindee/doctr-tfjs-demo) to
|
|
|
254
254
|
|
|
255
255
|
### Docker container
|
|
256
256
|
|
|
257
|
-
|
|
257
|
+
We offer Docker container support for easy testing and deployment. [Here are the available docker tags.](https://github.com/mindee/doctr/pkgs/container/doctr).
|
|
258
258
|
|
|
259
259
|
#### Using GPU with docTR Docker Images
|
|
260
260
|
|
|
261
|
-
The docTR Docker images are GPU-ready and based on CUDA `
|
|
262
|
-
|
|
261
|
+
The docTR Docker images are GPU-ready and based on CUDA `12.2`. Make sure your host is **at least `12.2`**, otherwise Torch or TensorFlow won't be able to initialize the GPU.
|
|
262
|
+
Please ensure that Docker is configured to use your GPU.
|
|
263
263
|
|
|
264
264
|
To verify and configure GPU support for Docker, please follow the instructions provided in the [NVIDIA Container Toolkit Installation Guide](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html).
|
|
265
265
|
|
|
266
266
|
Once Docker is configured to use GPUs, you can run docTR Docker containers with GPU support:
|
|
267
267
|
|
|
268
268
|
```shell
|
|
269
|
-
docker run -it --gpus all ghcr.io/mindee/doctr:
|
|
269
|
+
docker run -it --gpus all ghcr.io/mindee/doctr:torch-py3.9.18-2024-10 bash
|
|
270
270
|
```
|
|
271
271
|
|
|
272
272
|
#### Available Tags
|
|
273
273
|
|
|
274
|
-
The Docker images for docTR follow a specific tag nomenclature: `<
|
|
274
|
+
The Docker images for docTR follow a specific tag nomenclature: `<deps>-py<python_version>-<doctr_version|YYYY-MM>`. Here's a breakdown of the tag structure:
|
|
275
275
|
|
|
276
|
-
- `<
|
|
277
|
-
- `<python_version>`: `3.
|
|
278
|
-
- `<
|
|
279
|
-
- `<
|
|
280
|
-
- `<YYYY-MM>`: e.g. `2023-09`
|
|
276
|
+
- `<deps>`: `tf`, `torch`, `tf-viz-html-contrib` or `torch-viz-html-contrib`.
|
|
277
|
+
- `<python_version>`: `3.9.18`, `3.10.13` or `3.11.8`.
|
|
278
|
+
- `<doctr_version>`: a tag >= `v0.11.0`
|
|
279
|
+
- `<YYYY-MM>`: e.g. `2014-10`
|
|
281
280
|
|
|
282
281
|
Here are examples of different image tags:
|
|
283
282
|
|
|
284
283
|
| Tag | Description |
|
|
285
284
|
|----------------------------|---------------------------------------------------|
|
|
286
|
-
| `tf-py3.
|
|
287
|
-
| `torch-py3.
|
|
285
|
+
| `tf-py3.10.13-v0.11.0` | TensorFlow version `3.10.13` with docTR `v0.11.0`. |
|
|
286
|
+
| `torch-viz-html-contrib-py3.11.8-2024-10` | Torch with extra dependencies version `3.11.8` from latest commit on `main` in `2024-10`. |
|
|
287
|
+
| `torch-py3.11.8-2024-10`| PyTorch version `3.11.8` from latest commit on `main` in `2024-10`. |
|
|
288
288
|
|
|
289
289
|
#### Building Docker Images Locally
|
|
290
290
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .artefacts import ArtefactDetector
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
# Copyright (C) 2021-
|
|
1
|
+
# Copyright (C) 2021-2025, Mindee.
|
|
2
2
|
|
|
3
3
|
# This program is licensed under the Apache License 2.0.
|
|
4
4
|
# See LICENSE or go to <https://opensource.org/licenses/Apache-2.0> for full license details.
|
|
5
5
|
|
|
6
|
-
from typing import Any
|
|
6
|
+
from typing import Any
|
|
7
7
|
|
|
8
8
|
import cv2
|
|
9
9
|
import numpy as np
|
|
@@ -14,7 +14,7 @@ from .base import _BasePredictor
|
|
|
14
14
|
|
|
15
15
|
__all__ = ["ArtefactDetector"]
|
|
16
16
|
|
|
17
|
-
default_cfgs:
|
|
17
|
+
default_cfgs: dict[str, dict[str, Any]] = {
|
|
18
18
|
"yolov8_artefact": {
|
|
19
19
|
"input_shape": (3, 1024, 1024),
|
|
20
20
|
"labels": ["bar_code", "qr_code", "logo", "photo"],
|
|
@@ -34,7 +34,6 @@ class ArtefactDetector(_BasePredictor):
|
|
|
34
34
|
>>> results = detector(doc)
|
|
35
35
|
|
|
36
36
|
Args:
|
|
37
|
-
----
|
|
38
37
|
arch: the architecture to use
|
|
39
38
|
batch_size: the batch size to use
|
|
40
39
|
model_path: the path to the model to use
|
|
@@ -50,9 +49,9 @@ class ArtefactDetector(_BasePredictor):
|
|
|
50
49
|
self,
|
|
51
50
|
arch: str = "yolov8_artefact",
|
|
52
51
|
batch_size: int = 2,
|
|
53
|
-
model_path:
|
|
54
|
-
labels:
|
|
55
|
-
input_shape:
|
|
52
|
+
model_path: str | None = None,
|
|
53
|
+
labels: list[str] | None = None,
|
|
54
|
+
input_shape: tuple[int, int, int] | None = None,
|
|
56
55
|
conf_threshold: float = 0.5,
|
|
57
56
|
iou_threshold: float = 0.5,
|
|
58
57
|
**kwargs: Any,
|
|
@@ -66,7 +65,7 @@ class ArtefactDetector(_BasePredictor):
|
|
|
66
65
|
def preprocess(self, img: np.ndarray) -> np.ndarray:
|
|
67
66
|
return np.transpose(cv2.resize(img, (self.input_shape[2], self.input_shape[1])), (2, 0, 1)) / np.array(255.0)
|
|
68
67
|
|
|
69
|
-
def postprocess(self, output:
|
|
68
|
+
def postprocess(self, output: list[np.ndarray], input_images: list[list[np.ndarray]]) -> list[list[dict[str, Any]]]:
|
|
70
69
|
results = []
|
|
71
70
|
|
|
72
71
|
for batch in zip(output, input_images):
|
|
@@ -109,7 +108,6 @@ class ArtefactDetector(_BasePredictor):
|
|
|
109
108
|
Display the results
|
|
110
109
|
|
|
111
110
|
Args:
|
|
112
|
-
----
|
|
113
111
|
**kwargs: additional keyword arguments to be passed to `plt.show`
|
|
114
112
|
"""
|
|
115
113
|
requires_package("matplotlib", "`.show()` requires matplotlib installed")
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
# Copyright (C) 2021-
|
|
1
|
+
# Copyright (C) 2021-2025, Mindee.
|
|
2
2
|
|
|
3
3
|
# This program is licensed under the Apache License 2.0.
|
|
4
4
|
# See LICENSE or go to <https://opensource.org/licenses/Apache-2.0> for full license details.
|
|
5
5
|
|
|
6
|
-
from typing import Any
|
|
6
|
+
from typing import Any
|
|
7
7
|
|
|
8
8
|
import numpy as np
|
|
9
9
|
|
|
@@ -16,32 +16,29 @@ class _BasePredictor:
|
|
|
16
16
|
Base class for all predictors
|
|
17
17
|
|
|
18
18
|
Args:
|
|
19
|
-
----
|
|
20
19
|
batch_size: the batch size to use
|
|
21
20
|
url: the url to use to download a model if needed
|
|
22
21
|
model_path: the path to the model to use
|
|
23
22
|
**kwargs: additional arguments to be passed to `download_from_url`
|
|
24
23
|
"""
|
|
25
24
|
|
|
26
|
-
def __init__(self, batch_size: int, url:
|
|
25
|
+
def __init__(self, batch_size: int, url: str | None = None, model_path: str | None = None, **kwargs) -> None:
|
|
27
26
|
self.batch_size = batch_size
|
|
28
27
|
self.session = self._init_model(url, model_path, **kwargs)
|
|
29
28
|
|
|
30
|
-
self._inputs:
|
|
31
|
-
self._results:
|
|
29
|
+
self._inputs: list[np.ndarray] = []
|
|
30
|
+
self._results: list[Any] = []
|
|
32
31
|
|
|
33
|
-
def _init_model(self, url:
|
|
32
|
+
def _init_model(self, url: str | None = None, model_path: str | None = None, **kwargs: Any) -> Any:
|
|
34
33
|
"""
|
|
35
34
|
Download the model from the given url if needed
|
|
36
35
|
|
|
37
36
|
Args:
|
|
38
|
-
----
|
|
39
37
|
url: the url to use
|
|
40
38
|
model_path: the path to the model to use
|
|
41
39
|
**kwargs: additional arguments to be passed to `download_from_url`
|
|
42
40
|
|
|
43
41
|
Returns:
|
|
44
|
-
-------
|
|
45
42
|
Any: the ONNX loaded model
|
|
46
43
|
"""
|
|
47
44
|
requires_package("onnxruntime", "`.contrib` module requires `onnxruntime` to be installed.")
|
|
@@ -57,40 +54,34 @@ class _BasePredictor:
|
|
|
57
54
|
Preprocess the input image
|
|
58
55
|
|
|
59
56
|
Args:
|
|
60
|
-
----
|
|
61
57
|
img: the input image to preprocess
|
|
62
58
|
|
|
63
59
|
Returns:
|
|
64
|
-
-------
|
|
65
60
|
np.ndarray: the preprocessed image
|
|
66
61
|
"""
|
|
67
62
|
raise NotImplementedError
|
|
68
63
|
|
|
69
|
-
def postprocess(self, output:
|
|
64
|
+
def postprocess(self, output: list[np.ndarray], input_images: list[list[np.ndarray]]) -> Any:
|
|
70
65
|
"""
|
|
71
66
|
Postprocess the model output
|
|
72
67
|
|
|
73
68
|
Args:
|
|
74
|
-
----
|
|
75
69
|
output: the model output to postprocess
|
|
76
70
|
input_images: the input images used to generate the output
|
|
77
71
|
|
|
78
72
|
Returns:
|
|
79
|
-
-------
|
|
80
73
|
Any: the postprocessed output
|
|
81
74
|
"""
|
|
82
75
|
raise NotImplementedError
|
|
83
76
|
|
|
84
|
-
def __call__(self, inputs:
|
|
77
|
+
def __call__(self, inputs: list[np.ndarray]) -> Any:
|
|
85
78
|
"""
|
|
86
79
|
Call the model on the given inputs
|
|
87
80
|
|
|
88
81
|
Args:
|
|
89
|
-
----
|
|
90
82
|
inputs: the inputs to use
|
|
91
83
|
|
|
92
84
|
Returns:
|
|
93
|
-
-------
|
|
94
85
|
Any: the postprocessed output
|
|
95
86
|
"""
|
|
96
87
|
self._inputs = inputs
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Copyright (C) 2021-
|
|
1
|
+
# Copyright (C) 2021-2025, Mindee.
|
|
2
2
|
|
|
3
3
|
# This program is licensed under the Apache License 2.0.
|
|
4
4
|
# See LICENSE or go to <https://opensource.org/licenses/Apache-2.0> for full license details.
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import json
|
|
7
7
|
import os
|
|
8
8
|
from pathlib import Path
|
|
9
|
-
from typing import Any
|
|
9
|
+
from typing import Any
|
|
10
10
|
|
|
11
11
|
import numpy as np
|
|
12
12
|
from tqdm import tqdm
|
|
@@ -29,7 +29,6 @@ class CORD(VisionDataset):
|
|
|
29
29
|
>>> img, target = train_set[0]
|
|
30
30
|
|
|
31
31
|
Args:
|
|
32
|
-
----
|
|
33
32
|
train: whether the subset should be the training one
|
|
34
33
|
use_polygons: whether polygons should be considered as rotated bounding box (instead of straight ones)
|
|
35
34
|
recognition_task: whether the dataset should be used for recognition task
|
|
@@ -72,12 +71,14 @@ class CORD(VisionDataset):
|
|
|
72
71
|
+ "To get the whole dataset with boxes and labels leave both parameters to False."
|
|
73
72
|
)
|
|
74
73
|
|
|
75
|
-
#
|
|
74
|
+
# list images
|
|
76
75
|
tmp_root = os.path.join(self.root, "image")
|
|
77
|
-
self.data:
|
|
76
|
+
self.data: list[tuple[str | np.ndarray, str | dict[str, Any] | np.ndarray]] = []
|
|
78
77
|
self.train = train
|
|
79
78
|
np_dtype = np.float32
|
|
80
|
-
for img_path in tqdm(
|
|
79
|
+
for img_path in tqdm(
|
|
80
|
+
iterable=os.listdir(tmp_root), desc="Preparing and Loading CORD", total=len(os.listdir(tmp_root))
|
|
81
|
+
):
|
|
81
82
|
# File existence check
|
|
82
83
|
if not os.path.exists(os.path.join(tmp_root, img_path)):
|
|
83
84
|
raise FileNotFoundError(f"unable to locate {os.path.join(tmp_root, img_path)}")
|
|
@@ -91,7 +92,7 @@ class CORD(VisionDataset):
|
|
|
91
92
|
if len(word["text"]) > 0:
|
|
92
93
|
x = word["quad"]["x1"], word["quad"]["x2"], word["quad"]["x3"], word["quad"]["x4"]
|
|
93
94
|
y = word["quad"]["y1"], word["quad"]["y2"], word["quad"]["y3"], word["quad"]["y4"]
|
|
94
|
-
box:
|
|
95
|
+
box: list[float] | np.ndarray
|
|
95
96
|
if use_polygons:
|
|
96
97
|
# (x, y) coordinates of top left, top right, bottom right, bottom left corners
|
|
97
98
|
box = np.array(
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
# Copyright (C) 2021-
|
|
1
|
+
# Copyright (C) 2021-2025, Mindee.
|
|
2
2
|
|
|
3
3
|
# This program is licensed under the Apache License 2.0.
|
|
4
4
|
# See LICENSE or go to <https://opensource.org/licenses/Apache-2.0> for full license details.
|
|
5
5
|
|
|
6
6
|
import os
|
|
7
7
|
import shutil
|
|
8
|
+
from collections.abc import Callable
|
|
8
9
|
from pathlib import Path
|
|
9
|
-
from typing import Any
|
|
10
|
+
from typing import Any
|
|
10
11
|
|
|
11
12
|
import numpy as np
|
|
12
13
|
|
|
@@ -19,15 +20,15 @@ __all__ = ["_AbstractDataset", "_VisionDataset"]
|
|
|
19
20
|
|
|
20
21
|
|
|
21
22
|
class _AbstractDataset:
|
|
22
|
-
data:
|
|
23
|
-
_pre_transforms:
|
|
23
|
+
data: list[Any] = []
|
|
24
|
+
_pre_transforms: Callable[[Any, Any], tuple[Any, Any]] | None = None
|
|
24
25
|
|
|
25
26
|
def __init__(
|
|
26
27
|
self,
|
|
27
|
-
root:
|
|
28
|
-
img_transforms:
|
|
29
|
-
sample_transforms:
|
|
30
|
-
pre_transforms:
|
|
28
|
+
root: str | Path,
|
|
29
|
+
img_transforms: Callable[[Any], Any] | None = None,
|
|
30
|
+
sample_transforms: Callable[[Any, Any], tuple[Any, Any]] | None = None,
|
|
31
|
+
pre_transforms: Callable[[Any, Any], tuple[Any, Any]] | None = None,
|
|
31
32
|
) -> None:
|
|
32
33
|
if not Path(root).is_dir():
|
|
33
34
|
raise ValueError(f"expected a path to a reachable folder: {root}")
|
|
@@ -41,10 +42,10 @@ class _AbstractDataset:
|
|
|
41
42
|
def __len__(self) -> int:
|
|
42
43
|
return len(self.data)
|
|
43
44
|
|
|
44
|
-
def _read_sample(self, index: int) ->
|
|
45
|
+
def _read_sample(self, index: int) -> tuple[Any, Any]:
|
|
45
46
|
raise NotImplementedError
|
|
46
47
|
|
|
47
|
-
def __getitem__(self, index: int) ->
|
|
48
|
+
def __getitem__(self, index: int) -> tuple[Any, Any]:
|
|
48
49
|
# Read image
|
|
49
50
|
img, target = self._read_sample(index)
|
|
50
51
|
# Pre-transforms (format conversion at run-time etc.)
|
|
@@ -82,7 +83,6 @@ class _VisionDataset(_AbstractDataset):
|
|
|
82
83
|
"""Implements an abstract dataset
|
|
83
84
|
|
|
84
85
|
Args:
|
|
85
|
-
----
|
|
86
86
|
url: URL of the dataset
|
|
87
87
|
file_name: name of the file once downloaded
|
|
88
88
|
file_hash: expected SHA256 of the file
|
|
@@ -96,13 +96,13 @@ class _VisionDataset(_AbstractDataset):
|
|
|
96
96
|
def __init__(
|
|
97
97
|
self,
|
|
98
98
|
url: str,
|
|
99
|
-
file_name:
|
|
100
|
-
file_hash:
|
|
99
|
+
file_name: str | None = None,
|
|
100
|
+
file_hash: str | None = None,
|
|
101
101
|
extract_archive: bool = False,
|
|
102
102
|
download: bool = False,
|
|
103
103
|
overwrite: bool = False,
|
|
104
|
-
cache_dir:
|
|
105
|
-
cache_subdir:
|
|
104
|
+
cache_dir: str | None = None,
|
|
105
|
+
cache_subdir: str | None = None,
|
|
106
106
|
**kwargs: Any,
|
|
107
107
|
) -> None:
|
|
108
108
|
cache_dir = (
|
|
@@ -115,7 +115,7 @@ class _VisionDataset(_AbstractDataset):
|
|
|
115
115
|
|
|
116
116
|
file_name = file_name if isinstance(file_name, str) else os.path.basename(url)
|
|
117
117
|
# Download the file if not present
|
|
118
|
-
archive_path:
|
|
118
|
+
archive_path: str | Path = os.path.join(cache_dir, cache_subdir, file_name)
|
|
119
119
|
|
|
120
120
|
if not os.path.exists(archive_path) and not download:
|
|
121
121
|
raise ValueError("the dataset needs to be downloaded first with download=True")
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
# Copyright (C) 2021-
|
|
1
|
+
# Copyright (C) 2021-2025, Mindee.
|
|
2
2
|
|
|
3
3
|
# This program is licensed under the Apache License 2.0.
|
|
4
4
|
# See LICENSE or go to <https://opensource.org/licenses/Apache-2.0> for full license details.
|
|
5
5
|
|
|
6
6
|
import os
|
|
7
7
|
from copy import deepcopy
|
|
8
|
-
from typing import Any
|
|
8
|
+
from typing import Any
|
|
9
9
|
|
|
10
10
|
import numpy as np
|
|
11
11
|
import torch
|
|
@@ -20,7 +20,7 @@ __all__ = ["AbstractDataset", "VisionDataset"]
|
|
|
20
20
|
class AbstractDataset(_AbstractDataset):
|
|
21
21
|
"""Abstract class for all datasets"""
|
|
22
22
|
|
|
23
|
-
def _read_sample(self, index: int) ->
|
|
23
|
+
def _read_sample(self, index: int) -> tuple[torch.Tensor, Any]:
|
|
24
24
|
img_name, target = self.data[index]
|
|
25
25
|
|
|
26
26
|
# Check target
|
|
@@ -29,14 +29,14 @@ class AbstractDataset(_AbstractDataset):
|
|
|
29
29
|
assert "labels" in target, "Target should contain 'labels' key"
|
|
30
30
|
elif isinstance(target, tuple):
|
|
31
31
|
assert len(target) == 2
|
|
32
|
-
assert isinstance(target[0], str) or isinstance(
|
|
33
|
-
|
|
34
|
-
)
|
|
32
|
+
assert isinstance(target[0], str) or isinstance(target[0], np.ndarray), (
|
|
33
|
+
"first element of the tuple should be a string or a numpy array"
|
|
34
|
+
)
|
|
35
35
|
assert isinstance(target[1], list), "second element of the tuple should be a list"
|
|
36
36
|
else:
|
|
37
|
-
assert isinstance(target, str) or isinstance(
|
|
38
|
-
|
|
39
|
-
)
|
|
37
|
+
assert isinstance(target, str) or isinstance(target, np.ndarray), (
|
|
38
|
+
"Target should be a string or a numpy array"
|
|
39
|
+
)
|
|
40
40
|
|
|
41
41
|
# Read image
|
|
42
42
|
img = (
|
|
@@ -48,11 +48,11 @@ class AbstractDataset(_AbstractDataset):
|
|
|
48
48
|
return img, deepcopy(target)
|
|
49
49
|
|
|
50
50
|
@staticmethod
|
|
51
|
-
def collate_fn(samples:
|
|
51
|
+
def collate_fn(samples: list[tuple[torch.Tensor, Any]]) -> tuple[torch.Tensor, list[Any]]:
|
|
52
52
|
images, targets = zip(*samples)
|
|
53
|
-
images = torch.stack(images, dim=0)
|
|
53
|
+
images = torch.stack(images, dim=0)
|
|
54
54
|
|
|
55
|
-
return images, list(targets)
|
|
55
|
+
return images, list(targets)
|
|
56
56
|
|
|
57
57
|
|
|
58
58
|
class VisionDataset(AbstractDataset, _VisionDataset): # noqa: D101
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
# Copyright (C) 2021-
|
|
1
|
+
# Copyright (C) 2021-2025, Mindee.
|
|
2
2
|
|
|
3
3
|
# This program is licensed under the Apache License 2.0.
|
|
4
4
|
# See LICENSE or go to <https://opensource.org/licenses/Apache-2.0> for full license details.
|
|
5
5
|
|
|
6
6
|
import os
|
|
7
7
|
from copy import deepcopy
|
|
8
|
-
from typing import Any
|
|
8
|
+
from typing import Any
|
|
9
9
|
|
|
10
10
|
import numpy as np
|
|
11
11
|
import tensorflow as tf
|
|
@@ -20,7 +20,7 @@ __all__ = ["AbstractDataset", "VisionDataset"]
|
|
|
20
20
|
class AbstractDataset(_AbstractDataset):
|
|
21
21
|
"""Abstract class for all datasets"""
|
|
22
22
|
|
|
23
|
-
def _read_sample(self, index: int) ->
|
|
23
|
+
def _read_sample(self, index: int) -> tuple[tf.Tensor, Any]:
|
|
24
24
|
img_name, target = self.data[index]
|
|
25
25
|
|
|
26
26
|
# Check target
|
|
@@ -29,14 +29,14 @@ class AbstractDataset(_AbstractDataset):
|
|
|
29
29
|
assert "labels" in target, "Target should contain 'labels' key"
|
|
30
30
|
elif isinstance(target, tuple):
|
|
31
31
|
assert len(target) == 2
|
|
32
|
-
assert isinstance(target[0], str) or isinstance(
|
|
33
|
-
|
|
34
|
-
)
|
|
32
|
+
assert isinstance(target[0], str) or isinstance(target[0], np.ndarray), (
|
|
33
|
+
"first element of the tuple should be a string or a numpy array"
|
|
34
|
+
)
|
|
35
35
|
assert isinstance(target[1], list), "second element of the tuple should be a list"
|
|
36
36
|
else:
|
|
37
|
-
assert isinstance(target, str) or isinstance(
|
|
38
|
-
|
|
39
|
-
)
|
|
37
|
+
assert isinstance(target, str) or isinstance(target, np.ndarray), (
|
|
38
|
+
"Target should be a string or a numpy array"
|
|
39
|
+
)
|
|
40
40
|
|
|
41
41
|
# Read image
|
|
42
42
|
img = (
|
|
@@ -48,7 +48,7 @@ class AbstractDataset(_AbstractDataset):
|
|
|
48
48
|
return img, deepcopy(target)
|
|
49
49
|
|
|
50
50
|
@staticmethod
|
|
51
|
-
def collate_fn(samples:
|
|
51
|
+
def collate_fn(samples: list[tuple[tf.Tensor, Any]]) -> tuple[tf.Tensor, list[Any]]:
|
|
52
52
|
images, targets = zip(*samples)
|
|
53
53
|
images = tf.stack(images, axis=0)
|
|
54
54
|
|