提交 7b8ee75b authored 作者: Sina Honari's avatar Sina Honari

updating notations and namings

上级 4bd7b623
...@@ -177,21 +177,25 @@ def conv2d(input, ...@@ -177,21 +177,25 @@ def conv2d(input,
return conv_op(input, filters) return conv_op(input, filters)
def deconv(input, def conv2d_grad_wrt_inputs(output_grad,
filters, filters,
input_shape=None, output_grad_shape=None,
output_shape=None, input_shape=None,
filter_shape=None, filter_shape=None,
border_mode='valid', border_mode='valid',
subsample=(1, 1), subsample=(1, 1),
filter_flip=True): filter_flip=True):
"""This function will build the symbolic graph for deconvoloving a """This function builds the symbolic graph for getting the
mini-batch of a stack of 2D inputs with a set of 2D filters (using gradient of the output of a convolution (namely output_grad)
gradient of convolution), such that it upsamples the input to the w.r.t the input of the convolution, given a set of 2D filters
desired output resolution. used by the convolution, such that the output_grad is upsampled
to the input shape.
:type input: symbolic 4D tensor to be upsampled
:param input: mini-batch of feature map stacks, of shape :type output_grad: symbolic 4D tensor as the output gradient
of the convolution. This is the tensor that will be upsampled
or whose gradient will be taken with respect to the input of
the convolution.
:param output_grad: mini-batch of feature map stacks, of shape
(batch size, input channels, input rows, input columns). (batch size, input channels, input rows, input columns).
See the optional parameter ``input_shape``. See the optional parameter ``input_shape``.
...@@ -200,18 +204,18 @@ def deconv(input, ...@@ -200,18 +204,18 @@ def deconv(input,
(output channels, input channels, filter rows, filter columns). (output channels, input channels, filter rows, filter columns).
See the optional parameter ``filter_shape``. See the optional parameter ``filter_shape``.
:type input_shape: None, tuple/list of len 4 of int or Constant variable :type output_grad_shape: None, tuple/list of len 4 of int or
indicating the shape to be upsampled or whose gradient should be taken. Constant variable indicating the shape of the output_grad.
:param input_shape: The shape of the input parameter. :param output_grad_shape: The shape of the output_grad parameter.
Optional, possibly used to choose an optimal implementation. Optional, possibly used to choose an optimal implementation.
You can give ``None`` for any element of the list to specify that this You can give ``None`` for any element of the list to specify that this
element is not known at compile time. element is not known at compile time.
:type output_shape: tuple/list of len 2 of int or Constant variable :type input_shape: tuple/list of len 2 of int or Constant variable
indicating the row and column size of the output (upsampled) features. indicating the row and column size of the input (upsampled) features.
:param output_shape: The shape of the input parameter. :param input_shape: The shape of the input parameter.
Not Optional, since given the input_shape and the subsample values, Not Optional, since given the output_grad_shape and the subsample values,
multiple output_shape may be plausible. multiple input_shape may be plausible.
:type filter_shape: None, tuple/list of len 4 of int or Constant variable :type filter_shape: None, tuple/list of len 4 of int or Constant variable
:param filter_shape: The shape of the filters parameter. :param filter_shape: The shape of the filters parameter.
...@@ -259,32 +263,34 @@ def deconv(input, ...@@ -259,32 +263,34 @@ def deconv(input,
""" """
deconv_op = AbstractConv2d_gradInputs(imshp=output_shape, deconv_op = AbstractConv2d_gradInputs(imshp=input_shape,
kshp=filter_shape, kshp=filter_shape,
border_mode=border_mode, border_mode=border_mode,
subsample=subsample, subsample=subsample,
filter_flip=filter_flip) filter_flip=filter_flip)
return deconv_op(filters, input, output_shape) return deconv_op(filters, input, output_grad_shape)
def gradWeights(input, def conv2d_grad_wrt_weights(input,
output, output_grad,
input_shape=None, input_shape=None,
output_shape=None, output_grad_shape=None,
filter_shape=None, filter_shape=None,
border_mode='valid', border_mode='valid',
subsample=(1, 1), subsample=(1, 1),
filter_flip=True): filter_flip=True):
"""This function will build the symbolic graph for getting the """This function will build the symbolic graph for getting the
gradient of the output of a convolution layer w.r.t its wights. gradient of the output of a convolution (output_grad) w.r.t its wights.
:type input: symbolic 4D tensor as in the input in the forward pass :type input: symbolic 4D tensor as the input of the convolution
in the forward pass
:param input: mini-batch of feature map stacks, of shape :param input: mini-batch of feature map stacks, of shape
(batch size, input channels, input rows, input columns). (batch size, input channels, input rows, input columns).
:type output: symbolic 4D tensor as in the output in the forward pass :type output_grad: symbolic 4D tensor as the gradient output
:param output: mini-batch of feature map stacks, of shape of the convolution
:param output_grad: mini-batch of feature map stacks, of shape
(batch size, input channels, input rows, input columns). (batch size, input channels, input rows, input columns).
:type filters: symbolic 4D tensor :type filters: symbolic 4D tensor
...@@ -292,8 +298,8 @@ def gradWeights(input, ...@@ -292,8 +298,8 @@ def gradWeights(input,
(output channels, input channels, filter rows, filter columns). (output channels, input channels, filter rows, filter columns).
See the optional parameter ``filter_shape``. See the optional parameter ``filter_shape``.
:type output_shape: None, tuple/list of len 4 of int or Constant variable :type output_grad_shape: None, tuple/list of len 4 of int or Constant variable
:param output_shape: The shape of the input parameter. :param output_grad_shape: The shape of the input parameter.
Optional, possibly used to choose an optimal implementation. Optional, possibly used to choose an optimal implementation.
You can give ``None`` for any element of the list to specify that this You can give ``None`` for any element of the list to specify that this
element is not known at compile time. element is not known at compile time.
...@@ -301,15 +307,15 @@ def gradWeights(input, ...@@ -301,15 +307,15 @@ def gradWeights(input,
:type input_shape: tuple/list of len 2 of int or Constant variable :type input_shape: tuple/list of len 2 of int or Constant variable
indicating the row and column size of the input in the forward pass. indicating the row and column size of the input in the forward pass.
:param input_shape: The shape of the input parameter. :param input_shape: The shape of the input parameter.
Not Optional, since given the input_shape and the subsample values,
multiple input_shape may be plausible.
:type filter_shape: None, tuple/list of len 4 of int or Constant variable
:param filter_shape: The shape of the filters parameter.
Optional, possibly used to choose an optimal implementation. Optional, possibly used to choose an optimal implementation.
You can give ``None`` for any element of the list to specify that this You can give ``None`` for any element of the list to specify that this
element is not known at compile time. element is not known at compile time.
:type filter_shape: None, tuple/list of len 4 of int or Constant variable
:param filter_shape: The shape of the filters parameter.
Not Optional, since given the output_grad_shape and the input_shape,
multiple filter_shape may be plausible.
:type border_mode: str, int or tuple of two int :type border_mode: str, int or tuple of two int
:param border_mode: Either of the following: :param border_mode: Either of the following:
* ``'valid'``: apply filter wherever it completely overlaps with the * ``'valid'``: apply filter wherever it completely overlaps with the
...@@ -350,12 +356,12 @@ def gradWeights(input, ...@@ -350,12 +356,12 @@ def gradWeights(input,
""" """
gradWeight_op = AbstractConv2d_gradWeights(imshp=input_shape, gradWeight_op = AbstractConv2d_gradWeights(imshp=input_shape,
kshp=filter_shape, kshp=filter_shape,
border_mode=border_mode, border_mode=border_mode,
subsample=subsample, subsample=subsample,
filter_flip=filter_flip) filter_flip=filter_flip)
return gradWeight_op(input, output, input_shape) return gradWeight_op(input, output_grad, input_shape)
class BaseAbstractConv2d(Op): class BaseAbstractConv2d(Op):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论