Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group convolution backprop data #4113

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
346a524
GroupConvolutionBackpropData: Added backend unit tests
ggalieroc Feb 1, 2021
72c01cb
GroupConvolutionBackpropData: Refactor SLT and added tests for 1D
ggalieroc Feb 1, 2021
cf16f11
GroupConvolutionBackpropData: Added Serialization tests
ggalieroc Feb 1, 2021
dfe774d
GroupConvolutionBackpropData: Added GroupConvolutionBackpropData refe…
ggalieroc Feb 1, 2021
4167c54
GroupConvolutionBackpropData specification refactoring.
jdanieck Feb 1, 2021
23b24f0
Merge remote-tracking branch 'upstream/master' into group_convolution…
jdanieck Feb 2, 2021
b017b48
GroupConvolutionBackpropData: Added validation node checks for the op
ggalieroc Feb 3, 2021
40fdeec
GroupConvolutionBackpropData: Copyright year fixed
ggalieroc Feb 3, 2021
4cc5c78
GroupConvolutionBackpropData: Enhanced output shape inference with dy…
ggalieroc Feb 3, 2021
dc8e437
Merge remote-tracking branch 'upstream/master' into group_convolution…
ggalieroc Feb 3, 2021
f704edb
GroupConvolutionBackpropData: Remove redefinition of helper variables
ggalieroc Feb 3, 2021
a3e0c5e
Spec refactoring: add ticks to types and layouts.
jdanieck Feb 4, 2021
51610aa
Minor refactoring.
jdanieck Feb 4, 2021
99c69c9
GroupConvolutionBackpropData: Moved backend tests from GroupConvoluti…
ggalieroc Feb 4, 2021
6b9b3f5
GroupConvolutionBackpropData: Improved output shape inference for ful…
ggalieroc Feb 4, 2021
8f6084f
GroupConvolutionBackpropData: Clean up type_prop tests
ggalieroc Feb 4, 2021
ba0a029
Merge remote-tracking branch 'upstream/master' into group_convolution…
ggalieroc Feb 4, 2021
3aa7b7f
Fix banner in GroupConvolution shared test class.
jdanieck Feb 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 90 additions & 48 deletions docs/ops/convolution/GroupConvolutionBackpropData_1.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,25 @@

**Category**: Convolution

**Short description**: Computes the gradients of a GroupConvolution operation with respect to the input. Also known as Deconvolution or Transposed Convolution.
**Short description**: Computes 1D, 2D or 3D *GroupConvolutionBackpropData* of input and kernel tensors.

**Detailed description**:
**Detailed description**: Splits input and filters into multiple groups, computes *ConvolutionBackpropData* on them and concatenates the results. It is equivalent to GroupConvolution and Convolution relationship.

GroupConvolutionBackpropData is similar to ConvolutionBackpropData but also specifies the group processing in a way similar to how GroupConvolution extends behavior of a regular Convolution operation.

GroupConvolutionBackpropData takes input tensor, weights tensor and output shape and computes output tensor of a given shape. The shape of the output can be specified as an input 1D integer tensor explicitly or determined according to other attributes implicitly. If the output shape is specified as an explicit input, shape of the output exactly matches the specified size and required amount of padding is computed.

GroupConvolutionBackpropData accepts the same set of attributes as a regular GroupConvolution operation, but they are interpreted in a "backward way", so they are applied to the output of GroupConvolutionBackpropData, but not to the input. Refer to a regular GroupConvolution operation for detailed description of each attribute.

Output shape when specified as an input `output_shape`, specifies only spatial dimensions. No batch or channel dimension should be passed along with H, W or other spatial dimensions. If `output_shape` is omitted, then `pads_begin`, `pads_end` or `auto_pad` are used to determine output spatial shape `[Y_1, Y_2, ..., Y_D]` by input spatial shape `[X_1, X_2, ..., X_D]` in the following way:

```
if auto_pads != None:
pads_begin[i] = 0
pads_end[i] = 0

Y_i = stride[i] * (X_i - 1) + ((K_i - 1) * dilations[i] + 1) - pads_begin[i] - pads_end[i] + output_padding[i]
```

