tfms is a tuple of two Transforms lists. The first one is applied to your x and the second one to your y, so between your two lines, you can add/remove anything you want to each elements of tfms.
you can think of ‘aug_tfms’ as a list of functions that are applied to image. Each function takes an image as input. For 'RandomCrop() you have to provide crop size also eg ‘RandomCrop(224)’.
Hope this helps a bit
This list of functions is applied to x and y, I want to apply something different on y.
@sgugger Basically gave me the anwser but I’m new to python and I don’t know how to add something like RandomFlip to a list of type Transforms
I don’t understand either how the first list of tfms is applied to x and the second to y when my tfms is like that:
([<fastai.transforms.Scale object at 0x7f43fe499470>, <fastai.transforms.RandomFlip object at 0x7f43fe4995f8>, <fastai.transforms.RandomDihedral object at 0x7f43fe499828>, <fastai.transforms.RandomCrop object at 0x7f44054019b0>, <fastai.transforms.Normalize object at 0x7f43fe499f98>, <fastai.transforms.ChannelOrder object at 0x7f44054010f0>],
[<fastai.transforms.Scale object at 0x7f43fe499780>, <fastai.transforms.CenterCrop object at 0x7f43fe4992b0>, <fastai.transforms.Normalize object at 0x7f43fe499f98>, <fastai.transforms.ChannelOrder object at 0x7f43fe499f28>])
y doesn’t have RandomDihedral but y still get the same transform as x when i look at them.
My mistake, I replied too quickly and said something wrong: in your list of transforms, the first part is applied to your training set (that’s why it has the augmentation) and the second part is applied to your validation set.
Each of the transform is applied to x and y if you want to (it depends on the argument you give to tfm_y). If you want to apply something to your ys only, this isn’t supported by fastai so you have to do it before as a preprocessing.
My guess would be a loop over all your ys. You can open an image from its filename with the open_image function. Then you can apply a specific transform to it by just typing img = tfm(img) if tfm is your Transform. Hope that helps, and sorry I misled you before.
Don’t worry about it, since I have to give the names of my images to ImageData.get_ds, does it mean that I have to write the processed images on my disk ? I’d like to avoid that.
That’s what I tried first but I can’t figure out how to only apply it to y.
Let’s take class RandomZoom :
Yes but it only takes x in input, the issue I face is syntax. Because a transform put inside aug_tfms will affect X and Y, I don’t know how to say to my tranform only affect Y.
did you try my example? I see that transform is implemented generically so that x and y both go into transform and come out also. By default transform function is applied on x and y is returned untouched. Maybe I am misundersanding the code and there are more nuances to it.
I didn’t try this code, and I’m not sure aug_func is going to return two arguments so maybe the ,_ is unnecessary but you’ll see that easily when you test.
If you want the transformation to be applied to the validation set too, you have to add it in the second elements of your tfms.
Something like tfms[1].tfms.insert(0,your_custom_tfm) should work (of course you can replace the 0 by your desired position inside the list).
At the end of the day though, it’s probably easier to stop using tfms_from_model and just build your own custom lists.