Skip to content

Commit

Permalink
Merge a903f3f into 3c7a0fc
Browse files Browse the repository at this point in the history
  • Loading branch information
kmaehashi committed Jun 6, 2018
2 parents 3c7a0fc + a903f3f commit f309500
Show file tree
Hide file tree
Showing 18 changed files with 544 additions and 4 deletions.
10 changes: 10 additions & 0 deletions chainer/functions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,12 @@

from chainer.functions.connection.bilinear import bilinear # NOQA
from chainer.functions.connection.convolution_2d import convolution_2d # NOQA
from chainer.functions.connection.convolution_nd import convolution_1d # NOQA
from chainer.functions.connection.convolution_nd import convolution_3d # NOQA
from chainer.functions.connection.convolution_nd import convolution_nd # NOQA
from chainer.functions.connection.deconvolution_2d import deconvolution_2d # NOQA
from chainer.functions.connection.deconvolution_nd import deconvolution_1d # NOQA
from chainer.functions.connection.deconvolution_nd import deconvolution_3d # NOQA
from chainer.functions.connection.deconvolution_nd import deconvolution_nd # NOQA
from chainer.functions.connection.depthwise_convolution_2d import depthwise_convolution_2d # NOQA
from chainer.functions.connection.dilated_convolution_2d import dilated_convolution_2d # NOQA
Expand Down Expand Up @@ -291,17 +295,23 @@

