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

feat: Added WordGenerator dataset #760

Merged
merged 8 commits into from
Dec 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
refactor: Refactored WordGenerator
  • Loading branch information
fg-mindee committed Dec 26, 2021
commit 3f10d7389118b775da77c39acd1272cc1997b7b9
4 changes: 2 additions & 2 deletions doctr/datasets/generator/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def __init__(
self.vocab = vocab
self.wordlen_range = (min_chars, max_chars)
self._num_samples = num_samples
self.font_family = font_family if isinstance(font_family, list) else [font_family]
self.font_family = font_family if isinstance(font_family, list) else [font_family] # type: ignore[list-item]
# Validate fonts
if isinstance(font_family, list):
for font in self.font_family:
Expand All @@ -149,7 +149,7 @@ def _generate_string(self, min_chars: int, max_chars: int) -> str:
def __len__(self) -> int:
return self._num_samples

def _read_sample(self, index: int) -> Tuple[Any, int]:
def _read_sample(self, index: int) -> Tuple[Any, str]:
# Samples are already cached
if len(self._data) > 0:
pil_img, target = self._data[index]
Expand Down
4 changes: 1 addition & 3 deletions doctr/datasets/generator/pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,4 @@ class WordGenerator(_WordGenerator):
sample_transforms: composable transformations that will be applied to both the image and the target
"""

def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
setattr(self, 'collate_fn', default_collate)
pass
11 changes: 1 addition & 10 deletions doctr/datasets/generator/tensorflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,4 @@ class WordGenerator(_WordGenerator):
sample_transforms: composable transformations that will be applied to both the image and the target
"""

def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)

@staticmethod
def collate_fn(samples):

images, targets = zip(*samples)
images = tf.stack(images, axis=0)

return images, tf.convert_to_tensor(targets)
pass