mxnet.gluon.nn.Dense¶
-
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.
- Parameters
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.
- Inputs:
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).
- Outputs:
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.
Methods
__init__
(units[, activation, use_bias, …])Initialize self.
apply
(fn)Applies
fn
recursively to every child block as well as self.cast
(dtype)Cast this Block to use another data type.
collect_params
([select])Returns a
ParameterDict
containing thisBlock
and all of its children’s Parameters(default), also can returns the selectParameterDict
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.
hybridize
([active])Activates or deactivates
HybridBlock
s recursively.infer_shape
(*args)Infers shape of Parameters from inputs.
infer_type
(*args)Infers data type of Parameters from inputs.
initialize
([init, ctx, verbose, force_reinit])Initializes
Parameter
s of thisBlock
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.
name_scope
()Returns a name space object managing a child
Block
and parameter names.register_child
(block[, name])Registers block as a child of self.
register_forward_hook
(hook)Registers a forward hook on the block.
register_forward_pre_hook
(hook)Registers a forward pre-hook on the block.
save_parameters
(filename)Save parameters to file.
save_params
(filename)[Deprecated] Please use save_parameters.
summary
(*inputs)Print the summary of the model’s output and parameters.
Attributes
name
Name of this
Block
, without ‘_’ in the end.params
Returns this
Block
’s parameter dictionary (does not include its children’s parameters).prefix
Prefix of this
Block
.