albumentations
albumentations copied to clipboard
ReplayCompose incorrect behavior with PadIfNeeded
PadIfNeeded update params dependent on target size using function update_params, but ReplayCompose does not process it.
Also some problems with LongestMaxSize, because resize params determined in apply call.
Hi, I found the params of LongestMaxSize and PadIfNeeded is always empty when print data['replay'].
Do you know how to fix it? and are there any alternatives?
My code is
transform = A.ReplayCompose([
A.LongestMaxSize(224),
A.PadIfNeeded(224, 224, border_mode=cv2.BORDER_CONSTANT),
A.RandomCrop(224, 224, always_apply=True),
A.Rotate(limit=(-20,20), border_mode=cv2.BORDER_CONSTANT, p=1.0),
A.MotionBlur(blur_limit=(3,7), p=1.0),
], keypoint_params=A.KeypointParams(format='xy'))
Thanks!
Hello.
That is a some kind of bug, because all transforms must generate all parameters in specific methods, but LongestMaxSize does not do this and calculates this parameters for each call.
Bug with PadIfNeeded happens because this transform update his parameters using function update_params and it is called inside apply_with_params that called after copying all parameters to replay dict.
https://github.com/albumentations-team/albumentations/blob/1f4fa59389f07a692a3934ba5c2c7d3c4e89e9f6/albumentations/core/transforms_interface.py#L89
Simple fix for PadIfNeeded is move apply_with_params call before copying parameters to replay dict and rewrite code like this:
res = self.apply_with_params(params, **kwargs)
if self.deterministic:
if self.targets_as_params:
warn(
self.get_class_fullname() + " could work incorrectly in ReplayMode for other input data"
" because its' params depend on targets."
)
kwargs[self.save_key][id(self)] = deepcopy(params)
return res
Thanks for your advice. And is there any plan to fix this bug in the near release?
Thanks B. R.
Also ran into this issue
Same here but with additional_targets instead of ReplayCompose which should be very similar
This: https://github.com/albumentations-team/albumentations/issues/716#issuecomment-760723917 didn't fix it for me
Also ran into this issue