MONAI
MONAI copied to clipboard
Instancenorm must have defaults affine=True
For many monai networks (including Unet) we use the default normalization - Instancenorm , using a short string 'instance' or Norm.INSTANCE https://github.com/Project-MONAI/MONAI/blob/fb6d95058c26bcbaaf44e5e8cb75625ebf9f67ac/monai/networks/nets/unet.py#L124
But the way it's implemented via Monai 'factory', it will init with the default Instancenorm options (affine=False), meaning - no Trainable parameters (scale and bias), for 2D and 3D https://pytorch.org/docs/stable/generated/torch.nn.InstanceNorm2d.html
The default should be affine=True (for any segmentation / classification networks). For Batchnorm, Groupnorm (the default pytorch option is affine=True).
It's unclear why pytorch decided to treat Instancenorm differently: https://github.com/pytorch/pytorch/issues/22755
This implies that our implementation of Unet (and Convolution, and ResidualBlocks) is somewhat unconventional (non-standard). It works, but deviates from a common practice. To use a standard instancenorm in monai, one has to use a verbose form ('instance', {affine:True}) to override the default setting.
We can change the default behavior to (affine=True) with a smallfix: https://github.com/Project-MONAI/MONAI/pull/5220
However, this change the behavior of Unet, Convolution helper, etc, when using instancenorm (to get previous behaviour one will need to use ('instance', {affine:False})