Connection

Conv2DActiv

class chainercv.links.connection.Conv2DActiv(in_channels, out_channels, ksize=None, stride=1, pad=0, dilate=1, nobias=False, initialW=None, initial_bias=None, activ=<function relu>)

Convolution2D –> Activation

This is a chain that does two-dimensional convolution and applies an activation.

The arguments are the same as those of chainer.links.Convolution2D except for activ.

Example

There are sevaral ways to initialize a Conv2DActiv.

  1. Give the first three arguments explicitly:

    >>> l = Conv2DActiv(5, 10, 3)
    
  2. Omit in_channels or fill it with None:

    In these ways, attributes are initialized at runtime based on the channel size of the input.

    >>> l = Conv2DActiv(10, 3)
    >>> l = Conv2DActiv(None, 10, 3)
    
Parameters:
  • in_channels (int or None) – Number of channels of input arrays. If None, parameter initialization will be deferred until the first forward data pass at which time the size will be determined.
  • out_channels (int) – Number of channels of output arrays.
  • ksize (int or tuple of ints) – Size of filters (a.k.a. kernels). ksize=k and ksize=(k, k) are equivalent.
  • stride (int or tuple of ints) – Stride of filter applications. stride=s and stride=(s, s) are equivalent.
  • pad (int or tuple of ints) – Spatial padding width for input arrays. pad=p and pad=(p, p) are equivalent.
  • dilate (int or tuple of ints) – Dilation factor of filter applications. dilate=d and dilate=(d, d) are equivalent.
  • nobias (bool) – If True, then this link does not use the bias term.
  • initialW (callable) – Initial weight value. If None, the default initializer is used. May also be a callable that takes numpy.ndarray or cupy.ndarray and edits its value.
  • initial_bias (callable) – Initial bias value. If None, the bias is set to 0. May also be a callable that takes numpy.ndarray or cupy.ndarray and edits its value.
  • activ (callable) – An activation function. The default value is chainer.functions.relu(). If this is None, no activation is applied (i.e. the activation is the identity function).

Conv2DBNActiv

class chainercv.links.connection.Conv2DBNActiv(in_channels, out_channels, ksize=None, stride=1, pad=0, dilate=1, nobias=True, initialW=None, initial_bias=None, activ=<function relu>, bn_kwargs={})

Convolution2D –> Batch Normalization –> Activation

This is a chain that sequentially apllies a two-dimensional convolution, a batch normalization and an activation.

The arguments are the same as that of chainer.links.Convolution2D except for activ and bn_kwargs. bn_kwargs can include comm key and a communicator of ChainerMN as the value to use chainermn.links.MultiNodeBatchNormalization. If comm is not included in bn_kwargs, chainer.links.BatchNormalization link from Chainer is used. Note that the default value for the nobias is changed to True.

Example

There are sevaral ways to initialize a Conv2DBNActiv.

  1. Give the first three arguments explicitly:

    >>> l = Conv2DBNActiv(5, 10, 3)
    
  2. Omit in_channels or fill it with None:

    In these ways, attributes are initialized at runtime based on the channel size of the input.

    >>> l = Conv2DBNActiv(10, 3)
    >>> l = Conv2DBNActiv(None, 10, 3)
    
Parameters:
  • in_channels (int or None) – Number of channels of input arrays. If None, parameter initialization will be deferred until the first forward data pass at which time the size will be determined.
  • out_channels (int) – Number of channels of output arrays.
  • ksize (int or tuple of ints) – Size of filters (a.k.a. kernels). ksize=k and ksize=(k, k) are equivalent.
  • stride (int or tuple of ints) – Stride of filter applications. stride=s and stride=(s, s) are equivalent.
  • pad (int or tuple of ints) – Spatial padding width for input arrays. pad=p and pad=(p, p) are equivalent.
  • dilate (int or tuple of ints) – Dilation factor of filter applications. dilate=d and dilate=(d, d) are equivalent.
  • nobias (bool) – If True, then this link does not use the bias term.
  • initialW (callable) – Initial weight value. If None, the default initializer is used. May also be a callable that takes numpy.ndarray or cupy.ndarray and edits its value.
  • initial_bias (callable) – Initial bias value. If None, the bias is set to 0. May also be a callable that takes numpy.ndarray or cupy.ndarray and edits its value.
  • activ (callable) – An activation function. The default value is chainer.functions.relu(). If this is None, no activation is applied (i.e. the activation is the identity function).
  • bn_kwargs (dict) – Keyword arguments passed to initialize chainer.links.BatchNormalization. If a ChainerMN communicator (CommunicatorBase) is given with the key :obj:`comm, MultiNodeBatchNormalization will be used for the batch normalization. Otherwise, BatchNormalization will be used.