Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICDAR2013 dataset integration #662

Merged
merged 37 commits into from
Dec 10, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
e7122a5
start synth
felixdittrich92 Nov 13, 2021
4fa0aff
cleanup
felixdittrich92 Nov 15, 2021
3ffdcc5
Merge branch 'mindee:main' into main
felixdittrich92 Nov 15, 2021
b74f06a
start synth
felixdittrich92 Nov 15, 2021
1a661e0
add synthtext
felixdittrich92 Nov 15, 2021
6270c93
add docu and tests
felixdittrich92 Nov 15, 2021
d74f148
apply code factor suggestions
felixdittrich92 Nov 15, 2021
9099e95
apply changes
felixdittrich92 Nov 15, 2021
23eca0d
Merge branch 'mindee:main' into main
felixdittrich92 Nov 15, 2021
7ba31e1
clean
felixdittrich92 Nov 15, 2021
02a8104
Merge branch 'mindee:main' into main
felixdittrich92 Nov 15, 2021
6955110
Merge branch 'mindee:main' into main
felixdittrich92 Nov 16, 2021
8fbeb30
Merge branch 'mindee:main' into main
felixdittrich92 Nov 16, 2021
7408935
Merge branch 'mindee:main' into main
felixdittrich92 Nov 17, 2021
a2b0fbc
Merge branch 'mindee:main' into main
felixdittrich92 Nov 19, 2021
a9cbd14
Merge branch 'mindee:main' into main
felixdittrich92 Nov 20, 2021
b245443
Merge branch 'mindee:main' into main
felixdittrich92 Nov 23, 2021
0cb2f7b
Merge branch 'mindee:main' into main
felixdittrich92 Nov 23, 2021
743c54a
Merge branch 'mindee:main' into main
felixdittrich92 Nov 25, 2021
1c1cbcb
Merge branch 'mindee:main' into main
felixdittrich92 Nov 25, 2021
cfbd898
Merge branch 'mindee:main' into main
felixdittrich92 Nov 30, 2021
8787f74
Merge branch 'mindee:main' into main
felixdittrich92 Nov 30, 2021
47ed381
Merge branch 'mindee:main' into main
felixdittrich92 Nov 30, 2021
eb7f59c
Merge branch 'mindee:main' into main
felixdittrich92 Dec 2, 2021
efaa2c0
Merge branch 'mindee:main' into main
felixdittrich92 Dec 3, 2021
f7288ca
Merge branch 'mindee:main' into main
felixdittrich92 Dec 3, 2021
044f523
Merge branch 'mindee:main' into main
felixdittrich92 Dec 7, 2021
9dc3983
Merge branch 'mindee:main' into main
felixdittrich92 Dec 7, 2021
fc4c2d9
Merge branch 'mindee:main' into main
felixdittrich92 Dec 7, 2021
78b8d27
Merge branch 'mindee:main' into main
felixdittrich92 Dec 8, 2021
d26341b
Merge branch 'mindee:main' into main
felixdittrich92 Dec 9, 2021
6338cac
Merge branch 'mindee:main' into main
felixdittrich92 Dec 10, 2021
351e008
opening ic13
felixdittrich92 Nov 30, 2021
f046b63
opening ic13
felixdittrich92 Nov 30, 2021
ebb7a82
update tests
felixdittrich92 Nov 30, 2021
dc4a033
change tests
felixdittrich92 Nov 30, 2021
e2d15f2
apply changes
felixdittrich92 Dec 10, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update tests
  • Loading branch information
felixdittrich92 committed Dec 10, 2021
commit ebb7a827610abb7b1b6352327dd92e621d71bfda
41 changes: 18 additions & 23 deletions doctr/datasets/ic13.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
# See LICENSE or go to <https://www.apache.org/licenses/LICENSE-2.0.txt> for full license details.

import os
from typing import Any, Callable, List, Optional, Tuple, Dict
from pathlib import Path
from typing import Any, Callable, Dict, List, Optional, Tuple

import numpy as np

Expand All @@ -15,18 +15,19 @@


