Solved by AreTor in post #3 
              
              
                I am sorry, I have not specified that I need the solution in C++ (I thought the C++ tag was enough). 
Anyway, I managed to solve the problem: 
    auto conv = torch::nn::Conv2d(
        torch::nn::Conv2dOptions(3, 16, 3)
    );
    conv->requires_grad_(false);
    conv->weight.zero_();