Transform only on input

I’m using carvana dataset (originally for object segmentation) to generate cars from masks.

I’m using a U-net where the inputs are the masks and the outputs are the cars.

My masks are in png format, single channel images with pixels being 0s or 1s. I’ve written a custom transform (TfmPixel) that multiply these pixels by 255, but here is the thing, I only want to apply this transform to the inputs!

I’m also using the other standard transforms, so I need to set tfm_y=True, currently I’ve not found a way to apply some transforms only on the input and some on input and output.

Of course I workaround is to create the masks already in the 0-255 format, but I feel this is a functionality that can be used in a variety of cases.

Is there any way of achieving this in the current fastai library?
If not, I’m more than willing to help implement this functionality, I might need some help to do so but I can get there :sweat_smile:

Something that I tried is to call two successives .transform with different parameters, but that didn’t worked so well…

...
        .label_from_func(get_y_fn)
        .transform(get_transforms(), tfm_y=True, size=size)
        .transform([[mask2img()], []], tfm_y=False)
...

Maybe I should not even care about this because of v2?

As I cannot find a reasonable solution for my problem, I implemented the hack:

class TfmPixelXOnly(TfmPixel):
    def __call__(self, *args, **kwargs):
        kwargs.pop('use_on_y', None)
        return super().__call__(*args, use_on_y=False, **kwargs)
1 Like