-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
A.Compose
, A.Sequential
components run multiple times inside of A.OneOf
#1051
Comments
|
@BloodAxe Thank you for advice! I couldn't search proper keyword like "nested" which wasn't familiar with me. :) 1.tf = A.OneOf([
#A.Sequential(self._get_resize_crop(**kwargs), p=1.0), # <-- this line still makes error.
A.Sequential(self._get_crop_resize(**kwargs), p=1.0),
A.Sequential(self._get_pad_crop_resize(**kwargs), p=1.0),
A.Sequential(self._get_pad_resize_crop(**kwargs), p=1.0),
], p=1.0)
return A.Compose(tf, p=1.0) When print inside of transform components, print(tf) nothing seemed to matter,
OneOf([
Sequential([
RandomCrop(always_apply=False, p=1.0, height=780, width=1280),
Resize(always_apply=False, p=1.0, height=480, width=640, interpolation=1),
], p=1.0),
Sequential([
PadIfNeeded(always_apply=False, p=1.0, min_height=1920, min_width=1920, pad_height_divisor=None, pad_width_divisor=None, border_mode=4, value=None, mask_value=None),
RandomCrop(always_apply=False, p=1.0, height=780, width=1280),
Resize(always_apply=False, p=1.0, height=480, width=640, interpolation=1),
], p=1.0),
Sequential([
PadIfNeeded(always_apply=False, p=1.0, min_height=1920, min_width=1920, pad_height_divisor=None, pad_width_divisor=None, border_mode=4, value=None, mask_value=None),
Resize(always_apply=False, p=1.0, height=780, width=1280, interpolation=1),
RandomCrop(always_apply=False, p=1.0, height=480, width=640),
], p=1.0),
], p=1.0) but result images are same. 2.There is something even strange. When run this code without annotation, tf = A.OneOf([
A.Sequential(self._get_resize_crop(**kwargs), p=1.0),
A.Sequential(self._get_crop_resize(**kwargs), p=1.0),
A.Sequential(self._get_pad_crop_resize(**kwargs), p=1.0),
A.Sequential(self._get_pad_resize_crop(**kwargs), p=1.0),
], p=1.0)
return A.Compose(tf, p=1.0) print(tf)
OneOf([
Sequential([
Resize(always_apply=False, p=1.0, height=780, width=1280, interpolation=1),
RandomCrop(always_apply=False, p=1.0, height=480, width=640),
], p=1.0),
Sequential([
RandomCrop(always_apply=False, p=1.0, height=780, width=1280),
Resize(always_apply=False, p=1.0, height=480, width=640, interpolation=1),
], p=1.0),
Sequential([
PadIfNeeded(always_apply=False, p=1.0, min_height=1920, min_width=1920, pad_height_divisor=None, pad_width_divisor=None, border_mode=4, value=None, mask_value=None),
RandomCrop(always_apply=False, p=1.0, height=780, width=1280),
Resize(always_apply=False, p=1.0, height=480, width=640, interpolation=1),
], p=1.0),
Sequential([
PadIfNeeded(always_apply=False, p=1.0, min_height=1920, min_width=1920, pad_height_divisor=None, pad_width_divisor=None, border_mode=4, value=None, mask_value=None),
Resize(always_apply=False, p=1.0, height=780, width=1280, interpolation=1),
RandomCrop(always_apply=False, p=1.0, height=480, width=640),
], p=1.0),
], p=1.0) Note that but error raises ValueError: Requested crop size (780, 1280) is larger than the image size (480, 640) Entire error description
ValueError Traceback (most recent call last)
<ipython-input-17-4725b0ed649d> in <module>()
50
51 start = time.time()
---> 52 image_train_debug, mask_train_debug = aug_fn_for_train(image, mask)
53 end = time.time()
54 print('training augmentation time cost (per image):', end - start)
6 frames
<ipython-input-16-90611d3e3759> in <lambda>(image, mask)
23
24 def get_train_augmentation(self):
---> 25 return lambda image, mask: list(self.train_augmentation(image=image, mask=mask).values())
26
27 def get_valid_augmentation(self):
/content/gdrive/MyDrive/ColabWorkspace/albumentations/albumentations/core/composition.py in __call__(self, force_apply, *args, **data)
213
214 for idx, t in enumerate(transforms):
--> 215 data = t(force_apply=force_apply, **data)
216
217 if check_each_transform:
/content/gdrive/MyDrive/ColabWorkspace/albumentations/albumentations/core/composition.py in __call__(self, **data)
604 def __call__(self, **data):
605 for t in self.transforms:
--> 606 data = t(**data)
607 return data
/content/gdrive/MyDrive/ColabWorkspace/albumentations/albumentations/core/transforms_interface.py in __call__(self, force_apply, *args, **kwargs)
95 )
96 kwargs[self.save_key][id(self)] = deepcopy(params)
---> 97 return self.apply_with_params(params, **kwargs)
98
99 return kwargs
/content/gdrive/MyDrive/ColabWorkspace/albumentations/albumentations/core/transforms_interface.py in apply_with_params(self, params, force_apply, **kwargs)
110 target_function = self._get_target_function(key)
111 target_dependencies = {k: kwargs[k] for k in self.target_dependence.get(key, [])}
--> 112 res[key] = target_function(arg, **dict(params, **target_dependencies))
113 else:
114 res[key] = None
/content/gdrive/MyDrive/ColabWorkspace/albumentations/albumentations/augmentations/crops/transforms.py in apply(self, img, h_start, w_start, **params)
45
46 def apply(self, img, h_start=0, w_start=0, **params):
---> 47 return F.random_crop(img, self.height, self.width, h_start, w_start)
48
49 def get_params(self):
/content/gdrive/MyDrive/ColabWorkspace/albumentations/albumentations/augmentations/crops/functional.py in random_crop(img, crop_height, crop_width, h_start, w_start)
26 "Requested crop size ({crop_height}, {crop_width}) is "
27 "larger than the image size ({height}, {width})".format(
---> 28 crop_height=crop_height, crop_width=crop_width, height=height, width=width
29 )
30 )
ValueError: Requested crop size (780, 1280) is larger than the image size (480, 640) |
A.Compose
, A.Sequential
components run multiple times inside of A.OneOf
The second sequential operation could cause this:
Here you trying to get a random crop of size 1280x780. Depending on your dataset this may or may be not guaranteed that all images has sufficient size. If some image comes in smaller size, this operation will raise an exception (Like you see above). Could be your case. |
If problem was came from dataset as you said @BloodAxe, problem should occur when I run a single 1.tf = A.OneOf([
A.Sequential(self._get_resize_crop(**kwargs), p=1.0),
#A.Sequential(self._get_crop_resize(**kwargs), p=1.0),
#A.Sequential(self._get_pad_crop_resize(**kwargs), p=1.0),
#A.Sequential(self._get_pad_resize_crop(**kwargs), p=1.0),
], p=1.0) ['/content/gdrive/MyDrive/data/pedestrian/surface_masking/Surface_021/MP_SEL_SUR_002440.jpg', '/content/gdrive/MyDrive/data/pedestrian/surface_masking/Surface_021/MASK/MP_SEL_SUR_002440.png'] 2.tf = A.OneOf([
#A.Sequential(self._get_resize_crop(**kwargs), p=1.0),
A.Sequential(self._get_crop_resize(**kwargs), p=1.0),
#A.Sequential(self._get_pad_crop_resize(**kwargs), p=1.0),
#A.Sequential(self._get_pad_resize_crop(**kwargs), p=1.0),
], p=1.0) ['/content/gdrive/MyDrive/data/pedestrian/surface_masking/Surface_021/MP_SEL_SUR_002440.jpg', '/content/gdrive/MyDrive/data/pedestrian/surface_masking/Surface_021/MASK/MP_SEL_SUR_002440.png'] 3.tf = A.OneOf([
#A.Sequential(self._get_resize_crop(**kwargs), p=1.0),
#A.Sequential(self._get_crop_resize(**kwargs), p=1.0),
A.Sequential(self._get_pad_crop_resize(**kwargs), p=1.0),
#A.Sequential(self._get_pad_resize_crop(**kwargs), p=1.0),
], p=1.0) ['/content/gdrive/MyDrive/data/pedestrian/surface_masking/Surface_021/MP_SEL_SUR_002440.jpg', '/content/gdrive/MyDrive/data/pedestrian/surface_masking/Surface_021/MASK/MP_SEL_SUR_002440.png'] 4.tf = A.OneOf([
#A.Sequential(self._get_resize_crop(**kwargs), p=1.0),
#A.Sequential(self._get_crop_resize(**kwargs), p=1.0),
#A.Sequential(self._get_pad_crop_resize(**kwargs), p=1.0),
A.Sequential(self._get_pad_resize_crop(**kwargs), p=1.0),
], p=1.0) ['/content/gdrive/MyDrive/data/pedestrian/surface_masking/Surface_021/MP_SEL_SUR_002440.jpg', '/content/gdrive/MyDrive/data/pedestrian/surface_masking/Surface_021/MASK/MP_SEL_SUR_002440.png'] But when |
Hm, actually I was able to reproduce this issue. We will investigate this. Thanks for reporting! |
I think problem in |
Thanks, @Dipet's reply helped to fix solve the issue. albumentations/albumentations/core/composition.py Lines 37 to 58 in 6c733c4
Do you have a plan to make |
Yes, I am working on this problem. |
🐛 Bug
Hi, I used
A.OneOf
method on myA.Compose
objects,but when I run entire pipeline, all components of
A.Compose
objects are called altogether.To Reproduce
Steps to reproduce the behavior:
Expected behavior
Doing augmentation from randomly selected one of the composed pipeline.
Environment
conda
,pip
, source): colab default installedAdditional context
The text was updated successfully, but these errors were encountered: