Table Of Contents
Table Of Contents

Conv2D

class mxnet.gluon.nn.Conv2D(channels, kernel_size, strides=(1, 1), padding=(0, 0), dilation=(1, 1), groups=1, layout='NCHW', activation=None, use_bias=True, weight_initializer=None, bias_initializer='zeros', in_channels=0, **kwargs)[source]

2D convolution layer (e.g. spatial convolution over images).

This layer creates a convolution kernel that is convolved with the layer input to produce a tensor of outputs. If use_bias is True, a bias vector is created and added to the outputs. Finally, if activation is not None, it is applied to the outputs as well.

If in_channels is not specified, Parameter initialization will be deferred to the first time forward is called and in_channels will be inferred from the shape of input data.

Parameters:
  • channels (int) – The dimensionality of the output space, i.e. the number of output channels (filters) in the convolution.
  • kernel_size (int or tuple/list of 2 int) – Specifies the dimensions of the convolution window.
  • strides (int or tuple/list of 2 int,) – Specify the strides of the convolution.
  • padding (int or a tuple/list of 2 int,) – If padding is non-zero, then the input is implicitly zero-padded on both sides for padding number of points
  • dilation (int or tuple/list of 2 int) – Specifies the dilation rate to use for dilated convolution.
  • groups (int) – Controls the connections between inputs and outputs. At groups=1, all inputs are convolved to all outputs. At groups=2, the operation becomes equivalent to having two conv layers side by side, each seeing half the input channels, and producing half the output channels, and both subsequently concatenated.
  • layout (str, default 'NCHW') – Dimension ordering of data and weight. Only supports ‘NCHW’ and ‘NHWC’ layout for now. ‘N’, ‘C’, ‘H’, ‘W’ stands for batch, channel, height, and width dimensions respectively. Convolution is applied on the ‘H’ and ‘W’ dimensions.
  • in_channels (int, default 0) – The number of input channels to this layer. If not specified, initialization will be deferred to the first time forward is called and in_channels will be inferred from the shape of input data.
  • activation (str) – Activation function to use. See Activation(). If you don’t specify anything, no activation is applied (ie. “linear” activation: a(x) = x).
  • use_bias (bool) – Whether the layer uses a bias vector.
  • weight_initializer (str or Initializer) – Initializer for the weight weights matrix.
  • bias_initializer (str or Initializer) – Initializer for the bias vector.
Inputs:
  • data: 4D input tensor with shape (batch_size, in_channels, height, width) when layout is NCHW. For other layouts shape is permuted accordingly.
Outputs:
  • out: 4D output tensor with shape (batch_size, channels, out_height, out_width) when layout is NCHW. out_height and out_width are calculated as:

    out_height = floor((height+2*padding[0]-dilation[0]*(kernel_size[0]-1)-1)/stride[0])+1
    out_width = floor((width+2*padding[1]-dilation[1]*(kernel_size[1]-1)-1)/stride[1])+1
    
__init__(channels, kernel_size, strides=(1, 1), padding=(0, 0), dilation=(1, 1), groups=1, layout='NCHW', activation=None, use_bias=True, weight_initializer=None, bias_initializer='zeros', in_channels=0, **kwargs)[source]

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

Methods

__init__(channels, kernel_size[, strides, …]) 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 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.
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 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.
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.