from chainer.functions.pooling.average_pooling_2d import average_pooling_2d # NOQA
from chainer.functions.pooling.average_pooling_2d import AveragePooling2D # NOQA
from chainer.functions.pooling.average_pooling_nd import average_pooling_1d # NOQA
from chainer.functions.pooling.average_pooling_nd import average_pooling_3d # NOQA
from chainer.functions.pooling.average_pooling_nd import average_pooling_nd # NOQA
from chainer.functions.pooling.average_pooling_nd import AveragePoolingND # NOQA
from chainer.functions.pooling.max_pooling_2d import max_pooling_2d # NOQA
from chainer.functions.pooling.max_pooling_2d import MaxPooling2D # NOQA
from chainer.functions.pooling.max_pooling_nd import max_pooling_1d # NOQA
from chainer.functions.pooling.max_pooling_nd import max_pooling_3d # NOQA
from chainer.functions.pooling.max_pooling_nd import max_pooling_nd # NOQA
from chainer.functions.pooling.max_pooling_nd import MaxPoolingND # NOQA
from chainer.functions.pooling.roi_pooling_2d import roi_pooling_2d # NOQA
from chainer.functions.pooling.roi_pooling_2d import ROIPooling2D # NOQA
from chainer.functions.pooling.spatial_pyramid_pooling_2d import spatial_pyramid_pooling_2d # NOQA
from chainer.functions.pooling.unpooling_2d import Unpooling2D # NOQA
from chainer.functions.pooling.unpooling_2d import unpooling_2d # NOQA
from chainer.functions.pooling.unpooling_nd import unpooling_1d # NOQA
from chainer.functions.pooling.unpooling_nd import unpooling_3d # NOQA
from chainer.functions.pooling.unpooling_nd import unpooling_nd # NOQA
from chainer.functions.pooling.unpooling_nd import UnpoolingND # NOQA
from chainer.functions.pooling.upsampling_2d import Upsampling2D # NOQA
Expand Down
40 changes: 39 additions & 1 deletion chainer/functions/connection/convolution_nd.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ def convolution_nd(x, W, b=None, stride=1, pad=0, cover_all=False,
`cover_all` needs to be ``False`` if you want to use cuDNN.
dilate (:class:`int` or :class:`tuple` of :class:`int` s):
Dilation factor of filter applications.
``dilate=d`` and ``dilate=(d, d)`` are equivalent.
``dilate=d`` and ``dilate=(d, d, ..., d)`` are equivalent.
groups (:class:`int`):
The number of groups to use grouped convolution.
The default is one, where grouped convolution is not used.
Expand Down Expand Up @@ -461,3 +461,41 @@ def convolution_nd(x, W, b=None, stride=1, pad=0, cover_all=False,
args = (x, W) if b is None else (x, W, b)
y, = fnode.apply(args)
return y


def convolution_1d(x, W, b=None, stride=1, pad=0, cover_all=False,
dilate=1, groups=1):
"""1-dimensional convolution function.
.. note::
This function calls :func:`~chainer.functions.convolution_nd`
internally, so see the details of the behavior in
the documentation of :func:`~chainer.functions.convolution_nd`.
"""
if len(x.shape[2:]) != 1:
raise ValueError(
'The number of dimensions under channel dimension of the input '
'\'x\' should be 1. But the actual ndim was {}.'.format(
len(x.shape[2:])))
return convolution_nd(x, W, b, stride, pad, cover_all, dilate, groups)


def convolution_3d(x, W, b=None, stride=1, pad=0, cover_all=False,
dilate=1, groups=1):
"""3-dimensional convolution function.
.. note::
This function calls :func:`~chainer.functions.convolution_nd`
internally, so see the details of the behavior in
the documentation of :func:`~chainer.functions.convolution_nd`.
"""
if len(x.shape[2:]) != 3:
raise ValueError(
'The number of dimensions under channel dimension of the input '
'\'x\' should be 3. But the actual ndim was {}.'.format(
len(x.shape[2:])))
return convolution_nd(x, W, b, stride, pad, cover_all, dilate, groups)
40 changes: 39 additions & 1 deletion chainer/functions/connection/deconvolution_nd.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def deconvolution_nd(x, W, b=None, stride=1, pad=0, outsize=None,
pad.
dilate (:class:`int` or :class:`tuple` of :class:`int` s):
Dilation factor of filter applications.
``dilate=d`` and ``dilate=(d, d)`` are equivalent.
``dilate=d`` and ``dilate=(d, d, ..., d)`` are equivalent.
groups (:class:`int`):
The number of groups to use grouped convolution.
The default is one, where grouped convolution is not used.
Expand Down Expand Up @@ -370,3 +370,41 @@ def deconvolution_nd(x, W, b=None, stride=1, pad=0, outsize=None,
args = (x, W) if b is None else (x, W, b)
y, = func.apply(args)
return y


def deconvolution_1d(x, W, b=None, stride=1, pad=0, outsize=None,
dilate=1, groups=1):
"""1-dimensional deconvolution function.
.. note::
This function calls :func:`~chainer.functions.deconvolution_nd`
internally, so see the details of the behavior in
the documentation of :func:`~chainer.functions.deconvolution_nd`.
"""
if len(x.shape[2:]) != 1:
raise ValueError(
'The number of dimensions under channel dimension of the input '
'\'x\' should be 1. But the actual ndim was {}.'.format(
len(x.shape[2:])))
return deconvolution_nd(x, W, b, stride, pad, outsize, dilate, groups)


def deconvolution_3d(x, W, b=None, stride=1, pad=0, outsize=None,
dilate=1, groups=1):
"""3-dimensional deconvolution function.
.. note::
This function calls :func:`~chainer.functions.deconvolution_nd`
internally, so see the details of the behavior in
the documentation of :func:`~chainer.functions.deconvolution_nd`.
"""
if len(x.shape[2:]) != 3:
raise ValueError(
'The number of dimensions under channel dimension of the input '
'\'x\' should be 3. But the actual ndim was {}.'.format(
len(x.shape[2:])))
return deconvolution_nd(x, W, b, stride, pad, outsize, dilate, groups)
44 changes: 44 additions & 0 deletions chainer/functions/pooling/average_pooling_nd.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,47 @@ def average_pooling_nd(x, ksize, stride=None, pad=0):
"""
ndim = len(x.shape[2:])
return AveragePoolingND(ndim, ksize, stride=stride, pad=pad).apply((x,))[0]


def average_pooling_1d(x, ksize, stride=None, pad=0):
"""1-dimensional spatial average pooling function.
.. warning::
This feature is experimental. The interface can change in the future.
.. note::
This function calls :func:`~chainer.functions.average_pooling_nd`
internally, so see the details of the behavior in
the documentation of :func:`~chainer.functions.average_pooling_nd`.
"""
if len(x.shape[2:]) != 1:
raise ValueError(
'The number of dimensions under channel dimension of the input '
'\'x\' should be 1. But the actual ndim was {}.'.format(
len(x.shape[2:])))
return average_pooling_nd(x, ksize, stride, pad)


def average_pooling_3d(x, ksize, stride=None, pad=0):
"""3-dimensional spatial average pooling function.
.. warning::
This feature is experimental. The interface can change in the future.
.. note::
This function calls :func:`~chainer.functions.average_pooling_nd`
internally, so see the details of the behavior in
the documentation of :func:`~chainer.functions.average_pooling_nd`.
"""
if len(x.shape[2:]) != 3:
raise ValueError(
'The number of dimensions under channel dimension of the input '
'\'x\' should be 3. But the actual ndim was {}.'.format(
len(x.shape[2:])))
return average_pooling_nd(x, ksize, stride, pad)
44 changes: 44 additions & 0 deletions chainer/functions/pooling/max_pooling_nd.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,47 @@ def max_pooling_nd(x, ksize, stride=None, pad=0, cover_all=True):
"""
ndim = len(x.shape[2:])
return MaxPoolingND(ndim, ksize, stride, pad, cover_all).apply((x,))[0]


def max_pooling_1d(x, ksize, stride=None, pad=0, cover_all=True):
"""1-dimensional spatial max pooling function.
.. warning::
This feature is experimental. The interface can change in the future.
.. note::
This function calls :func:`~chainer.functions.max_pooling_nd`
internally, so see the details of the behavior in
the documentation of :func:`~chainer.functions.max_pooling_nd`.
"""
if len(x.shape[2:]) != 1:
raise ValueError(
'The number of dimensions under channel dimension of the input '
'\'x\' should be 1. But the actual ndim was {}.'.format(
len(x.shape[2:])))
return max_pooling_nd(x, ksize, stride, pad, cover_all)


def max_pooling_3d(x, ksize, stride=None, pad=0, cover_all=True):
"""3-dimensional spatial max pooling function.
.. warning::
This feature is experimental. The interface can change in the future.
.. note::
This function calls :func:`~chainer.functions.max_pooling_nd`
internally, so see the details of the behavior in
the documentation of :func:`~chainer.functions.max_pooling_nd`.
"""
if len(x.shape[2:]) != 3:
raise ValueError(
'The number of dimensions under channel dimension of the input '
'\'x\' should be 3. But the actual ndim was {}.'.format(
len(x.shape[2:])))
return max_pooling_nd(x, ksize, stride, pad, cover_all)
44 changes: 44 additions & 0 deletions chainer/functions/pooling/unpooling_nd.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,47 @@ def unpooling_nd(x, ksize, stride=None, pad=0, outsize=None, cover_all=True):
ndim = len(x.shape[2:])
return UnpoolingND(
ndim, ksize, stride, pad, outsize, cover_all).apply((x,))[0]


def unpooling_1d(x, ksize, stride=None, pad=0, outsize=None, cover_all=True):
"""Inverse operation of 1-dimensional spatial pooling.
.. warning::
This feature is experimental. The interface can change in the future.
.. note::
This function calls :func:`~chainer.functions.unpooling_nd`
internally, so see the details of the behavior in
the documentation of :func:`~chainer.functions.unpooling_nd`.
"""
if len(x.shape[2:]) != 1:
raise ValueError(
'The number of dimensions under channel dimension of the input '
'\'x\' should be 1. But the actual ndim was {}.'.format(
len(x.shape[2:])))
return unpooling_nd(x, ksize, stride, pad, outsize, cover_all)


def unpooling_3d(x, ksize, stride=None, pad=0, outsize=None, cover_all=True):
"""Inverse operation of 3-dimensional spatial pooling.
.. warning::
This feature is experimental. The interface can change in the future.
.. note::
This function calls :func:`~chainer.functions.unpooling_nd`
internally, so see the details of the behavior in
the documentation of :func:`~chainer.functions.unpooling_nd`.
"""
if len(x.shape[2:]) != 3:
raise ValueError(
'The number of dimensions under channel dimension of the input '
'\'x\' should be 3. But the actual ndim was {}.'.format(
len(x.shape[2:])))
return unpooling_nd(x, ksize, stride, pad, outsize, cover_all)
4 changes: 4 additions & 0 deletions chainer/links/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
from chainer.links.connection.bias import Bias # NOQA
from chainer.links.connection.bilinear import Bilinear # NOQA
from chainer.links.connection.convolution_2d import Convolution2D # NOQA
from chainer.links.connection.convolution_nd import Convolution1D # NOQA
from chainer.links.connection.convolution_nd import Convolution3D # NOQA
from chainer.links.connection.convolution_nd import ConvolutionND # NOQA
from chainer.links.connection.deconvolution_2d import Deconvolution2D # NOQA
from chainer.links.connection.deconvolution_nd import Deconvolution1D # NOQA
from chainer.links.connection.deconvolution_nd import Deconvolution3D # NOQA
from chainer.links.connection.deconvolution_nd import DeconvolutionND # NOQA
from chainer.links.connection.depthwise_convolution_2d import DepthwiseConvolution2D # NOQA
from chainer.links.connection.dilated_convolution_2d import DilatedConvolution2D # NOQA
Expand Down
40 changes: 39 additions & 1 deletion chainer/links/connection/convolution_nd.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ConvolutionND(link.Link):
``cover_all`` needs to be ``False`` if you want to use cuDNN.
dilate (:class:`int` or :class:`tuple` of :class:`int` s):
Dilation factor of filter applications.
``dilate=d`` and ``dilate=(d, d)`` are equivalent.
``dilate=d`` and ``dilate=(d, d, ..., d)`` are equivalent.
groups (:class:`int`):
The number of groups to use grouped convolution.
The default is one, where grouped convolution is not used.
Expand Down Expand Up @@ -95,3 +95,41 @@ def __call__(self, x):
return convolution_nd.convolution_nd(
x, self.W, self.b, self.stride, self.pad, cover_all=self.cover_all,
dilate=self.dilate, groups=self.groups)


class Convolution1D(ConvolutionND):
"""1-dimensional convolution layer.
.. note::
This link wraps :class:`~chainer.links.ConvolutionND` by giving 1 to
the first argument ``ndim``, so see the details of the behavior in
the documentation of :class:`~chainer.links.ConvolutionND`.
"""

def __init__(self, in_channels, out_channels, ksize, stride=1, pad=0,
nobias=False, initialW=None, initial_bias=None,
cover_all=False, dilate=1, groups=1):
super(Convolution1D, self).__init__(
1, in_channels, out_channels, ksize, stride, pad, nobias, initialW,
initial_bias, cover_all, dilate, groups)


class Convolution3D(ConvolutionND):
"""3-dimensional convolution layer.
.. note::
This link wraps :class:`~chainer.links.ConvolutionND` by giving 3 to
the first argument ``ndim``, so see the details of the behavior in
the documentation of :class:`~chainer.links.ConvolutionND`.
"""

def __init__(self, in_channels, out_channels, ksize, stride=1, pad=0,
nobias=False, initialW=None, initial_bias=None,
cover_all=False, dilate=1, groups=1):
super(Convolution3D, self).__init__(
3, in_channels, out_channels, ksize, stride, pad, nobias, initialW,
initial_bias, cover_all, dilate, groups)
40 changes: 39 additions & 1 deletion chainer/links/connection/deconvolution_nd.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class DeconvolutionND(link.Link):
zero. When it is :class:`numpy.ndarray`, its ``ndim`` should 1.
dilate (:class:`int` or :class:`tuple` of :class:`int` s):
Dilation factor of filter applications.
``dilate=d`` and ``dilate=(d, d)`` are equivalent.
``dilate=d`` and ``dilate=(d, d, ..., d)`` are equivalent.
groups (:class:`int`):
The number of groups to use grouped convolution.
The default is one, where grouped convolution is not used.
Expand Down Expand Up @@ -83,3 +83,41 @@ def __call__(self, x):
return deconvolution_nd.deconvolution_nd(
x, self.W, b=self.b, stride=self.stride, pad=self.pad,
outsize=self.outsize, dilate=self.dilate, groups=self.groups)


class Deconvolution1D(DeconvolutionND):
"""1-dimensional deconvolution layer.
.. note::
This link wraps :class:`~chainer.links.DeconvolutionND` by giving 1 to
the first argument ``ndim``, so see the details of the behavior in
the documentation of :class:`~chainer.links.DeconvolutionND`.
"""

def __init__(self, in_channels, out_channels, ksize, stride=1, pad=0,
nobias=False, outsize=None, initialW=None, initial_bias=None,
dilate=1, groups=1):
super(Deconvolution1D, self).__init__(
1, in_channels, out_channels, ksize, stride, pad, nobias, outsize,
initialW, initial_bias, dilate, groups)


class Deconvolution3D(DeconvolutionND):
"""3-dimensional deconvolution layer.
.. note::
This link wraps :class:`~chainer.links.DeconvolutionND` by giving 3 to
the first argument ``ndim``, so see the details of the behavior in
the documentation of :class:`~chainer.links.DeconvolutionND`.
"""

def __init__(self, in_channels, out_channels, ksize, stride=1, pad=0,
nobias=False, outsize=None, initialW=None, initial_bias=None,
dilate=1, groups=1):
super(Deconvolution3D, self).__init__(
3, in_channels, out_channels, ksize, stride, pad, nobias, outsize,
initialW, initial_bias, dilate, groups)
Loading

0 comments on commit f309500

Please sign in to comment.