Chainer
v2.0.2
  • Installation Guide
  • Chainer Tutorial
  • Chainer Reference Manual
    • Core functionalities
    • Utilities
    • Assertion and Testing
    • Standard Function implementations
    • Standard Link implementations
      • Learnable connections
        • chainer.links.Bias
        • chainer.links.Bilinear
        • chainer.links.Convolution2D
        • chainer.links.ConvolutionND
        • chainer.links.Deconvolution2D
        • chainer.links.DeconvolutionND
        • chainer.links.DepthwiseConvolution2D
        • chainer.links.DilatedConvolution2D
        • chainer.links.EmbedID
        • chainer.links.GRU
        • chainer.links.Highway
        • chainer.links.Inception
        • chainer.links.InceptionBN
        • chainer.links.Linear
        • chainer.links.LSTM
        • chainer.links.MLPConvolution2D
        • chainer.links.NStepBiGRU
        • chainer.links.NStepBiLSTM
        • chainer.links.NStepBiRNNReLU
        • chainer.links.NStepBiRNNTanh
        • chainer.links.NStepGRU
        • chainer.links.NStepLSTM
        • chainer.links.NStepRNNReLU
        • chainer.links.NStepRNNTanh
        • chainer.links.Scale
        • chainer.links.StatefulGRU
        • chainer.links.StatefulPeepholeLSTM
        • chainer.links.StatelessLSTM
      • Activation/loss/normalization functions with parameters
      • Machine learning models
      • Pre-trained models
    • Optimizers
    • Serializers
    • Function hooks
    • Weight Initializers
    • Dataset examples
    • Iterator examples
    • Trainer extensions
    • Trainer triggers
    • Caffe Reference Model Support
    • Visualization of Computational Graph
    • Environment variables
  • Upgrade Guide from v1 to v2
  • Contribution Guide
  • API Compatibility Policy
  • Tips and FAQs
  • Comparison with Other Frameworks
  • License
Chainer
  • Docs »
  • Chainer Reference Manual »
  • Standard Link implementations »
  • chainer.links.MLPConvolution2D
  • Edit on GitHub

chainer.links.MLPConvolution2D¶

class chainer.links.MLPConvolution2D(self, in_channels, out_channels, ksize=None, stride=1, pad=0, activation=relu.relu, conv_init=None, bias_init=None)[source]¶

Two-dimensional MLP convolution layer of Network in Network.

This is an “mlpconv” layer from the Network in Network paper. This layer is a two-dimensional convolution layer followed by 1x1 convolution layers and interleaved activation functions.

Note that it does not apply the activation function to the output of the last 1x1 convolution layer.

Parameters:
  • in_channels (int or None) – Number of channels of input arrays. If it is None or omitted, parameter initialization will be deferred until the first forward data pass at which time the size will be determined.
  • out_channels (tuple of ints) – Tuple of number of channels. The i-th integer indicates the number of filters of the i-th convolution.
  • ksize (int or pair of ints) – Size of filters (a.k.a. kernels) of the first convolution layer. ksize=k and ksize=(k, k) are equivalent.
  • stride (int or pair of ints) – Stride of filter applications at the first convolution layer. stride=s and stride=(s, s) are equivalent.
  • pad (int or pair of ints) – Spatial padding width for input arrays at the first convolution layer. pad=p and pad=(p, p) are equivalent.
  • activation (function) – Activation function for internal hidden units. Note that this function is not applied to the output of this link.
  • conv_init – An initializer of weight matrices passed to the convolution layers. This option must be specified as a keyword argument.
  • bias_init – An initializer of bias vectors passed to the convolution layers. This option must be specified as a keyword argument.

See: Network in Network.

Variables:activation (function) – Activation function.

Methods

__call__(x)[source]¶

Computes the output of the mlpconv layer.

Parameters:x (Variable) – Input image.
Returns:Output of the mlpconv layer.
Return type:Variable
__getitem__(index)[source]¶

Returns the child at given index.

Parameters:index (int) – Index of the child in the list.
Returns:The index-th child link.
Return type:Link
__len__()[source]¶

