Merge pull request #14489 from dkurt:fix_14464

pull/14500/head
Alexander Alekhin 6 years ago
commit 94c7d99d0d
  1. 4
      modules/dnn/src/layers/convolution_layer.cpp
  2. 22
      modules/dnn/src/layers/layers_common.cpp
  3. 5
      modules/dnn/src/layers/layers_common.hpp
  4. 2
      modules/dnn/src/layers/pooling_layer.cpp

@ -125,7 +125,7 @@ public:
inpShape.push_back(inputs[0].size[i]); inpShape.push_back(inputs[0].size[i]);
outShape.push_back(outputs[0].size[i]); outShape.push_back(outputs[0].size[i]);
} }
getConvPoolPaddings(inpShape, outShape, kernel_size, strides, padMode, dilations, pads_begin, pads_end); getConvPoolPaddings(inpShape, kernel_size, strides, padMode, pads_begin, pads_end);
if (pads_begin.size() == 2) { if (pads_begin.size() == 2) {
for (int i = 0; i < pads_begin.size(); i++) { for (int i = 0; i < pads_begin.size(); i++) {
if (pads_begin[i] != pads_end[i]) if (pads_begin[i] != pads_end[i])
@ -1257,7 +1257,7 @@ public:
inpShape.push_back(inputs[0].size[i]); inpShape.push_back(inputs[0].size[i]);
outShape.push_back(outputs[0].size[i]); outShape.push_back(outputs[0].size[i]);
} }
getConvPoolPaddings(outShape, inpShape, kernel_size, strides, padMode, dilations, pads_begin, pads_end); getConvPoolPaddings(outShape, kernel_size, strides, padMode, pads_begin, pads_end);
if (pads_begin.size() == 2) { if (pads_begin.size() == 2) {
for (int i = 0; i < pads_begin.size(); i++) { for (int i = 0; i < pads_begin.size(); i++) {
if (pads_begin[i] != pads_end[i]) if (pads_begin[i] != pads_end[i])

@ -214,25 +214,25 @@ void getConvPoolOutParams(const std::vector<int>& inp, const std::vector<size_t>
} }
} }
void getConvPoolPaddings(const std::vector<int>& inp, const std::vector<int>& out, void getConvPoolPaddings(const std::vector<int>& inp, const std::vector<size_t>& kernel,
const std::vector<size_t>& kernel, const std::vector<size_t>& strides, const std::vector<size_t>& strides, const String &padMode,
const String &padMode, const std::vector<size_t>& dilation,
std::vector<size_t>& pads_begin, std::vector<size_t>& pads_end) std::vector<size_t>& pads_begin, std::vector<size_t>& pads_end)
{ {
if (padMode == "VALID") if (padMode == "SAME" || padMode == "VALID")
{ {
pads_begin.assign(kernel.size(), 0); pads_begin.assign(kernel.size(), 0);
pads_end.assign(kernel.size(), 0); pads_end.assign(kernel.size(), 0);
} }
else if (padMode == "SAME") if (padMode == "SAME")
{ {
CV_Assert_N(kernel.size() == dilation.size(), kernel.size() == strides.size(), CV_Assert_N(kernel.size() == strides.size(), kernel.size() == inp.size());
kernel.size() == inp.size(), kernel.size() == out.size());
pads_begin.resize(kernel.size());
pads_end.resize(kernel.size());
for (int i = 0; i < pads_begin.size(); i++) { for (int i = 0; i < pads_begin.size(); i++) {
int pad = ((out[i] - 1) * strides[i] + dilation[i] * (kernel[i] - 1) + 1 - inp[i]) / 2; // There are test cases with stride > kernel.
pads_begin[i] = pads_end[i] = std::max(0, pad); if (strides[i] <= kernel[i])
{
int pad = (kernel[i] - 1 - (inp[i] - 1 + strides[i]) % strides[i]) / 2;
pads_begin[i] = pads_end[i] = pad;
}
} }
} }
} }

@ -69,9 +69,8 @@ void getConvPoolOutParams(const std::vector<int>& inp, const std::vector<size_t>
const std::vector<size_t>& stride, const String &padMode, const std::vector<size_t>& stride, const String &padMode,
const std::vector<size_t>& dilation, std::vector<int>& out); const std::vector<size_t>& dilation, std::vector<int>& out);
void getConvPoolPaddings(const std::vector<int>& inp, const std::vector<int>& out, void getConvPoolPaddings(const std::vector<int>& inp, const std::vector<size_t>& kernel,
const std::vector<size_t>& kernel, const std::vector<size_t>& strides, const std::vector<size_t>& strides, const String &padMode,
const String &padMode, const std::vector<size_t>& dilation,
std::vector<size_t>& pads_begin, std::vector<size_t>& pads_end); std::vector<size_t>& pads_begin, std::vector<size_t>& pads_end);
} }
} }

@ -143,7 +143,7 @@ public:
kernel_size = std::vector<size_t>(inp.begin(), inp.end()); kernel_size = std::vector<size_t>(inp.begin(), inp.end());
} }
getConvPoolPaddings(inp, out, kernel_size, strides, padMode, std::vector<size_t>(kernel_size.size(), 1), pads_begin, pads_end); getConvPoolPaddings(inp, kernel_size, strides, padMode, pads_begin, pads_end);
if (pads_begin.size() == 2) { if (pads_begin.size() == 2) {
pad_t = pads_begin[0]; pad_t = pads_begin[0];
pad_l = pads_begin[1]; pad_l = pads_begin[1];

Loading…
Cancel
Save