Trying to implement data augmentation into a semantic segmentation training, I tried to apply some transformations to the same image and mask. If I rotate the image, I need to rotate the mask as well. The thing is RandomRotation, RandomHorizontalFlip, etc. use random seeds.
I read somewhere this seeds are generated at the instantiation of the transforms. I’m trying to figure out how to ensure that both image and mask are transformed in the same way. This is a “simple” example of the workflow I’ve tried, which results in image and mask with different rotations.
It should show the same angle and would thus rotate both images with it.
If that’s the case your plot might show the images in a wrong order or you might be shuffling the images somewhere afterwards.
So you have confirmed that indeed the same angle is used for both rotations and that the plotting is not an issue. In this case the correspondence between input and target seems to be broken somewhere else and we might need a minimal and executable code snippet to reproduce and isolate the issue.
What is the correct way to load a label image which is saved in PascalVoc format?
In my approach, the dual transform with v2 works well if I just read JPEG image and PNG mask (mode=P), but in this case the mask does now not work with CrossEntropyLoss.
So my solution is to just add mask = mask.to(torch.long).squeeze() after the transforms.
Is there a better way to achieve the same? The docs for the Mask class is relative sparse so far.