Returns the number of children.

__iter__()[source]¶
add_link(link)[source]¶

Registers a child link and adds it to the tail of the list.

Parameters:link (Link) – The link object to be registered.
add_param(name, shape=None, dtype=<type 'numpy.float32'>, initializer=None)[source]¶

Registers a parameter to the link.

Deprecated since version v2.0.0: Assign a Parameter object directly to an attribute within an initialization scope instead. For example, the following code

link.add_param('W', shape=(5, 3))

can be replaced by the following assignment.

with self.init_scope():
    link.W = chainer.Parameter(None, (5, 3))

The latter one is easier for IDEs to keep track of the attribute’s type.

Parameters:
  • name (str) – Name of the parameter. This name is also used as the attribute name.
  • shape (int or tuple of ints) – Shape of the parameter array. If it is omitted, the parameter variable is left uninitialized.
  • dtype – Data type of the parameter array.
  • initializer – If it is not None, the data is initialized with the given initializer. If it is an array, the data is directly initialized by it. If it is callable, it is used as a weight initializer. Note that in these cases, dtype argument is ignored.
add_persistent(name, value)[source]¶

Registers a persistent value to the link.

The registered value is saved and loaded on serialization and deserialization. The value is set to an attribute of the link.

Parameters:
  • name (str) – Name of the persistent value. This name is also used for the attribute name.
  • value – Value to be registered.
addgrads(link)[source]¶
append(link)[source]¶

Registers a child link and adds it to the tail of the list.

This is equivalent to add_link(). This method has been added to emulate the list interface.

Parameters:link (Link) – The link object to be regsitered.
children()[source]¶
cleargrads()[source]¶

Clears all gradient arrays.

This method should be called before the backward computation at every iteration of the optimization.

copy()[source]¶
copyparams(link)[source]¶
disable_update()[source]¶

Disables update rules of all parameters under the link hierarchy.

This method sets the :attr:~chainer.UpdateRule.enabled` flag of the update rule of each parameter variable to False.

enable_update()[source]¶

Enables update rules of all parameters under the link hierarchy.

This method sets the enabled flag of the update rule of each parameter variable to True.

init_scope(*args, **kwds)[source]¶

Creates an initialization scope.

This method returns a context manager object that enables registration of parameters (and links for Chain) by an assignment. A Parameter object can be automatically registered by assigning it to an attribute under this context manager.

Example

In most cases, the parameter registration is done in the initializer method. Using the init_scope method, we can simply assign a Parameter object to register it to the link.

class MyLink(chainer.Link):
    def __init__(self):
        super().__init__()
        with self.init_scope():
            self.W = chainer.Parameter(0, (10, 5))
            self.b = chainer.Parameter(0, (5,))
links(skipself=False)[source]¶
namedlinks(skipself=False)[source]¶
namedparams(include_uninit=True)[source]¶
params(include_uninit=True)[source]¶
register_persistent(name)[source]¶

Registers an attribute of a given name as a persistent value.

This is a convenient method to register an existing attribute as a persistent value. If name has been already registered as a parameter, this method removes it from the list of parameter names and re-registers it as a persistent value.

Parameters:name (str) – Name of the attribute to be registered.
serialize(serializer)[source]¶
to_cpu()[source]¶
to_gpu(device=None)[source]¶
zerograds()[source]¶

Initializes all gradient arrays by zero.

This method can be used for the same purpose of cleargrads, but less efficient. This method is left for backward compatibility.

Deprecated since version v1.15: Use cleargrads() instead.

Attributes

update_enabled¶

True if at least one parameter has an update rule enabled.

within_init_scope¶

True if the current code is inside of an initialization scope.

See init_scope() for the details of the initialization scope.

xp¶

Array module for this link.

Depending on which of CPU/GPU this link is on, this property returns numpy or cupy.

Next Previous

© Copyright 2015, Preferred Networks, inc. and Preferred Infrastructure, inc.. Revision 0f6e5bd1.

Built with Sphinx using a theme provided by Read the Docs.