Skip to content

Commit

Permalink
Add ConvTranspose1d module (pytorch#449)
Browse files Browse the repository at this point in the history
  • Loading branch information
colesbury authored and soumith committed Jan 13, 2017
1 parent 24a2f2e commit 3a07228
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 137 deletions.
7 changes: 5 additions & 2 deletions docs/source/nn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ Convolution Layers
.. autoclass:: Conv2d
:members:

.. autoclass:: ConvTranspose2d
.. autoclass:: Conv3d
:members:

.. autoclass:: Conv3d
.. autoclass:: ConvTranspose1d
:members:

.. autoclass:: ConvTranspose2d
:members:

.. autoclass:: ConvTranspose3d
Expand Down
15 changes: 14 additions & 1 deletion test/test_nn.py
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ def compare_cpu_gpu(outputs_cpu, outputs_gpu):
for bidirectional in (False, True):
for dropout in (0, 1): # Because of dropout randomness, can only compare 0 and 1
for batch_first in (False, True):
num_directions = 2 if bidirectional else 1
num_directions = 2 if bidirectional else 1
if batch_first:
input_val = torch.randn(batch, seq_length, input_size)
else:
Expand Down Expand Up @@ -1211,6 +1211,19 @@ def add_test(test):
input_size=(2, 4, 6),
cudnn=True,
),
dict(
module_name='ConvTranspose1d',
constructor_args=(3, 4, 3, (3,), 1, (1,)),
cudnn=True,
input_size=(1, 3, 7)
),
dict(
module_name='ConvTranspose1d',
constructor_args=(3, 4, 3, 2, 1, 1, 1, False),
input_size=(1, 3, 6),
cudnn=True,
desc='no_bias'
),
dict(
module_name='MaxPool1d',
constructor_args=(4,),
Expand Down
7 changes: 7 additions & 0 deletions torch/nn/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ def conv3d(input, weight, bias=None, stride=1, padding=0, dilation=1,
return f(input, weight, bias) if bias is not None else f(input, weight)


def conv_transpose1d(input, weight, bias=None, stride=1, padding=0,
output_padding=0, groups=1):
f = ConvNd(_single(stride), _single(padding), _single(1), True,
_single(output_padding), groups)
return f(input, weight, bias) if bias is not None else f(input, weight)


def conv_transpose2d(input, weight, bias=None, stride=1, padding=0,
output_padding=0, groups=1):
"""Applies a 2D transposed convolution operator over an input image
Expand Down
3 changes: 2 additions & 1 deletion torch/nn/modules/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .module import Module
from .linear import Linear
from .conv import Conv1d, Conv2d, ConvTranspose2d, Conv3d, ConvTranspose3d
from .conv import Conv1d, Conv2d, Conv3d, \
ConvTranspose1d, ConvTranspose2d, ConvTranspose3d
from .activation import Threshold, ReLU, Hardtanh, ReLU6, Sigmoid, Tanh, \
Softmax, Softmax2d, LogSoftmax, ELU, Hardshrink, LeakyReLU, LogSigmoid, \
Softplus, Softshrink, PReLU, Softsign, Softmin, Tanhshrink, RReLU
Expand Down
Loading

0 comments on commit 3a07228

Please sign in to comment.