torchocr.datasets#
Datasets return (uint8 image, TextDetectionTarget) pairs (detection) or (image, text) pairs
(word crops). None of them downloads anything: point them at the extracted archives.
- class torchocr.datasets.TextDetectionTarget(polygons, texts, ignore)[source]#
Bases:
objectGround-truth text regions for one image.
- polygons#
(N, P, 2)float vertices in pixel(x, y)order. ICDAR-2015 regions are quadrilaterals (P = 4).- Type:
- ignore#
(N,)bool mask of don’t-care regions (###in ICDAR files). Evaluators exclude them from both recall and precision.- Type:
- class torchocr.datasets.ICDAR2015(root, split='test', transforms=None)[source]#
Bases:
Dataset[tuple[Tensor,TextDetectionTarget]]ICDAR 2015 Incidental Scene Text, Task 4.1 (text localization).
1000 training and 500 test images of street-level scenes captured with wearable cameras; text regions are word-level quadrilaterals.
The dataset requires registration, so it cannot be downloaded automatically. Get the four archives from https://rrc.cvc.uab.es/?ch=4&com=downloads and extract each into a folder of the same name under
root:root/ ch4_training_images/ img_1.jpg ... ch4_training_localization_transcription_gt/ gt_img_1.txt ... ch4_test_images/ img_1.jpg ... Challenge4_Test_Task1_GT/ gt_img_1.txt ...
- Parameters:
root (str | Path) – Directory holding the extracted archives.
split (Literal['train', 'test']) –
"train"or"test". Default"test".transforms (Callable[[Tensor, TextDetectionTarget], tuple[Tensor, TextDetectionTarget]] | None) – Optional callable
(image, target) -> (image, target)applied to every sample.
- Returns:
(image, target)whereimageis a(3, H, W)uint8RGB tensor andtargetaTextDetectionTargetwith(N, 4, 2)polygons in original-image pixels.
- class torchocr.datasets.TotalText(root, split='test', transforms=None)[source]#
Bases:
Dataset[tuple[Tensor,TextDetectionTarget]]Total-Text (Ch’ng & Chan, ICDAR 2017): 1255 train / 300 test images of horizontal, multi-oriented and curved scene text, annotated with word-level polygons of 3 to 19 vertices.
Expected layout (the released images plus the
txt_formatground truth):root/ Images/Train/img11.jpg ... Images/Test/img1.jpg ... txt_format/Train/poly_gt_img11.txt txt_format/Test/poly_gt_img1.txt
Polygons are padded to the largest vertex count of their image by repeating their last vertex, which changes neither area, IoU nor rasterization, so they fit one
(N, P, 2)tensor. Words transcribed#(illegible) or with an empty transcription, and polygons with fewer than 3 vertices, are markedignore.Images are read without applying EXIF orientation: the annotations follow the stored pixels (checked on the six EXIF-rotated images).
- Parameters:
root (str | Path) – Directory holding
Images/andtxt_format/.split (Literal['train', 'test']) –
"train"or"test". Default"test".transforms (Callable[[Tensor, TextDetectionTarget], tuple[Tensor, TextDetectionTarget]] | None) – Optional callable
(image, target) -> (image, target).
- Returns:
(3, H, W)uint8RGB and aTextDetectionTargetwith(N, P, 2)polygons.- Return type:
(image, target)
- class torchocr.datasets.FUNSD(root, split='test', transforms=None)[source]#
Bases:
Dataset[tuple[Tensor,TextDetectionTarget]]FUNSD (Jaume et al., ICDAR-OST 2019): 149 train / 50 test noisy scanned business forms with word-level boxes and transcriptions.
A document benchmark, unlike ICDAR-2015 and Total-Text: use it to check how a scene-text model transfers to scans. Words with an empty transcription (check boxes, rules) are marked
ignore.Download and unzip https://guillaumejaume.github.io/FUNSD/dataset.zip (no registration);
rootis the extracteddatasetfolder:root/training_data/{images,annotations}/ root/testing_data/{images,annotations}/
- Parameters:
split (Literal['train', 'test']) –
"train"or"test". Default"test".transforms (Callable[[Tensor, TextDetectionTarget], tuple[Tensor, TextDetectionTarget]] | None) – Optional callable
(image, target) -> (image, target).
- Returns:
(3, H, W)uint8RGB (scans are grayscale, replicated to three channels) and aTextDetectionTargetof axis-aligned(N, 4, 2)word quads.- Return type:
(image, target)
- class torchocr.datasets.LMDBWords(root, label_filter=None, transform=None)[source]#
Bases:
Dataset[tuple[Tensor,str]]Cropped word images in the LMDB layout of clovaai’s deep-text-recognition-benchmark.
This is how the standard recognition corpora circulate (MJSynth, SynthText, IIIT5K, SVT, ICDAR 2013/2015 crops, CUTE80, MLT word crops):
num-samplesholds the count and samplesi = 1..Nare stored underimage-%09d(encoded image bytes) andlabel-%09d(UTF-8 text).Requires the optional
lmdbpackage (pip install torchocr[lmdb]).- Parameters:
label_filter (Callable[[str], bool] | None) – Optional predicate on the label; only matching samples are kept. Evaluated once on all labels at construction (images are not decoded), e.g. to drop words outside a model’s charset.
transform (Callable[[Tensor], Tensor] | None) – Optional callable applied to the
uint8image.
- Returns:
a
(3, H, W)uint8RGB crop and its label.- Return type:
(image, text)