How to normalize convolutional weights in pytorch?
I have a CNN in pytorch and I need to normalize the convolution weights (filters) with L2 norm in each iteration. What is the most efficient way to do this? 

Basically, in my particular experiment I need to replace the filters with their normalized value in the model (during both training and test).

I am not sure if I have understood your question correctly. But if I were asked to normalize the weights of NN layer at each iteration, I would do something like as follows.

for ite in range(100): # training iteration

    # write your code to train your model
    # update the parameters using optimizer.step() and then normalize

    with torch.no_grad():
        model.conv.weight.div_(torch.norm(model.conv.weight, dim=2, keepdim=True)


Here, the model.conv refers to the Convolution layer of the model. Please make sure, you give the dim parameter in torch.norm() function appropriately. I just set it to 2 to give you an example.

For example, if you are using Conv1d, then the shape of the weight parameters would be (out_channels, in_channels, kW), then you can set dim=2.
