Merge pull request #14489 from dkurt:fix_14464

This commit is contained in:
Alexander Alekhin 2019-05-06 19:16:26 +00:00
commit 94c7d99d0d
4 changed files with 16 additions and 17 deletions

View File

@ -125,7 +125,7 @@ public:
inpShape.push_back(inputs[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) {
for (int i = 0; i < pads_begin.size(); i++) {
if (pads_begin[i] != pads_end[i])
@ -1257,7 +1257,7 @@ public:
inpShape.push_back(inputs[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) {
for (int i = 0; i < pads_begin.size(); i++) {
if (pads_begin[i] != pads_end[i])

View File

@ -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,
const std::vector<size_t>& kernel, const std::vector<size_t>& strides,
const String &padMode, const std::vector<size_t>& dilation,
void getConvPoolPaddings(const std::vector<int>& inp, const std::vector<size_t>& kernel,
const std::vector<size_t>& strides, const String &padMode,
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_end.assign(kernel.size(), 0);
}
else if (padMode == "SAME")
if (padMode == "SAME")
{
CV_Assert_N(kernel.size() == dilation.size(), kernel.size() == strides.size(),
kernel.size() == inp.size(), kernel.size() == out.size());
pads_begin.resize(kernel.size());
pads_end.resize(kernel.size());
CV_Assert_N(kernel.size() == strides.size(), kernel.size() == inp.size());
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;
pads_begin[i] = pads_end[i] = std::max(0, pad);
// There are test cases with stride > kernel.
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;
}
}
}
}

View File

@ -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>& dilation, std::vector<int>& out);
void getConvPoolPaddings(const std::vector<int>& inp, const std::vector<int>& out,
const std::vector<size_t>& kernel, const std::vector<size_t>& strides,
const String &padMode, const std::vector<size_t>& dilation,
void getConvPoolPaddings(const std::vector<int>& inp, const std::vector<size_t>& kernel,
const std::vector<size_t>& strides, const String &padMode,
std::vector<size_t>& pads_begin, std::vector<size_t>& pads_end);
}
}

View File

@ -143,7 +143,7 @@ public:
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) {
pad_t = pads_begin[0];
pad_l = pads_begin[1];