Skip to content

refractor transforms #98

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

Merged
merged 7 commits into from
Mar 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@ The supported recognition models and their overall performance on the public ben
## Notes

### Change Log
- 2023/03/23
1. Add dynamic loss scaler support, compatiable with drop overflow update. To enable dynamic loss scaler, please set `type` of `loss_scale` as `dynamic`. A yaml example can be viewed in `configs/rec/crnn/crnn_icdar15.yaml`

- 2023/03/20
1. Arg names changed: `output_keys` -> `output_columns`, `num_keys_to_net` -> `num_columns_to_net`
2. Data pipeline updated
Expand Down
3 changes: 1 addition & 2 deletions mindocr/data/transforms/det_transforms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""
transform for text detection tasks.
TODO: rewrite copied code
transforms for text detection tasks.
"""
import random
import warnings
Expand Down
51 changes: 23 additions & 28 deletions mindocr/data/transforms/iaa_augment.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,35 @@
"""
This code is refer from:
https://github.com/WenmuZhou/DBNet.pytorch/blob/master/data_loader/modules/iaa_augment.py
iaa transform
"""
import numpy as np
import imgaug
import imgaug.augmenters as iaa

__all__ = ['IaaAugment']

class AugmenterBuilder(object):
def __init__(self):
pass

def build(self, args, root=True):
if args is None or len(args) == 0:
return None
elif isinstance(args, list):
if root:
sequence = [self.build(value, root=False) for value in args]
return iaa.Sequential(sequence)
else:
return getattr(iaa, args[0])(
*[self.to_tuple_if_list(a) for a in args[1:]])
elif isinstance(args, dict):
cls = getattr(iaa, args['type'])
return cls(**{
k: self.to_tuple_if_list(v)
for k, v in args['args'].items()
})
def compose_iaa_transforms(args, root=True):
if (args is None) or (len(args) == 0):
return None
elif isinstance(args, list):
if root:
sequence = [compose_iaa_transforms(value, root=False) for value in args]
return iaa.Sequential(sequence)
else:
raise RuntimeError('unknown augmenter arg: ' + str(args))
return getattr(iaa, args[0])( *[_list_to_tuple(a) for a in args[1:]])
elif isinstance(args, dict):
cls = getattr(iaa, args['type'])
return cls(**{
k: _list_to_tuple(v)
for k, v in args['args'].items()
})
else:
raise ValueError('Unknown augmenter arg: ' + str(args))


def to_tuple_if_list(self, obj):
if isinstance(obj, list):
return tuple(obj)
return obj
def _list_to_tuple(obj):
if isinstance(obj, list):
return tuple(obj)
return obj


class IaaAugment():
Expand All @@ -56,7 +51,7 @@ def __init__(self, augmenter_args=None, **kwargs):
'size': [0.5, 3]
}
}]
self.augmenter = AugmenterBuilder().build(augmenter_args)
self.augmenter = compose_iaa_transforms(augmenter_args)

def __call__(self, data):
image = data['image']
Expand Down