nakulp21:

I don’t want to use torchvision.transforms to normalize the image, instead I want to add a layer at the beginning that does the same work for me.


Batchnorm layers do not work in the same way as the transforms.Normalize transformation, since the latter uses static statistics while the batchnorm layer uses running estimates during validation and the batch statistics during training.
However, in case you still want to add this layer:
based on the model description, I assume you are using a custom nn.Module, which uses self.encoder1 as one submodule.
If that’s the case, add self.bn1 = nn.BatchNorm2d(3) to the __init__ method of UNet and call it in the forward method before executing self.encoder1.