-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
-
-
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
MultiMasks Augmentation - Issue with torch.from_numpy() - Abumentation #1935
Labels
Comments
FrsECM
changed the title
MultiMasks Augmentation - Issue with torch.from_numpy() - Abumentation >=1.4.13
MultiMasks Augmentation - Issue with torch.from_numpy() - Abumentation
Sep 18, 2024
Thanks, I can reproduce the bug. Will take a look ASAP. |
In [4]: import albumentations as A
...: from albumentations.pytorch import ToTensorV2
...: import cv2
...: import numpy as np
...:
...: transform = A.Compose([
...: A.HorizontalFlip(p=1),
...: A.ToFloat(max_value=255),
...: ToTensorV2()
...: ],is_check_shapes=False)
...:
...:
...: image = 255*np.ones((3096,2048,3),dtype=np.uint8)
...: masks = [np.ones((3096,2048),dtype=np.uint8) for i in range(2)]
...:
...: transformed = transform(image=image,masks=masks)
In [5]: A.__version__
Out[5]: '1.4.15' Could you please check with the latest version? |
For me it's not fixed with the last version : import albumentations as A
from albumentations.pytorch import ToTensorV2
import cv2
import numpy as np
import torch
from albumentations.core.types import NUM_MULTI_CHANNEL_DIMENSIONS
################### WORKARROUND THAT WORK
class ToTensor(ToTensorV2):
def apply_to_mask(self, mask: np.ndarray, **params: A.Any) -> torch.Tensor:
if self.transpose_mask and mask.ndim == NUM_MULTI_CHANNEL_DIMENSIONS:
mask = mask.transpose(2, 0, 1)
return torch.from_numpy(np.ascontiguousarray(mask))
transform_buggy = A.Compose([
A.HorizontalFlip(p=1),
A.ToFloat(max_value=255),
ToTensorV2()
],is_check_shapes=False)
transform_fixed = A.Compose([
A.HorizontalFlip(p=1),
A.ToFloat(max_value=255),
ToTensor()
],is_check_shapes=False)
image = 255*np.ones((3096,2048,3),dtype=np.uint8)
masks = [np.ones((3096,2048),dtype=np.uint8) for i in range(2)]
print(A.__version__)
try:
transformed = transform_fixed(image=image,masks=masks)
except:
print('transform_fixed failed')
try:
transformed_buggy = transform_buggy(image=image,masks=masks)
except:
print('transform_buggy failed')
print('The end') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
Hello !
I have a problem when i use HorizontalFlip combined with multiple masks and ToTensorV2 augmentation.
To Reproduce
You can use this piece of code to reproduce :
Steps to reproduce the behavior:
Expected behavior
I expect the augmentation to be applied without error
Actual behavior
I have an exception :
Screenshots
You can see bellow that it's working with v1.4.12
With v1.4.13, it is no longer working :
Additional context
I suspect this commit to be the cause of the problem :
Workarround :
The text was updated successfully, but these errors were encountered: