lavender99:

no i do not want to apply it randomly, I would like to normalize the full dataset


In that case just apply TF.normalize on your data without the if-clause.



 lavender99:

you mentioned that functional API is better for segmentation tasks


Yes, if you would like to randomly apply transformations, e.g. transforms.RandomCrop, you should use the functional API instead, as you can sample the parameters and apply the same parameters on the image as well as the mask.



 lavender99:

i tried the torchvision.transforms with Unet model it gives me a negative loss while when i used functional API the loss as low at the beginning and then started to be Nan


The torchvision.transforms modules call internally their functional methods, so if you’ve applied exactly the same transformations, both should yield the same results.
However, if it’s possible, you could post the code so that we could have a look.