Transforms on label

I want to implement decrappify in v2. For that I need to implement a transform that only happens on y.

I created my datablock by doing:
DataBlock(blocks=(ImageBlock, ImageBlock)....

In v1 I had to say tfm_y=True whenever I wanted to use the same transforms applied to X on Y. By following this notebook I don’t see that being set anymore, I’m guessing v2 automatically understand what to do from the blocks?

Anyways, in v1 there was a problem that once you defined tfm_y=True all of the transforms would be applied to y without any exception, but again, I need to apply a specific transform only on y, so in v1 I implemented the following hack:

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

How can I achieve something similar in v2?


Note: My intuition was to pass a tuple of lists of transforms to batch_tfms when creating the databunch, but that did not worked.

I don’t understand it fully yet but here is my guess:

In the walkthough about transformers (4) Jeremy explains that you use the class Transfromer or the decorator Transformer. This in combination with a Type annotation in your function (or encoder/decoders function of your class). If you do this it will check if your input is the right type and if so it will apply the function on that part of the tuple.

Not sure if this all still makes sense. Please do look at walkthrough 4. It is really good and made me understood it (I think). The linked post is also quit a thorough explanation.

1 Like

In v2 just create/use a transform that has a type annotation specifying your y data type.

But since I’m doing Image to Image both have a type of TensorImage.

Change the type with a made up class. Like:

Class TensorImageX(TensorImage): pass
Class TensorImageY(TensorImage): pass

And just use these in type annotations

1 Like

I just now realized I can change the class of Y by doing:

ImageBlock(cls=MyClass)

I never noticed this little argument inside ImageBlock :sweat_smile:

1 Like

Hi Igvaz, can you help me in applying jitter transform to my x only.I am badly stuck in this.I want to do Text-SuperResolution and for that I have to add some noises to my input, and not to target(y)…

Does what has been shared here does not work anymore?