Update check params

pull/16223/head
Liubov Batanina 5 years ago
parent 97455f1593
commit d825caf18e
  1. 55
      modules/dnn/src/layers/layers_common.cpp
  2. 9
      modules/dnn/src/layers/pooling_layer.cpp

@ -162,6 +162,7 @@ void getPoolingKernelParams(const LayerParams &params, std::vector<size_t>& kern
}
else
{
util::getStrideAndPadding(params, pads_begin, pads_end, strides, padMode);
if ((globalPooling[0] && params.has("kernel_d")) ||
(globalPooling[1] && params.has("kernel_h")) ||
(globalPooling[2] && params.has("kernel_w")) ||
@ -170,60 +171,18 @@ void getPoolingKernelParams(const LayerParams &params, std::vector<size_t>& kern
}
kernel.resize(3);
pads_begin.resize(3, 0);
pads_end.resize(3, 0);
strides.resize(3, 1);
kernel[0] = params.get<int>("kernel_d", 1);
kernel[1] = params.get<int>("kernel_h", 1);
kernel[2] = params.get<int>("kernel_w", 1);
pads_begin[1] = params.get<int>("pad_t", 0);
pads_begin[2] = params.get<int>("pad_l", 0);
pads_end[1] = params.get<int>("pad_b", 0);
pads_end[2] = params.get<int>("pad_r", 0);
if (params.has("pad_h")) {
pads_begin[1] = params.get<int>("pad_h");
pads_end[1] = params.get<int>("pad_h");
for (int i = 0, j = globalPooling.size() - pads_begin.size(); i < pads_begin.size(); i++, j++) {
if ((pads_begin[i] != 0 || pads_end[i] != 0) && globalPooling[j])
CV_Error(cv::Error::StsBadArg, "In global_pooling mode, pads must be = 0");
}
if (params.has("pad_w")) {
pads_begin[2] = params.get<int>("pad_w");
pads_end[2] = params.get<int>("pad_w");
for (int i = 0, j = globalPooling.size() - strides.size(); i < strides.size(); i++, j++) {
if (strides[i] != 1 && globalPooling[j])
CV_Error(cv::Error::StsBadArg, "In global_pooling mode, strides must be = 1");
}
if (params.has("pad")) {
DictValue param = params.get("pad");
if (param.size() == 1) {
std::fill(pads_begin.begin(), pads_begin.end(), param.get<int>(0));
pads_end = pads_begin;
} else if (param.size() <= pads_begin.size()) {
for (int i = param.size() - 1, j = pads_begin.size() - 1; i >= 0; i--, j--) {
pads_begin[j] = param.get<int>(i);
}
pads_end = pads_begin;
} else {
for (int i = param.size() - 1, j = pads_begin.size() - 1; i >= param.size() / 2; i--, j--) {
pads_begin[j] = param.get<int>(i);
}
for (int i = param.size() / 2 - 1, j = pads_end.size() / 2 - 1; i >= 0; i--, j--) {
pads_end[j] = param.get<int>(i);
}
}
}
strides[1] = params.get<int>("stride_h", 1);
strides[2] = params.get<int>("stride_w", 1);
if (params.has("stride")) {
DictValue param = params.get("stride");
for (int i = param.size() - 1, j = strides.size() - 1; i >= 0; i--, j--) {
strides[j] = param.get<int>(i);
}
if (param.size() == 1)
std::fill(strides.begin() + 1, strides.end(), strides[0]);
}
for (int i = 0; i < pads_begin.size(); i++) {
if ((pads_begin[i] != 0 || pads_end[i] != 0 || strides[i] != 1) && globalPooling[i])
CV_Error(cv::Error::StsBadArg, "In global_pooling mode, pads must be = 0 and strides must be = 1");
}
}
}

@ -151,9 +151,6 @@ public:
if (kernel_size.size() > inp.size()) {
kernel_size.erase(kernel_size.begin());
strides.erase(strides.begin());
pads_begin.erase(pads_begin.begin());
pads_end.erase(pads_end.begin());
}
kernel_size.resize(out.size());
@ -1025,16 +1022,16 @@ virtual Ptr<BackendNode> initNgraph(const std::vector<Ptr<BackendWrapper> >& inp
else if (padMode.empty())
{
for (int i = 0, j = local_kernel.size() - inpShape.size(); i < inpShape.size(); i++, j++) {
float dst = (float)(inpShape[i] + pads_begin[j] + pads_end[j] - local_kernel[j]) / strides[j];
float dst = (float)(inpShape[i] + pads_begin[i] + pads_end[i] - local_kernel[j]) / strides[i];
outShape.push_back(1 + (ceilMode ? ceil(dst) : floor(dst)));
}
// If we have padding, ensure that the last pooling starts strictly
// inside the image (instead of at the padding); otherwise clip the last.
for (int i = 0, j = local_kernel.size() - inpShape.size(); i < inpShape.size(); i++, j++) {
if (pads_end[j] && (outShape[2 + i] - 1) * strides[j] >= inpShape[i] + pads_end[j]) {
if (pads_end[i] && (outShape[2 + i] - 1) * strides[i] >= inpShape[i] + pads_end[i]) {
--outShape[2 + i];
CV_Assert((outShape[2 + i] - 1) * strides[j] < inpShape[i] + pads_end[j]);
CV_Assert((outShape[2 + i] - 1) * strides[i] < inpShape[i] + pads_end[i]);
}
}
}

Loading…
Cancel
Save