How to get a specific parameter matrix (tensor) of a model by its name in pytorch?
I have trained my model in pytorch. Now I want to extract a specific parameters tensor by its name (not all tensors). How can I do that?
print(myModel.parameters)

OUTPUT:
&lt;bound method Module.parameters of ANN(
  (fc1): Linear(in_features=2, out_features=4, bias=True)
  (fc2): Linear(in_features=4, out_features=1, bias=True)
)&gt;

For example, I only want to get fc1.weight and fc1.bias.

You can access sub-modules with the dot notation directly, while parameters returns a iterator over all tensors without providing keys:
&gt;&gt;&gt; myModel.fc1.weight
&gt;&gt;&gt; myModel.fc1.bias

