How to limit the weight and bias of nn.Conv3d as non-negative?

Hi all,
I am new to Pytorch and I am not familiar with it yet. I run the experiment of my paper on Pytorch using Conv3d (the 3D convolution module) as one of the major layers. According to the source codes, the self.weight and self.bias parameters of Conv3d are initialized uniformly within a range of (-bound, bound). I would like to limit the two parameters to non-negative values. How could I make it? Thanks in advance.


You could use a method from torch.nn.init and apply it on the parameters as e.g. seen here and used here.
Alternatively, you could directly copy the desired initial values into the parameter by using:

with torch.no_grad():