Skip to content
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

Global config padding value for masks? #710

Open
mitalbert opened this issue Aug 19, 2020 · 4 comments
Open

Global config padding value for masks? #710

mitalbert opened this issue Aug 19, 2020 · 4 comments

Comments

@mitalbert
Copy link

Is there a way to change the default padding value from 0 to another value for all segmentation mask augmentations without manually changing the default passed values in the library functions?

The problem occurs when I use augmentations such as geometric affine transformations, where new pixel values are added to the image (e.g. bottom right part of the image below).
image
For these newly added pixels I get zeroes in the segmentation maps, however the value 0 is used for another class and the ignore label value is 255. So I would like to set the default padding value for segmentations to 255 so that all added pixels in the paddings are ignored during the training.

@jspaezp
Copy link

jspaezp commented Sep 18, 2020

You might want to take a look at the fillcolor parameter, exemplified in Affine.

fillcolor (number or tuple of number or list of number or imgaug.ALL or imgaug.parameters.StochasticParameter, optional) 

link to the documentation: https://imgaug.readthedocs.io/en/latest/source/api_augmenters_pillike.html#imgaug.augmenters.pillike.Affine
let me know if it works for you

Best

@mitalbert
Copy link
Author

mitalbert commented Sep 18, 2020

Hi @jspaezp
Thanks for the suggestion. The problem with pillike is, as mentioned in the page you linked:

This augmenter can currently only transform image-data. Batches containing heatmaps, segmentation maps and coordinate-based augmentables will be rejected with an error. Use Affine if you have to transform such inputs.

And when using iaa.Affine as suggested, there is the cval argument (similar to fillcolor) that can be passed, however this value is used to fill the image and not the segmentation map. My problem is with segmentation maps in Cityscapes-like datasets, where the 0 value is used for labeling the road and 255 is used for void.

Whether the image will be padded by random, constant values or reflection, is not that relevant as the padding in segmentation, which can be confusing. I looked into the library and could not find a nice way to set the segmentation pad value, but I hope for a proper workaround until hopefully it will be added in the next release.

@jspaezp
Copy link

jspaezp commented Sep 18, 2020

ohhh, I see the issue (on the question it seemed like the problem was in the image side and not the segmaps).

Well ... It might not be ideal for your application but you could try to re-code your segmap before passing it to the augmentator and the decode it later.

something like ...

import numpy as np

# Creating a fake segmap
foo = np.zeros(shape = (6,6))
foo[2:5, 2:5] = 255
foo
# array([[  0.,   0.,   0.,   0.,   0.,   0.],
#        [  0.,   0.,   0.,   0.,   0.,   0.],
#        [  0.,   0., 255., 255., 255.,   0.],
#        [  0.,   0., 255., 255., 255.,   0.],
#        [  0.,   0., 255., 255., 255.,   0.],
#        [  0.,   0.,   0.,   0.,   0.,   0.]])

# Possibly define this as a function ...
streets = foo == 0
voids = foo == 255
foo[streets] = 255
foo[voids] = 0

foo
# array([[255., 255., 255., 255., 255., 255.],
#        [255., 255., 255., 255., 255., 255.],
#        [255., 255.,   0.,   0.,   0., 255.],
#        [255., 255.,   0.,   0.,   0., 255.],
#        [255., 255.,   0.,   0.,   0., 255.],
#        [255., 255., 255., 255., 255., 255.]])

let me know if it helps,
Best

@mitalbert
Copy link
Author

Thanks and sorry for ambiguous description. That is my workaround right now and it works. I was hoping either passing this padding value to imgaug or get help for writing my own setter for SegmentationMapsOnImage however it seems that one needs to consider many things before setting the cval(s) in that class, because those methods are used for many augmentations and changing it might mess things up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants