question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Encountering problem when augmented with mask.

See original GitHub issue

🐛 Bug

The augmented mask is not match to the augmented image.

To Reproduce

Steps to reproduce the behavior:

aug = A.Compose([A.OneOf([A.HorizontalFlip(p=0.5), A.VerticalFlip(p=0.5), A.Transpose(p=0.5)], p=1),
      A.RandomRotate90(p=0.5),
      A.GridDistortion(p=0.5)])

augmented  = aug(image=image, mask=label)
image = augmented['image']
label= augmented['mask']

Expected behavior

Environment

  • Albumentations version (e.g., 0.1.8): 0.4.6
  • Python version (e.g., 3.7): python 3.7.4
  • OS (e.g., Linux): Ubuntu 18.04.3 LTS
  • How you installed albumentations (conda, pip, source): conda
  • Any other relevant information:

Additional context

  • original images with mask

image

  • wrong augmented result, the mask is not match to the image

image

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
super233commented, Apr 7, 2021

Sorry, the problem was caused by I called __getitem__() twice to display the result, it’s a stupid problem, thanks for your reply. 😞

0reactions
Dipetcommented, Apr 7, 2021

I again can not reproduce the problem

from torch.utils.data import Dataset
from torchvision import transforms
import numpy as np
import albumentations as A
import matplotlib.pyplot as plt
import random


class CrossMoDADataSet(Dataset):
    def __init__(self):
        self.augment = self.build_augment()
        self.to_tensor_and_normalize = transforms.Compose([transforms.ToTensor()])

    def __len__(self):
        return 1

    def __getitem__(self, index):
        image = np.load("D:\\crossmoda_22_ceT1_40.npy")
        label = np.load("D:\\crossmoda_22_Label_40.npy")

        image = (image / np.max(image) * 255).astype(np.uint8)  # scale the value to [0, 255]
        label = label.astype(np.uint8)
        image_orig = image.copy()
        label_orig = label.copy()

        if self.augment is not None:
            augmented = self.augment(image=image, mask=label)
            image = augmented['image']
            label = augmented['mask']

        return image, label, image_orig, label_orig

    def build_augment(self):
        return A.Compose([A.OneOf([A.HorizontalFlip(p=0.5),
                                   A.VerticalFlip(p=0.5),
                                   A.Transpose(p=0.5)], p=1),
                          A.RandomRotate90(p=0.5),
                          A.GridDistortion(p=0.5)])


seed = 0
random.seed(seed)
np.random.seed(seed)
a, b, c, d = CrossMoDADataSet()[0]

plt.subplot(221, title="original")
plt.imshow(c, vmin=0, vmax=255, cmap="gray")
plt.subplot(222, title="original")
plt.imshow(d, vmin=0, vmax=1, cmap="gray")

plt.subplot(223, title="result")
plt.imshow(a, vmin=0, vmax=255, cmap="gray")
plt.subplot(224, title="result")
plt.imshow(b, vmin=0, vmax=1, cmap="gray")

plt.show()

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

augmented image and corresponding mask does not match
Hi. I would like to ask for assistance. I tried to use Augmentor on the ISBI2012 dataset at ...
Read more >
Must translate autoresizing mask i… | Apple Developer Forums
Hello! I have updated my project to Xcode 13 and iOS 15. Now the app is crashing with an error related to autoresizing...
Read more >
Face mask detection using deep learning: An approach to ...
Face mask detection refers to detect whether a person is wearing a mask or not. In fact, the problem is reverse engineering of...
Read more >
Why does my ARCore AugmentedFace mask flicker?
I found out that flickering stops if I render more than 1 mask. For example, if I write augmentedFaceRenderer.draw() and noseObject.draw() ...
Read more >
Masks Work. Really. We'll Show You How - The New York Times
The augmented-reality experience lets you stand inside the magnified fibers of an N95 respirator to see how it filters aerosols. Launch aerosols ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found