Albumentations transforms for multiple images

username: kabbas570
cooked: <p>Hello, Pytorch community,<br>
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.<br>
Thank You<br>
My code looks like this:</p>
<p>train_transforms = A.Compose(<br>
[<br>
A.Resize(height=IMAGE_HEIGHT, width=IMAGE_WIDTH),<br>
ToTensorV2(),<br>
],<br>
)<br>
class Dataset_(Dataset):<br>
def <strong>init</strong>(self, image_dir, mask_dir,mask_dir1 transform=None):<br>
self.image_dir = image_dir<br>
self.mask_dir = mask_dir<br>
self.mask_dir1 = mask_dir1<br>
self.transform = transform<br>
self.images = os.listdir(image_dir)<br>
self.masks = os.listdir(mask_dir)<br>
self.masks1 = os.listdir(mask_dir1)</p>
<pre><code>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
</code></pre>
<p>def get_loaders(<br>
train_dir=TRAIN_IMG_DIR,<br>
train_maskdir=TRAIN_MASK_DIR,<br>
train_maskdir1=TRAIN_MASK_DIR1,<br>
val_dir=VAL_IMG_DIR,<br>
val_maskdir=VAL_MASK_DIR,<br>
batch_size=BATCH_SIZE,<br>
train_transform=train_transforms,<br>
val_transform=val_transforms,<br>
num_workers=NUM_WORKERS,<br>
pin_memory=PIN_MEMORY,<br>
):<br>
train_ds = Dataset_(<br>
image_dir=train_dir,<br>
mask_dir=train_maskdir,train_maskdir1,<br>
transform=train_transform,<br>
)</p>

username: eqy
cooked: <p>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 <code>self.transform</code>.</p>

username: kabbas570
cooked: <p>Thanks for your reply, I have added the complete code.</p>

username: eqy
cooked: <p>A quick search revealed this github gist floating around…<br>
<a href="https://gist.githubusercontent.com/ternaus/02f581143a9ebe4a89c1c690ab6736f9/raw/a46310e6485eeb47dacc79682a931439706a5426/gistfile1.py" class="onebox" target="_blank" rel="noopener nofollow ugc">https://gist.githubusercontent.com/ternaus/02f581143a9ebe4a89c1c690ab6736f9/raw/a46310e6485eeb47dacc79682a931439706a5426/gistfile1.py</a></p>

username: kabbas570
cooked: <aside class="quote no-group" data-username="kabbas570" data-post="1" data-topic="150501">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/kabbas570/48/49146_2.png" class="avatar"> kabbas570:</div>
<blockquote>
<p>Hello, Pytorch community,</p>
</blockquote>
</aside>
<p>Thank you for your reply, yes its the solution</p>