From f251d9e28b1bbba621ca514c8a5632c7ec951576 Mon Sep 17 00:00:00 2001 From: Loovelj Date: Thu, 3 Jun 2021 17:49:01 +0800 Subject: [PATCH 1/2] Update iaa_augment.py refer https://github.com/MhLiao/DB/pull/259 , luning found this will accelerate the train --- data_loader/modules/iaa_augment.py | 31 +++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/data_loader/modules/iaa_augment.py b/data_loader/modules/iaa_augment.py index bd2588e..e2134c6 100644 --- a/data_loader/modules/iaa_augment.py +++ b/data_loader/modules/iaa_augment.py @@ -48,17 +48,26 @@ def __call__(self, data): def may_augment_annotation(self, aug, data, shape): if aug is None: return data - - line_polys = [] + + all_poly = [] #store all point for poly in data['text_polys']: - new_poly = self.may_augment_poly(aug, shape, poly) - line_polys.append(new_poly) - data['text_polys'] = np.array(line_polys) + for p in poly: + all_poly.append(imgaug.Keypoint(p[0], p[1])) # get all Keypoint + keypoints = aug.augment_keypoints([imgaug.KeypointsOnImage(all_poly, shape=shape)])[0].keypoints #transfrom all point + final_poly = np.array([(p.x, p.y) for p in keypoints]).reshape([-1, 4, 2]) # reshape to boxes + data['text_polys'] =final_poly return data - def may_augment_poly(self, aug, img_shape, poly): - keypoints = [imgaug.Keypoint(p[0], p[1]) for p in poly] - keypoints = aug.augment_keypoints( - [imgaug.KeypointsOnImage(keypoints, shape=img_shape)])[0].keypoints - poly = [(p.x, p.y) for p in keypoints] - return poly +# line_polys = [] +# for poly in data['text_polys']: +# new_poly = self.may_augment_poly(aug, shape, poly) +# line_polys.append(new_poly) +# data['text_polys'] = np.array(line_polys) +# return data + +# def may_augment_poly(self, aug, img_shape, poly): +# keypoints = [imgaug.Keypoint(p[0], p[1]) for p in poly] +# keypoints = aug.augment_keypoints( +# [imgaug.KeypointsOnImage(keypoints, shape=img_shape)])[0].keypoints +# poly = [(p.x, p.y) for p in keypoints] +# return poly From 54e3a0e2c8c6a26a913f941aa8cbc1263b50978e Mon Sep 17 00:00:00 2001 From: Loovelj Date: Fri, 4 Jun 2021 14:38:16 +0800 Subject: [PATCH 2/2] Update iaa_augment.py accelerate augment --- data_loader/modules/iaa_augment.py | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/data_loader/modules/iaa_augment.py b/data_loader/modules/iaa_augment.py index e2134c6..902862f 100644 --- a/data_loader/modules/iaa_augment.py +++ b/data_loader/modules/iaa_augment.py @@ -49,25 +49,11 @@ def may_augment_annotation(self, aug, data, shape): if aug is None: return data - all_poly = [] #store all point + all_poly = [] for poly in data['text_polys']: for p in poly: - all_poly.append(imgaug.Keypoint(p[0], p[1])) # get all Keypoint - keypoints = aug.augment_keypoints([imgaug.KeypointsOnImage(all_poly, shape=shape)])[0].keypoints #transfrom all point - final_poly = np.array([(p.x, p.y) for p in keypoints]).reshape([-1, 4, 2]) # reshape to boxes + all_poly.append(imgaug.Keypoint(p[0], p[1])) + keypoints = aug.augment_keypoints([imgaug.KeypointsOnImage(all_poly, shape=shape)])[0].keypoints + final_poly = np.array([(p.x, p.y) for p in keypoints]).reshape([-1, 4, 2]) data['text_polys'] =final_poly return data - -# line_polys = [] -# for poly in data['text_polys']: -# new_poly = self.may_augment_poly(aug, shape, poly) -# line_polys.append(new_poly) -# data['text_polys'] = np.array(line_polys) -# return data - -# def may_augment_poly(self, aug, img_shape, poly): -# keypoints = [imgaug.Keypoint(p[0], p[1]) for p in poly] -# keypoints = aug.augment_keypoints( -# [imgaug.KeypointsOnImage(keypoints, shape=img_shape)])[0].keypoints -# poly = [(p.x, p.y) for p in keypoints] -# return poly