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>)[source]

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 several 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, groups=1, nobias=True, initialW=None, initial_bias=None, activ=<function relu>, bn_kwargs={})[source]

Convolution2D –> Batch Normalization –> Activation

This is a chain that sequentially applies 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 several 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.

  • groups (int) – The number of groups to use grouped convolution. The default is one, where grouped convolution is not used.

  • 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 comm, MultiNodeBatchNormalization will be used for the batch normalization. Otherwise, BatchNormalization will be used.

SEBlock

class chainercv.links.connection.SEBlock(n_channel, ratio=16)[source]

A squeeze-and-excitation block.

This block is part of squeeze-and-excitation networks. Channel-wise multiplication weights are inferred from and applied to input feature map. Please refer to the original paper for more details.

Parameters
  • n_channel (int) – The number of channels of the input and output array.

  • ratio (int) – Reduction ratio of n_channel to the number of hidden layer units.

SeparableConv2DBNActiv

class chainercv.links.connection.SeparableConv2DBNActiv(in_channels, out_channels, ksize, stride=1, pad=0, dilate=1, nobias=False, dw_initialW=None, pw_initialW=None, dw_initial_bias=None, pw_initial_bias=None, dw_activ=<function identity>, pw_activ=<function relu>, bn_kwargs={})[source]

Separable Convolution with batch normalization and activation.

Convolution2D(Depthwise) –> Batch Normalization –> Activation –> Convolution2D(Pointwise) –> Batch Normalization –> Activation

Separable convolution with batch normalizations and activations. Parameters are almost same as Conv2DBNActiv except depthwise and pointwise convolution parameters.

Parameters
  • in_channels (int) – Number of channels of input arrays. Unlike Conv2DBNActiv, this can’t accept None currently.

  • 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.

  • dw_initialW (callable) – Initial weight value of depthwise convolution. If None, the default initializer is used. May also be a callable that takes numpy.ndarray or cupy.ndarray and edits its value.

  • pw_initialW (callable) – Initial weight value of pointwise convolution.

  • dw_initial_bias (callable) – Initial bias value of depthwise convolution. If None, the bias is set to 0. May also be a callable that takes numpy.ndarray or cupy.ndarray and edits its value.

  • pw_initial_bias (callable) – Initial bias value of pointwise convolution.

  • dw_activ (callable) – An activation function of depthwise convolution. The default value is chainer.functions.relu(). If this is None, no activation is applied (i.e. the activation is the identity function).

  • pw_activ (callable) – An activation function of pointwise convolution.

  • bn_kwargs (dict) – Keyword arguments passed to initialize chainer.links.BatchNormalization. If a ChainerMN communicator (CommunicatorBase) is given with the key comm, MultiNodeBatchNormalization will be used for the batch normalization. Otherwise, BatchNormalization will be used.