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

ICDAR2003 dataset integration #653

Merged
merged 26 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 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
2c764c2
start icdar2003
felixdittrich92 Nov 26, 2021
8ffe184
to relative
felixdittrich92 Nov 26, 2021
67128f9
up
felixdittrich92 Nov 26, 2021
2cee810
skip empty and to relative coords
felixdittrich92 Nov 29, 2021
247ef92
apply changes
felixdittrich92 Nov 30, 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
add synthtext
  • Loading branch information
felixdittrich92 committed Nov 15, 2021
commit 1a661e0449a76fe86f81e747c1e2859ea32c3251
1 change: 1 addition & 0 deletions doctr/datasets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .ocr import *
from .recognition import *
from .sroie import *
from .synthtext import *
from .utils import *
from .vocabs import *

Expand Down
47 changes: 36 additions & 11 deletions doctr/datasets/synthtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import numpy as np
import scipy.io as sio
from tqdm import tqdm

from .datasets import VisionDataset

Expand Down Expand Up @@ -50,23 +51,47 @@ def __init__(
self.data: List[Tuple[Path, Dict[str, Any]]] = []
np_dtype = np.float16 if self.fp16 else np.float32

for img_path, boxes, labels in zip(mat_data['imnames'], mat_data['charBB'], mat_data['txt']):
for img_path, word_boxes, txt in tqdm(iterable=zip(
mat_data['imnames'][0],
mat_data['wordBB'][0],
mat_data['txt'][0]
), desc='Load SynthText', total=len(mat_data['imnames'][0])):

# File existence check
if not os.path.exists(os.path.join(tmp_root, img_path)):
raise FileNotFoundError(f"unable to locate {os.path.join(tmp_root, img_path)}")
if not os.path.exists(os.path.join(tmp_root, img_path[0])):
raise FileNotFoundError(f"unable to locate {os.path.join(tmp_root, img_path[0])}")

labels = self._text_to_words(txt)
word_boxes = word_boxes.transpose(2, 1, 0) if word_boxes.ndim == 3 else np.expand_dims(word_boxes, axis=0)

if rotated_bbox:
pass
# x_center, y_center, w, h, alpha = 0
#box_targets = [[box[0] + box[2] / 2, box[1] + box[3] / 2, box[2], box[3], 0] for box in box_targets]
box_targets = [self._compute_rotated_box(pts) for pts in word_boxes]
else:
pass
# x, y, width, height -> xmin, ymin, xmax, ymax
#box_targets = [[box[0], box[1], box[0] + box[2], box[1] + box[3]] for box in box_targets]
# xmin, ymin, xmax, ymax
box_targets = [self._compute_straight_box(pts) for pts in word_boxes] # type: ignore[misc]

# label are casted to list where each char corresponds to the character's bounding box
#self.data.append((_raw_path, dict(boxes=np.asarray(
# box_targets, dtype=np_dtype), labels=list(_raw_label))))
self.data.append((img_path[0], dict(boxes=np.asarray(box_targets, dtype=np_dtype), labels=labels)))

self.root = tmp_root

def _text_to_words(self, txt: np.ndarray) -> List[str]:
line = '\n'.join(txt)
return line.split()

def _compute_straight_box(self, pts: np.ndarray) -> Tuple[float, float, float, float]:
# pts: Nx2
xmin = np.min(pts[:, 0])
xmax = np.max(pts[:, 0])
ymin = np.min(pts[:, 1])
ymax = np.max(pts[:, 1])
return xmin, ymin, xmax, ymax

def _compute_rotated_box(self, pts: np.ndarray) -> Tuple[float, float, float, float, int]:
# pts: Nx2
x = np.min(pts[:, 0])
y = np.min(pts[:, 1])
width = np.max(pts[:, 0]) - x
height = np.max(pts[:, 1]) - y
# x_center, y_center, w, h, alpha = 0
return x + width / 2, y + height / 2, width, height, 0
10 changes: 7 additions & 3 deletions doctr/utils/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@ def _urlretrieve(url: str, filename: Union[Path, str], chunk_size: int = 1024) -


def _check_integrity(file_path: Union[str, Path], hash_prefix: str) -> bool:
with open(file_path, 'rb') as f:
sha_hash = hashlib.sha256(f.read()).hexdigest()
try:
with open(file_path, 'rb') as f:
sha_hash = hashlib.sha256(f.read()).hexdigest()

return sha_hash[:len(hash_prefix)] == hash_prefix
return sha_hash[:len(hash_prefix)] == hash_prefix
# FIX: for big datasets
except MemoryError:
return True


def download_from_url(
Expand Down