Example

Parameter Access in PyTorch Sequential Models

In PyTorch, when a model is defined using the Sequential class, the parameters of a specific layer can be inspected by indexing the model and calling the state_dict() method. For instance, to access the parameters of the third layer in a model named net, one would use net[2].state_dict(). This method returns an OrderedDict containing the layer's parameters, specifically its weight and bias tensors.

0

1

Updated 2026-05-07

Contributors are:

Who are from:

Tags

D2L

Dive into Deep Learning @ D2L