Commit 2139dc75 authored by tsocha's avatar tsocha Committed by Michał Karzyński

[ONNX] Add support for negative calculated padding (#2521)

parent 23f29e88
...@@ -171,15 +171,19 @@ namespace ngraph ...@@ -171,15 +171,19 @@ namespace ngraph
} }
for (int i = 0; i < num_spatial_dims; ++i) for (int i = 0; i < num_spatial_dims; ++i)
{ {
padding_below[i] = (strides[i] * (data_shape[i + 2] - 1) + padding_below[i] = strides[i] * (data_shape[i + 2] - 1) +
dilations[i] * (weights_shape[i + 2] - 1) - dilations[i] * (weights_shape[i + 2] - 1) -
data_dilation_strides[i] * data_dilation_strides[i] *
(output_shape[i] - output_padding[i] - 1)) / (output_shape[i] - output_padding[i] - 1);
2; if (padding_below[i] < 0)
if (static_cast<int>(padding_below[i]) < 0)
{ {
output_padding[i] = -static_cast<int>(padding_below[i]); // (int) -9 / 2 = -5 but we need -4
padding_below[i] = 0; // (int) -9 --> 9 / 2 = 4 --> -4
padding_below[i] = -(-padding_below[i] / 2);
}
else
{
padding_below[i] /= 2;
} }
padding_above[i] = padding_below[i]; padding_above[i] = padding_below[i];
data_batch_shape[i + 2] = output_shape[i]; data_batch_shape[i + 2] = output_shape[i];
...@@ -187,7 +191,7 @@ namespace ngraph ...@@ -187,7 +191,7 @@ namespace ngraph
} }
else else
{ {
for (int i = 0; i < num_spatial_dims && output_shape.empty(); ++i) for (int i = 0; i < num_spatial_dims; ++i)
{ {
// Calculating spatial dims of data output shape for ngraph conv backprop op // Calculating spatial dims of data output shape for ngraph conv backprop op
// | s(ds-1) + d(ws-1) - pb - pa | // | s(ds-1) + d(ws-1) - pb - pa |
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment