@albanD, One more question about above code. If I want to define an optimizer, for example an SGD,  what should I do for such a defined network? Here is my code to get the parameters of the network and define the optimizer, but some error prompt when definition:
My code:

parameters = net.parameters()
optimizer = optim.SGD(params = parameters, lr = learning_rate, momentum=momentum, weight_decay = weight_decay)

Error:


ValueError                                Traceback (most recent call last)
 in ()
15 label = torch.randn(1,nc,imageSize[0], imageSize[1])
16 parameters = net.parameters()
—> 17 optimizer = optim.SGD(params = parameters, lr = learning_rate, momentum=momentum, weight_decay = weight_decay)


/home/mohammad/anaconda3/lib/python3.6/site-packages/torch/optim/sgd.py in init(self, params, lr, momentum, dampening, weight_decay)
24         defaults = dict(lr=lr, momentum=momentum, dampening=dampening,
25                         weight_decay=weight_decay)
—> 26         super(SGD, self).init(params, defaults)
27
28     def step(self, closure=None):


/home/mohammad/anaconda3/lib/python3.6/site-packages/torch/optim/optimizer.py in init(self, params, defaults)
56                                     "but one of the params is " + torch.typename(param))
57                 if not param.requires_grad:
—> 58                     raise ValueError("optimizing a parameter that doesn’t "
59                                      “require gradients”)
60                 if param.creator is not None:


ValueError: optimizing a parameter that doesn’t require gradients

So what should I do for repairing this error?
Thanks