deep-head-pose icon indicating copy to clipboard operation
deep-head-pose copied to clipboard

named_modules will return multiple times of the same parameter

Open CharlesNord opened this issue 6 years ago • 0 comments

https://github.com/natanielruiz/deep-head-pose/blob/175dff7849b3cdb342b48253bba401a7a9ef0e87/code/train_hopenet.py#L58

Hi, in your code, you use model.named_modules() to get the parameter generator, thus control the learning rate of different layers, but I find that in a model that contains multiple modules, it will return first the global module, then return different element of the module. For example:

net = nn.Sequential(nn.Linear(3,4), nn.Linear(4,5))
[(name, module) for name, module in net.named_modules()]

returns:

[('', Sequential(
    (0): Linear(in_features=3, out_features=4, bias=True)
    (1): Linear(in_features=4, out_features=5, bias=True)
  )),
 ('0', Linear(in_features=3, out_features=4, bias=True)),
 ('1', Linear(in_features=4, out_features=5, bias=True))]

So, in your inner loop of get_non_ignored_params, you will yield multiple times of one parameter. I think we can directly call the module.named_parameters() to get all the parameters:

net = nn.Sequential(nn.Linear(3,4), nn.Linear(4,5))
[(name, module) for name, module in net.named_parameters()]

will return

['0.weight', '0.bias', '1.weight', '1.bias']

CharlesNord avatar Mar 04 '19 09:03 CharlesNord