Table Of Contents
Table Of Contents


class mxnet.gluon.nn.Dense(units, activation=None, use_bias=True, flatten=True, dtype='float32', weight_initializer=None, bias_initializer='zeros', in_units=0, **kwargs)[source]

Just your regular densely-connected NN layer.

Dense implements the operation: output = activation(dot(input, weight) + bias) where activation is the element-wise activation function passed as the activation argument, weight is a weights matrix created by the layer, and bias is a bias vector created by the layer (only applicable if use_bias is True).

Note: the input must be a tensor with rank 2. Use flatten to convert it to rank 2 manually if necessary.

  • units (int) – Dimensionality of the output space.

  • activation (str) – Activation function to use. See help on Activation layer. If you don’t specify anything, no activation is applied (ie. “linear” activation: a(x) = x).

  • use_bias (bool, default True) – Whether the layer uses a bias vector.

  • flatten (bool, default True) – Whether the input tensor should be flattened. If true, all but the first axis of input data are collapsed together. If false, all but the last axis of input data are kept the same, and the transformation applies on the last axis.

  • dtype (str or np.dtype, default 'float32') – Data type of output embeddings.

  • weight_initializer (str or Initializer) – Initializer for the kernel weights matrix.

  • bias_initializer (str or Initializer) – Initializer for the bias vector.

  • in_units (int, optional) – Size of the input data. If not specified, initialization will be deferred to the first time forward is called and in_units will be inferred from the shape of input data.

  • prefix (str or None) – See document of Block.

  • params (ParameterDict or None) – See document of Block.

  • data: if flatten is True, data should be a tensor with shape (batch_size, x1, x2, …, xn), where x1 * x2 * … * xn is equal to in_units. If flatten is False, data should have shape (x1, x2, …, xn, in_units).

  • out: if flatten is True, out will be a tensor with shape (batch_size, units). If flatten is False, out will have shape (x1, x2, …, xn, units).

__init__(units, activation=None, use_bias=True, flatten=True, dtype='float32', weight_initializer=None, bias_initializer='zeros', in_units=0, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.


__init__(units[, activation, use_bias, …])

Initialize self.


Applies fn recursively to every child block as well as self.


Cast this Block to use another data type.


Returns a ParameterDict containing this Block and all of its children’s Parameters(default), also can returns the select ParameterDict which match some given regular expressions.

export(path[, epoch])

Export HybridBlock to json format that can be loaded by SymbolBlock.imports, mxnet.mod.Module or the C++ interface.

forward(x, *args)

Defines the forward computation.

hybrid_forward(F, x, weight[, bias])

Overrides to construct symbolic graph for this Block.


Activates or deactivates HybridBlock s recursively.


Infers shape of Parameters from inputs.


Infers data type of Parameters from inputs.

initialize([init, ctx, verbose, force_reinit])

Initializes Parameter s of this Block and its children.

load_parameters(filename[, ctx, …])

Load parameters from file previously saved by save_parameters.

load_params(filename[, ctx, allow_missing, …])

[Deprecated] Please use load_parameters.


Returns a name space object managing a child Block and parameter names.

register_child(block[, name])

Registers block as a child of self.


Registers a forward hook on the block.


Registers a forward pre-hook on the block.


Save parameters to file.


[Deprecated] Please use save_parameters.


Print the summary of the model’s output and parameters.



Name of this Block, without ‘_’ in the end.


Returns this Block’s parameter dictionary (does not include its children’s parameters).


Prefix of this Block.