class IC13(AbstractDataset):
"""IC13 dataset from
`"ICDAR 2013 Robust Reading Competition" <https://rrc.cvc.uab.es/>`_.
"""IC13 dataset from `"ICDAR 2013 Robust Reading Competition" <https://rrc.cvc.uab.es/>`_.
Example::
>>> # NOTE: You need to download both image and label parts from Focused Scene Text challenge Task2.1 2013-2015.
>>> # structure: - img_folder: all images (part1 and part2) | - label_folder: all labels (part1 and part2)
>>> from doctr.datasets import IC13
>>> train_set = IC13(img_folder="/path/to/images", label_folder="/path/to/labels", train=True)
>>> train_set = IC13(img_folder="/path/to/Challenge2_Training_Task12_Images",
>>> label_folder="/path/to/Challenge2_Training_Task1_GT")
>>> img, target = train_set[0]
>>> test_set = IC13(img_folder="/path/to/Challenge2_Test_Task12_Images",
>>> label_folder="/path/to/Challenge2_Test_Task1_GT")
>>> img, target = test_set[0]
Args:
img_folder: folder with all the images of the dataset
label_folder: folder with all annotation files for the images
train: whether the subset should be the training one
sample_transforms: composable transformations that will be applied to each image
rotated_bbox: whether polygons should be considered as rotated bounding box (instead of straight ones)
"""
Expand All @@ -35,7 +36,6 @@ def __init__(
self,
img_folder: str,
label_folder: str,
train: bool = True,
sample_transforms: Optional[Callable[[Any], Any]] = None,
rotated_bbox: bool = False,
) -> None:
Expand All @@ -51,30 +51,25 @@ def __init__(
np_dtype = np.float32

img_names = os.listdir(img_folder)
split = int(len(img_names) * 0.9)
img_names = img_names[:split] if train else img_names[split:]

for img_name in img_names:

img_path = Path(img_folder, img_name)
label_path = Path(label_folder, Path(img_name).stem + ".txt")
label_path = Path(label_folder, "gt_" + Path(img_name).stem + ".txt")
felixdittrich92 marked this conversation as resolved.
Show resolved Hide resolved

with open(label_path, "r") as f:
_lines = [[x for x in line.split(',')] for line in f.readlines()]
_lines = [[x.replace("\"", "").replace(",", "") for x in line.split()] for line in f.readlines()]
felixdittrich92 marked this conversation as resolved.
Show resolved Hide resolved
labels = [line[4].strip() for line in _lines]
felixdittrich92 marked this conversation as resolved.
Show resolved Hide resolved
coords = np.array([np.array(list(map(int, line[:8]))).reshape((4, 2))
for line in _lines], dtype=np_dtype)
# xmin, ymin, xmax, ymax
box_targets = np.array([list(map(int, line[:4])) for line in _lines], dtype=np_dtype)
if rotated_bbox:
# x_center, y_center, w, h, alpha = 0
mins = coords.min(axis=1)
maxs = coords.max(axis=1)
box_targets = np.concatenate(
((mins + maxs) / 2, maxs - mins, np.zeros((coords.shape[0], 1))), axis=1)
else:
# xmin, ymin, xmax, ymax
box_targets = np.concatenate((coords.min(axis=1), coords.max(axis=1)), axis=1)

self.data.append((img_path, dict(boxes=box_targets, languages=vocab_lang, labels=labels)))
# x_center, y_center, width, height, 0
box_targets = np.array([[coords[0] + (coords[2] - coords[0]) / 2,
coords[1] + (coords[3] - coords[1]) / 2,
(coords[2] - coords[0]),
(coords[3] - coords[1]), 0.0] for coords in box_targets], dtype=np_dtype)

self.data.append((img_path, dict(boxes=box_targets, labels=labels)))

def __getitem__(self, index: int) -> Tuple[np.ndarray, Dict[str, Any]]:
img, target = self._read_sample(index)
Expand Down
15 changes: 7 additions & 8 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,13 @@ def mock_ic13(tmpdir_factory, mock_image_stream):
file = BytesIO(mock_image_stream)
image_folder = tmpdir_factory.mktemp("images")
label_folder = tmpdir_factory.mktemp("labels")
labels = ["0,168,48,166,43,219,2,216,Symbols,-\n",
"102,131,951,142,958,251,126,255,Latin,TENTURE\n",
"1030,146,1745,142,1747,241,1029,246,Latin,MURALE\n",
"72,653,786,648,787,793,85,812,Latin,L'atelier\n",
"839,648,1226,650,1228,784,843,788,Latin,Kern\n"]
for i in range(10):
# labels needs same name as image
fn_l = label_folder.join(f"mock_image_file_{i}.txt")
labels = ["1309, 2240, 1440, 2341, 'I'\n",
"800, 2240, 1440, 2341, 'am'\n",
"500, 2240, 1440, 2341, 'a'\n",
"900, 2240, 1440, 2341, 'jedi'\n",
"400, 2240, 1440, 2341, '!'"]
for i in range(5):
fn_l = label_folder.join(f"gt_mock_image_file_{i}.txt")
with open(fn_l, 'w') as f:
f.writelines(labels)
fn_i = image_folder.join(f"mock_image_file_{i}.jpg")
Expand Down
10 changes: 5 additions & 5 deletions tests/pytorch/test_datasets_pt.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,18 +204,18 @@ def test_charactergenerator():


@pytest.mark.parametrize(
"train, size, rotate",
"size, rotate",
[
[True, 9, True], # Actual set has 9000 samples
[False, 1, False], # Actual set has 1000 samples
[5, True], # Actual set has 229 train and 233 test samples
[5, False]

],
)
def test_ic13_dataset(mock_ic13, train, size, rotate):
def test_ic13_dataset(mock_ic13, size, rotate):
input_size = (512, 512)
ds = datasets.IC13(
*mock_ic13,
sample_transforms=Resize(input_size),
train=train,
rotated_bbox=rotate,
)

Expand Down
11 changes: 6 additions & 5 deletions tests/tensorflow/test_datasets_tf.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,20 +190,21 @@ def test_charactergenerator():


@pytest.mark.parametrize(
"train, size, rotate",
"size, rotate",
[
[True, 9, True], # Actual set has 9000 samples
[False, 1, False], # Actual set has 1000 samples
[5, True], # Actual set has 229 train and 233 test samples
[5, False]

],
)
def test_icdar19_dataset(mock_ic13, train, size, rotate):
def test_ic13_dataset(mock_ic13, size, rotate):
input_size = (512, 512)
ds = datasets.IC13(
*mock_ic13,
sample_transforms=Resize(input_size),
train=train,
rotated_bbox=rotate,
)

assert len(ds) == size
img, target = ds[0]
assert isinstance(img, tf.Tensor)
Expand Down