where :math:`\star` is the valid 2D `cross-correlation`_ operator
where :math:`\star` is the valid 2D `cross-correlation`_ operator
| :attr:`stride` controls the stride for the cross-correlation.
| :attr:`stride` controls the stride for the cross-correlation.
...
@@ -414,10 +419,13 @@ class ReLU(Threshold):
...
@@ -414,10 +419,13 @@ class ReLU(Threshold):
classSigmoid(Module):
classSigmoid(Module):
"""Applies the element-wise function :math:`f(x) = 1 / ( 1 + exp(-x))`
"""Applies the element-wise function :math:`f(x) = 1 / ( 1 + exp(-x))`
Shape:
Shape:
- Input: :math:`(N, *)` where `*` means, any number of additional
- Input: :math:`(N, *)` where `*` means, any number of additional
dimensions
dimensions
- Output: :math:`(N, *)`, same shape as the input
- Output: :math:`(N, *)`, same shape as the input
Examples::
Examples::
>>> m = nn.Sigmoid()
>>> m = nn.Sigmoid()
>>> input = autograd.Variable(torch.randn(2))
>>> input = autograd.Variable(torch.randn(2))
>>> print(input)
>>> print(input)
...
@@ -436,10 +444,11 @@ class Sigmoid(Module):
...
@@ -436,10 +444,11 @@ class Sigmoid(Module):
classMaxPool2d(Module):
classMaxPool2d(Module):
r"""Applies a 2D max pooling over an input signal composed of several input
r"""Applies a 2D max pooling over an input signal composed of several
planes.
input planes.
In the simplest case, the output value of the layer with input size :math:`(N, C, H, W)`,
In the simplest case, the output value of the layer with input size
output :math:`(N, C, H_{out}, W_{out})` and :attr:`kernel_size` :math:`(kH, kW)`
:math:`(N, C, H, W)`, output :math:`(N, C, H_{out}, W_{out})` and
:attr:`kernel_size` :math:`(kH, kW)`
can be precisely described as:
can be precisely described as:
.. math::
.. math::
...
@@ -450,8 +459,8 @@ class MaxPool2d(Module):
...
@@ -450,8 +459,8 @@ class MaxPool2d(Module):
| If :attr:`padding` is non-zero, then the input is implicitly zero-padded on both sides
| If :attr:`padding` is non-zero, then the input is implicitly zero-padded on both sides
for :attr:`padding` number of points
for :attr:`padding` number of points
| :attr:`dilation` controls the spacing between the kernel points. It is harder to describe,
| :attr:`dilation` controls the spacing between the kernel points. It is harder to describe, but this `link`_ has a nice visualization of what :attr:`dilation` does.
but this `link`_ has a nice visualization of what :attr:`dilation` does.
The parameters :attr:`kernel_size`, :attr:`stride`, :attr:`padding`, :attr:`dilation` can either be:
The parameters :attr:`kernel_size`, :attr:`stride`, :attr:`padding`, :attr:`dilation` can either be:
- a single ``int`` -- in which case the same value is used for the height and width dimension
- a single ``int`` -- in which case the same value is used for the height and width dimension
- a ``tuple`` of two ints -- in which case, the first `int` is used for the height dimension,
- a ``tuple`` of two ints -- in which case, the first `int` is used for the height dimension,
...
@@ -531,8 +540,8 @@ class AvgPool2d(Module):
...
@@ -531,8 +540,8 @@ class AvgPool2d(Module):
input(N_i, C_j, stride[0] * h + m, stride[1] * w + n)
input(N_i, C_j, stride[0] * h + m, stride[1] * w + n)
\end{array}
\end{array}
| If :attr:`padding` is non-zero, then the input is implicitly zero-padded on both sides
| If :attr:`padding` is non-zero, then the input is implicitly zero-padded on both sides for :attr:`padding` number of points
for :attr:`padding` number of points
The parameters :attr:`kernel_size`, :attr:`stride`, :attr:`padding` can either be:
The parameters :attr:`kernel_size`, :attr:`stride`, :attr:`padding` can either be:
- a single ``int`` -- in which case the same value is used for the height and width dimension
- a single ``int`` -- in which case the same value is used for the height and width dimension
- a ``tuple`` of two ints -- in which case, the first `int` is used for the height dimension,
- a ``tuple`` of two ints -- in which case, the first `int` is used for the height dimension,
@@ -90,13 +97,63 @@ class DilatedAvgPool2d(Module):
...
@@ -90,13 +97,63 @@ class DilatedAvgPool2d(Module):
+', dilation='+str(self.dilation)+')'
+', dilation='+str(self.dilation)+')'
classMyConvTranspose2d(Module):
classUpsampleConv2d(Module):
"""Customized Layers, discuss later
r"""
To avoid the checkerboard artifacts of standard Fractionally-strided Convolution, we adapt an integer stride convolution but producing a :math:`2\times 2` outputs for each convolutional window.
.. image:: _static/img/upconv.png
:width: 50%
:align: center
Reference:
Hang Zhang and Kristin Dana. "Multi-style Generative Network for Real-time Transfer." *arXiv preprint arXiv:1703.06953 (2017)*
Args:
in_channels (int): Number of channels in the input image
out_channels (int): Number of channels produced by the convolution
kernel_size (int or tuple): Size of the convolving kernel
stride (int or tuple, optional): Stride of the convolution. Default: 1
padding (int or tuple, optional): Zero-padding added to both sides of the input. Default: 0
output_padding (int or tuple, optional): Zero-padding added to one side of the output. Default: 0
groups (int, optional): Number of blocked connections from input channels to output channels. Default: 1
bias (bool, optional): If True, adds a learnable bias to the output. Default: True
dilation (int or tuple, optional): Spacing between kernel elements. Default: 1
scale_factor (int): scaling factor for upsampling convolution. Default: 1
Shape:
- Input: :math:`(N, C_{in}, H_{in}, W_{in})`
- Output: :math:`(N, C_{out}, H_{out}, W_{out})` where
Inspiration Layer (CoMatch Layer) enables the multi-style transfer in feed-forward network, which learns to match the target feature statistics during the training.
This module is differentialble and can be inserted in standard feed-forward network to be learned directly from the loss function without additional supervision.
.. math::
.. math::
Y = \phi^{-1}[\phi(\mathcal{F}^T)W\mathcal{G}]
Y = \phi^{-1}[\phi(\mathcal{F}^T)W\mathcal{G}]
...
@@ -116,7 +171,7 @@ class Inspiration(nn.Module):
...
@@ -116,7 +171,7 @@ class Inspiration(nn.Module):
training multi-style generative network for real-time transfer.
training multi-style generative network for real-time transfer.
Reference:
Reference:
Hang Zhang, and Kristin Dana. "Multi-style Generative Network for Real-time Transfer." *arXiv preprint arXiv:1703.06953 (2017)*
Hang Zhang and Kristin Dana. "Multi-style Generative Network for Real-time Transfer." *arXiv preprint arXiv:1703.06953 (2017)*
"""
"""
def__init__(self,C,B=1):
def__init__(self,C,B=1):
super(Inspiration,self).__init__()
super(Inspiration,self).__init__()
...
@@ -156,76 +211,3 @@ class GramMatrix(nn.Module):
...
@@ -156,76 +211,3 @@ class GramMatrix(nn.Module):
gram=features.bmm(features_t)/(ch*h*w)
gram=features.bmm(features_t)/(ch*h*w)
returngram
returngram
classAggregate(nn.Module):
r"""
Aggregate operation, aggregate the residuals (:math:`R`) with
assignment weights (:math:`A`).
.. math::
e_{k} = \sum_{i=1}^{N} a_{ik} r_{ik}
Shape:
- Input: :math:`A\in\mathcal{R}^{B\times N\times K}` :math:`R\in\mathcal{R}^{B\times N\times K\times D}` (where :math:`B` is batch, :math:`N` is total number of features, :math:`K` is number is codewords, :math:`D` is feature dimensions.)