Parameters

Neural network parameters are often ndarrays. A ndarray, such as the weight of a dense layer, is presented as a Parameter object in Gluon. Then ParameterDict is used store multiple Parameter’s.

Parameter(name[, grad_req, shape, dtype, …]) A Container holding parameters (weights) of Blocks.
ParameterDict([prefix, shared]) A dictionary managing a set of parameters.

Example

Import modules and construct a MLP.

>>> from mxnet import np, npx
>>> from mxnet.gluon import nn
>>> npx.set_np()
>>> net = nn.Sequential()
>>> net.add(nn.Dense(10, activation='relu'),
...         nn.Dense(2))

Access the weight of the first layer (uninitialized yet)

>>> print(net[0].weight)
Parameter dense0_weight (shape=(10, -1), dtype=float32)

Get all parameters

>>> print(net.collect_params())
sequential0_ (
  Parameter dense0_weight (shape=(10, -1), dtype=float32)
  Parameter dense0_bias (shape=(10,), dtype=float32)
  Parameter dense1_weight (shape=(2, -1), dtype=float32)
  Parameter dense1_bias (shape=(2,), dtype=float32)
)

We can

initializer Weight initializer.