where `K_i` filter kernel dimension along spatial axis `i`.

If `output_shape` is specified, `pads_begin` and `pads_end` are ignored, and `auto_pad` defines how to distribute padding amount around the tensor. In this case pads are determined based on the next formulas to correctly align input and output tensors (similar to ONNX definition at https://github.com/onnx/onnx/blob/master/docs/Operators.md#convtranspose):

```
total_padding[i] = stride[i] * (X_i - 1) + ((K_i - 1) * dilations[i] + 1) - output_shape[i] + output_padding[i]
if auto_pads != SAME_UPPER:
pads_begin[i] = total_padding[i] // 2
pads_end[i] = total_padding[i] - pads_begin[i]
else:
pads_end[i] = total_padding[i] // 2
pads_begin[i] = total_padding[i] - pads_end[i]
```

**Attributes**
**Attributes**: The operation has the same attributes as a *ConvolutionBackpropData*. Number of groups is derived from the kernel shape.

* *strides*

* **Description**: *strides* has the same definition as *strides* for a regular Convolution but applied in the backward way, for the output tensor.
* **Range of values**: positive integers
* **Type**: int[]
* **Type**: `int[]`
* **Default value**: None
* **Required**: *yes*

* *pads_begin*

* **Description**: *pads_begin* has the same definition as *pads_begin* for a regular Convolution but applied in the backward way, for the output tensor. May be omitted, in which case pads are calculated automatically.
* **Range of values**: non-negative integers
* **Type**: int[]
* **Type**: `int[]`
* **Default value**: None
* **Required**: *yes*
* **Note**: the attribute is ignored when *auto_pad* attribute is specified.
Expand All @@ -61,7 +31,7 @@ else:

* **Description**: *pads_end* has the same definition as *pads_end* for a regular Convolution but applied in the backward way, for the output tensor. May be omitted, in which case pads are calculated automatically.
* **Range of values**: non-negative integers
* **Type**: int[]
* **Type**: `int[]`
* **Default value**: None
* **Required**: *yes*
* **Note**: the attribute is ignored when *auto_pad* attribute is specified.
Expand All @@ -70,43 +40,82 @@ else:

* **Description**: *dilations* has the same definition as *dilations* for a regular Convolution but applied in the backward way, for the output tensor.
* **Range of values**: positive integers
* **Type**: int[]
* **Type**: `int[]`
* **Default value**: None
* **Required**: *yes*

* *auto_pad*

* **Description**: *auto_pad* has the same definition as *auto_pad* for a regular Convolution but applied in the backward way, for the output tensor.
* *explicit*: use explicit padding values from `pads_begin` and `pads_end`.
* *same_upper (same_lower)* the input is padded to match the output size. In case of odd padding value an extra padding is added at the end (at the beginning).
* *explicit* - use explicit padding values from *pads_begin* and *pads_end*.
* *same_upper* - the input is padded to match the output size. In case of odd padding value an extra padding is added at the end.
* *same_lower* - the input is padded to match the output size. In case of odd padding value an extra padding is added at the beginning.
* *valid* - do not use padding.
* **Type**: string
* **Default value**: None
* **Type**: `string`
* **Default value**: explicit
* **Required**: *no*
* **Note**: *pads_begin* and *pads_end* attributes are ignored when *auto_pad* is specified.

* *output_padding*

* **Description**: *output_padding* adds additional amount of paddings per each spatial axis in the `output` tensor. It unlocks more elements in the output allowing them to be computed. Elements are added at the higher coordinate indices for the spatial dimensions. Number of elements in *output_padding* list matches the number of spatial dimensions in `data` and `output` tensors.
* **Description**: *output_padding* adds additional amount of paddings per each spatial axis in the output tensor. It unlocks more elements in the output allowing them to be computed. Elements are added at the higher coordinate indices for the spatial dimensions. Number of elements in *output_padding* list matches the number of spatial dimensions in input and output tensors.
* **Range of values**: non-negative integer values
* **Type**: int[]
* **Type**: `int[]`
* **Default value**: all zeros
* **Required**: *no*

**Inputs**:

* **1**: `data` -- input tensor of rank 3 or greater. Layout is `[N, C_INPUT * GROUPS, X1, ..., XD]`, where `GROUPS` is the number of groups that is specified as a dedicated dimension in `filter` input. *Required*.

* **2**: `filter` -- convolution kernel tensor. Weights have shape `[GROUPS, C_INPUT, C_OUTPUT, K_D, ..., K_1]`. `C_INPUT` is the number of channels in input `data` tensor shape, and `C_OUTPUT` is the number of channels in the `output` tensor. `GROUPS` is the number of groups in input/output channel dimension. Spatial size of the kernel `[K_D, ..., K_1]` is derived from the shape of this input and not specified by any attribute. *Required*.
* **1**: Input tensor of type `T1` and rank 3, 4 or 5. Layout is `NCZYX` (number of batches, number of channels, spatial axes Z, Y, X). Required.

* **3**: `output_shape` is 1D integer tensor that specifies spatial shape of the output. *Optional*. If specified, *padding amount* is deduced from relation of input and output spatial shapes according to formulas in the description. If not specified, *output shape* is calculated based on the `pads_begin` and `pads_end` or completely according to `auto_pad`.
* **2**: Kernel tensor of type `T1` and rank 4, 5 or 6. Layout is `GOIZYX` (number of groups, number of output channels, number of input channels, spatial axes Z, Y, X). Required.

* **3**: Output shape tensor of type `T2` and rank 1. It specifies spatial shape of the output. Optional.
* **Note** Number of groups is derived from the shape of the kernel and not specified by any attribute.
* **Note**: Type of the convolution (1D, 2D or 3D) is derived from the rank of the input tensors and not specified by any attribute:
* 1D convolution (input tensors rank 3) means that there is only one spatial axis X
* 2D convolution (input tensors rank 4) means that there are two spatial axes Y, X
* 3D convolution (input tensors rank 5) means that there are three spatial axes Z, Y, X

**Outputs**:

* **1**: `output` -- output tensor of the same rank as input `data` tensor and shape `[N, GROUPS * C_OUTPUT, Y1, ..., YD]`, where `GROUPS` is the number of groups that is specified as a dedicated dimension in `filter` input.
* **1**: Output tensor of type `T1` and rank 3, 4 or 5 (the same as input *1*). Layout is `NOZYX` (number of batches, number of kernel output channels, spatial axes Z, Y, X).

**Types**:

* *T1*: any floating point type.
* *T2*: any integer type.

**Example**

1D GroupConvolutionBackpropData
```xml
<layer id="5" name="upsampling_node" type="GroupConvolutionBackpropData">
<data dilations="1" pads_begin="1" pads_end="1" strides="2"/>
<input>
<port id="0">
<dim>1</dim>
<dim>20</dim>
<dim>224</dim>
</port>
<port id="1">
<dim>4</dim>
<dim>5</dim>
<dim>2</dim>
<dim>3</dim>
</port>
</input>
<output>
<port id="0" precision="FP32">
<dim>1</dim>
<dim>8</dim>
<dim>447</dim>
</port>
</output>
</layer>
```

2D GroupConvolutionBackpropData
```xml
<layer id="5" name="upsampling_node" type="GroupConvolutionBackpropData">
<data dilations="1,1" pads_begin="1,1" pads_end="1,1" strides="2,2"/>
Expand Down Expand Up @@ -135,3 +144,36 @@ else:
</output>
</layer>
```

3D GroupConvolutionBackpropData
```xml
<layer id="5" name="upsampling_node" type="GroupConvolutionBackpropData">
<data dilations="1,1,1" pads_begin="1,1,1" pads_end="1,1,1" strides="2,2,2"/>
<input>
<port id="0">
<dim>1</dim>
<dim>20</dim>
<dim>224</dim>
<dim>224</dim>
<dim>224</dim>
</port>
<port id="1">
<dim>4</dim>
<dim>5</dim>
<dim>2</dim>
<dim>3</dim>
<dim>3</dim>
<dim>3</dim>
</port>
</input>
<output>
<port id="0" precision="FP32">
<dim>1</dim>
<dim>8</dim>
<dim>447</dim>
<dim>447</dim>
<dim>447</dim>
</port>
</output>
</layer>
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include <vector>

#include "shared_test_classes/single_layer/group_convolution_backprop_data.hpp"

using namespace LayerTestsDefinitions;

namespace {

TEST_P(GroupConvBackpropDataLayerTest, Serialize) {
Serialize();
}

const std::vector<InferenceEngine::Precision> precisions = {
InferenceEngine::Precision::FP64, InferenceEngine::Precision::FP32,
InferenceEngine::Precision::FP16, InferenceEngine::Precision::BF16,
InferenceEngine::Precision::I8, InferenceEngine::Precision::I16,
InferenceEngine::Precision::I32, InferenceEngine::Precision::I64,
InferenceEngine::Precision::U8, InferenceEngine::Precision::U16,
InferenceEngine::Precision::U32, InferenceEngine::Precision::U64,
};
const std::vector<std::vector<size_t>> kernels = {{3, 3}};
const std::vector<std::vector<size_t>> strides = {{1, 1}};
const std::vector<std::vector<ptrdiff_t>> padBegins = {{0, 0}};
const std::vector<std::vector<ptrdiff_t>> padEnds = {{0, 0}};
const std::vector<std::vector<size_t>> dilations = {{1, 1}};
const std::vector<size_t> numOutChannels = {8, 16};
const std::vector<size_t> numGroups = {2, 8};
const std::vector<ngraph::op::PadType> pad_types = {
ngraph::op::PadType::EXPLICIT, ngraph::op::PadType::VALID,
ngraph::op::PadType::SAME_LOWER, ngraph::op::PadType::SAME_UPPER};
const auto inputShapes = std::vector<size_t>({1, 16, 30, 30});

const auto groupConvBackpropData2DParams = ::testing::Combine(
::testing::ValuesIn(kernels), ::testing::ValuesIn(strides),
::testing::ValuesIn(padBegins), ::testing::ValuesIn(padEnds),
::testing::ValuesIn(dilations), ::testing::ValuesIn(numOutChannels),
::testing::ValuesIn(numGroups), ::testing::ValuesIn(pad_types));

INSTANTIATE_TEST_CASE_P(
smoke_GroupConvBackpropData2D_Serialization, GroupConvBackpropDataLayerTest,
::testing::Combine(
groupConvBackpropData2DParams,
::testing::ValuesIn(precisions),
::testing::Values(InferenceEngine::Precision::UNSPECIFIED),
::testing::Values(InferenceEngine::Precision::UNSPECIFIED),
::testing::Values(InferenceEngine::Layout::ANY),
::testing::Values(InferenceEngine::Layout::ANY),
::testing::Values(inputShapes),
::testing::Values(CommonTestUtils::DEVICE_CPU)),
GroupConvBackpropDataLayerTest::getTestCaseName);

} // namespace
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,76 @@

#include <vector>

#include "single_layer_tests/group_convolution_backprop_data.hpp"
#include "common_test_utils/test_constants.hpp"
#include "single_layer_tests/group_convolution_backprop_data.hpp"

using namespace LayerTestsDefinitions;

namespace {

const std::vector<InferenceEngine::Precision> netPrecisions = {
InferenceEngine::Precision::FP32
InferenceEngine::Precision::FP32,
InferenceEngine::Precision::FP16
};

const std::vector<size_t> numOutChannels = {16, 32};
const std::vector<size_t> numGroups = {2, 8, 16};

/* ============= 1D GroupConvolution ============= */
const std::vector<std::vector<size_t >> inputShapes1D = {{1, 16, 32}};

const std::vector<std::vector<size_t >> kernels1D = {{1}, {3}};
const std::vector<std::vector<size_t>> strides1D = {{1}};
const std::vector<std::vector<ptrdiff_t>> padBegins1D = {{0}};
const std::vector<std::vector<ptrdiff_t>> padEnds1D = {{0}};
const std::vector<std::vector<size_t>> dilations1D = {{1}};

const auto groupConvBackpropData1DParams_ExplicitPadding = ::testing::Combine(
::testing::ValuesIn(kernels1D),
::testing::ValuesIn(strides1D),
::testing::ValuesIn(padBegins1D),
::testing::ValuesIn(padEnds1D),
::testing::ValuesIn(dilations1D),
::testing::ValuesIn(numOutChannels),
::testing::ValuesIn(numGroups),
::testing::Values(ngraph::op::PadType::EXPLICIT)
);

const auto groupConvBackpropData1DParams_AutoPadValid = ::testing::Combine(
::testing::ValuesIn(kernels1D),
::testing::ValuesIn(strides1D),
::testing::ValuesIn(padBegins1D),
::testing::ValuesIn(padEnds1D),
::testing::ValuesIn(dilations1D),
::testing::ValuesIn(numOutChannels),
::testing::ValuesIn(numGroups),
::testing::Values(ngraph::op::PadType::VALID)
);

INSTANTIATE_TEST_CASE_P(smoke_GroupConvBackpropData1D_ExplicitPadding, GroupConvBackpropDataLayerTest,
::testing::Combine(
groupConvBackpropData1DParams_ExplicitPadding,
::testing::ValuesIn(netPrecisions),
::testing::Values(InferenceEngine::Precision::UNSPECIFIED),
::testing::Values(InferenceEngine::Precision::UNSPECIFIED),
::testing::Values(InferenceEngine::Layout::ANY),
::testing::Values(InferenceEngine::Layout::ANY),
::testing::ValuesIn(inputShapes1D),
::testing::Values(CommonTestUtils::DEVICE_CPU)),
GroupConvBackpropDataLayerTest::getTestCaseName);

INSTANTIATE_TEST_CASE_P(smoke_GroupConvBackpropData1D_AutoPadValid, GroupConvBackpropDataLayerTest,
::testing::Combine(
groupConvBackpropData1DParams_AutoPadValid,
::testing::ValuesIn(netPrecisions),
::testing::Values(InferenceEngine::Precision::UNSPECIFIED),
::testing::Values(InferenceEngine::Precision::UNSPECIFIED),
::testing::Values(InferenceEngine::Layout::ANY),
::testing::Values(InferenceEngine::Layout::ANY),
::testing::ValuesIn(inputShapes1D),
::testing::Values(CommonTestUtils::DEVICE_CPU)),
GroupConvBackpropDataLayerTest::getTestCaseName);

/* ============= 2D GroupConvolution ============= */
const std::vector<std::vector<size_t >> inputShapes2D = {{1, 16, 10, 10},
{1, 32, 10, 10}};
Expand All @@ -40,8 +96,8 @@ const auto groupConvBackpropData2DParams_ExplicitPadding = ::testing::Combine(
const auto groupConvBackpropData2DParams_AutoPadValid = ::testing::Combine(
::testing::ValuesIn(kernels2D),
::testing::ValuesIn(strides2D),
::testing::Values(std::vector<ptrdiff_t>({0, 0})),
::testing::Values(std::vector<ptrdiff_t>({0, 0})),
::testing::ValuesIn(padBegins2D),
::testing::ValuesIn(padEnds2D),
::testing::ValuesIn(dilations2D),
::testing::ValuesIn(numOutChannels),
::testing::ValuesIn(numGroups),
Expand Down Expand Up @@ -94,8 +150,8 @@ const auto groupConvBackpropData3DParams_ExplicitPadding = ::testing::Combine(
const auto groupConvBackpropData3DParams_AutoPadValid = ::testing::Combine(
::testing::ValuesIn(kernels3D),
::testing::ValuesIn(strides3D),
::testing::Values(std::vector<ptrdiff_t>({0, 0, 0})),
::testing::Values(std::vector<ptrdiff_t>({0, 0, 0})),
::testing::ValuesIn(padBegins3D),
::testing::ValuesIn(padEnds3D),
::testing::ValuesIn(dilations3D),
::testing::ValuesIn(numOutChannels),
::testing::ValuesIn(numGroups),
Expand Down
Loading