Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
GreatV committed Jul 29, 2024
1 parent 37d8e9f commit cca394f
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions ppocr/data/imaug/iaa_augment.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ def build(self, args, root=True):
elif isinstance(args, list):
if root:
sequence = [self.build(value, root=False) for value in args]
return A.Compose(
sequence, keypoint_params=A.KeypointParams(format="xy")
return A.ReplayCompose(
sequence,
keypoint_params=A.KeypointParams(
format="xy", remove_invisible=False
),
)
else:
return getattr(A, args[0])(
Expand Down Expand Up @@ -71,24 +74,26 @@ def __call__(self, data):
image = data["image"]

if self.augmenter:
# note: Affine could work incorrectly in ReplayMode if set_deterministic(True)
# self.augmenter.set_deterministic(True)
data["image"] = self.augmenter(image=image)["image"]
data = self.may_augment_annotation(data)
transformed_data = self.augmenter(image=image)
data["image"] = transformed_data["image"]
replay = transformed_data["replay"]
data = self.may_augment_annotation(data, replay)
return data

def may_augment_annotation(self, data):
def may_augment_annotation(self, data, replay):
if self.augmenter is None:
return data

line_polys = []
for poly in data["polys"]:
new_poly = self.may_augment_poly(data["image"], poly)
new_poly = self.may_augment_poly(data["image"], poly, replay)
line_polys.append(new_poly)
data["polys"] = np.array(line_polys)
return data

def may_augment_poly(self, image, poly):
def may_augment_poly(self, image, poly, replay):
keypoints = [(p[0], p[1]) for p in poly]
poly = self.augmenter(image=image, keypoints=keypoints)["keypoints"]
poly = A.ReplayCompose.replay(replay, image=image, keypoints=keypoints)[
"keypoints"
]
return poly

0 comments on commit cca394f

Please sign in to comment.