albumentations: RandomShadow input type wrong

πŸ› Bug

Weather transformation. For RandomRain, RandomSnow, RandomSunFlare the inputs are just numpy uint8. However, RandomShadow does not allow the same input format.

To Reproduce

albu_shadow = albu.RandomShadow(p=1, num_shadows_lower=1, num_shadows_upper=1, shadow_dimension=5, shadow_roi=(0, 0.5, 1, 1))

x_np = albu_shadow(image=x_np)['image']

Error:

TypeError: Expected Ptr<cv::UMat> for argument img

Expected behavior

It should take the same uint8 numpy array as input.

Environment

  • Albumentations version: 0.4.5
  • Python version: 3.7.6
  • OS (e.g., Linux): Linux
  • How you installed albumentations: pip

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 15 (1 by maintainers)

Most upvoted comments

Very interesting. Problem how pytorch, numpy and OpenCV share memory. Until we find solution how to resolve problem you can use this fix to avoid problem:

x_np = albu_shadow(image=x_np.astype(np.uint8).copy())['image']

You need directly create numpy copy of image before provide it into albumentations transfromation

Good point! Thank you for your comment. I reproduced that problem in the last version. I think we could resolve this problem by just adding np.ascontiguousarray for the image there https://github.com/albumentations-team/albumentations/blob/master/albumentations/core/transforms_interface.py#L97

Please provide a minimal code snippet to reproduce the issue.

Π²Ρ‚, 5 мая 2020 Π³. Π² 11:59 AM, Tsun-Yi Yang notifications@github.com:

Just to be clear. My input is np uint8 array. It does not take it.

β€” You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/albumentations-team/albumentations/issues/614#issuecomment-623939309, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEB6YFMU3CNGD7ZEUXXZKTRP7IQXANCNFSM4MYJXNDA .