# Albumentations transforms for multiple images

**URL:** <https://discuss.pytorch.org/t/albumentations-transforms-for-multiple-images/150501>\
**Category:** Uncategorized\
**Created:** [April 30, 2022, 11:02pm UTC](https://discuss.pytorch.org/t/albumentations-transforms-for-multiple-images/150501 "2022-04-30T23:02:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kabbas570](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/kabbas570/32/49146_2.png) [@kabbas570](https://discuss.pytorch.org/u/kabbas570)\
**Post date:** [April 30, 2022, 11:02pm UTC](https://discuss.pytorch.org/t/albumentations-transforms-for-multiple-images/150501/1 "2022-04-30T23:02:20Z")

</div>

Hello, Pytorch community,  
I want to apply some argumentations transform for one image and two ground truths say mask and mask1. Transformations are applied on image and mask but mask1 is not undergoing through any transformation.  
Thank You  
My code looks like this:

train\_transforms = A.Compose(  
[  
A.Resize(height=IMAGE\_HEIGHT, width=IMAGE\_WIDTH),  
ToTensorV2(),  
],  
)  
class Dataset\_(Dataset):  
def **init** (self, image\_dir, mask\_dir,mask\_dir1 transform=None):  
self.image\_dir = image\_dir  
self.mask\_dir = mask\_dir  
self.mask\_dir1 = mask\_dir1  
self.transform = transform  
self.images = os.listdir(image\_dir)  
self.masks = os.listdir(mask\_dir)  
self.masks1 = os.listdir(mask\_dir1)

```
def __len__ (self):
    return len(self.images)

def __getitem__ (self, index):
    img_path = os.path.join(self.image_dir, self.images[index])
    mask_path = os.path.join(self.mask_dir, self.images[index][:-4]+'_gt.npy')
    mask_path1 = os.path.join(self.mask_dir1, self.images[index][:-4]+'_gt.npy')
    image = np.load(img_path,allow_pickle=True, fix_imports=True)
    mask = np.load(mask_path,allow_pickle=True, fix_imports=True)
    mask1 = np.load(mask_path1,allow_pickle=True, fix_imports=True)
    #mask=np.expand_dims(mask, axis=0)
    if self.transform is not None:
        augmentations = self.transform(image=image,mask=mask,mask1=mask1)
        image = augmentations["image"]
        mask = augmentations["mask"]
       mask1 = augmentations["mask1"]
       return image, mask, mask1

```

def get\_loaders(  
train\_dir=TRAIN\_IMG\_DIR,  
train\_maskdir=TRAIN\_MASK\_DIR,  
train\_maskdir1=TRAIN\_MASK\_DIR1,  
val\_dir=VAL\_IMG\_DIR,  
val\_maskdir=VAL\_MASK\_DIR,  
batch\_size=BATCH\_SIZE,  
train\_transform=train\_transforms,  
val\_transform=val\_transforms,  
num\_workers=NUM\_WORKERS,  
pin\_memory=PIN\_MEMORY,  
):  
train\_ds = Dataset\_(  
image\_dir=train\_dir,  
mask\_dir=train\_maskdir,train\_maskdir1,  
transform=train\_transform,  
)

---

<div class="post-metadata">

**Author:** ![eqy](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/eqy/32/46233_2.png) [@eqy](https://discuss.pytorch.org/u/eqy)\
**Post date:** [May 1, 2022, 6:59am UTC](https://discuss.pytorch.org/t/albumentations-transforms-for-multiple-images/150501/2 "2022-05-01T06:59:51Z")

</div>

Could you post a minimal code snippet illustrating the issue (can be with placeholder data/masks etc.) as it’s not really debuggable without visibility into `self.transform`.

---

<div class="post-metadata">

**Author:** ![kabbas570](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/kabbas570/32/49146_2.png) [@kabbas570](https://discuss.pytorch.org/u/kabbas570)\
**Post date:** [May 1, 2022, 4:19pm UTC](https://discuss.pytorch.org/t/albumentations-transforms-for-multiple-images/150501/3 "2022-05-01T16:19:06Z")

</div>

Thanks for your reply, I have added the complete code.

---

<div class="post-metadata">

**Author:** ![eqy](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/eqy/32/46233_2.png) [@eqy](https://discuss.pytorch.org/u/eqy)\
**Post date:** [May 4, 2022, 12:15am UTC](https://discuss.pytorch.org/t/albumentations-transforms-for-multiple-images/150501/4 "2022-05-04T00:15:08Z")

</div>

A quick search revealed this github gist floating around…  
[https://gist.githubusercontent.com/ternaus/02f581143a9ebe4a89c1c690ab6736f9/raw/a46310e6485eeb47dacc79682a931439706a5426/gistfile1.py](https://gist.githubusercontent.com/ternaus/02f581143a9ebe4a89c1c690ab6736f9/raw/a46310e6485eeb47dacc79682a931439706a5426/gistfile1.py)

---

<div class="post-metadata">

**Author:** ![kabbas570](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/kabbas570/32/49146_2.png) [@kabbas570](https://discuss.pytorch.org/u/kabbas570)\
**Post date:** [May 9, 2022, 2:56pm UTC](https://discuss.pytorch.org/t/albumentations-transforms-for-multiple-images/150501/5 "2022-05-09T14:56:46Z")

</div>

> [@kabbas570](#):
>
> Hello, Pytorch community,

Thank you for your reply, yes its the solution
