mirror of
https://github.com/opencv/opencv.git
synced 2025-08-06 06:26:29 +08:00
dnn(ocl4dnn): add extra checks to convolution layer
- prevent running code over unsupported/non-tested configurations - prevent integer div by zero
This commit is contained in:
parent
a3d7811f24
commit
724e04e979
@ -46,6 +46,7 @@
|
|||||||
#include "../op_inf_engine.hpp"
|
#include "../op_inf_engine.hpp"
|
||||||
#include "../ie_ngraph.hpp"
|
#include "../ie_ngraph.hpp"
|
||||||
|
|
||||||
|
#include <opencv2/core/utils/configuration.private.hpp>
|
||||||
#include <opencv2/core/utils/logger.hpp>
|
#include <opencv2/core/utils/logger.hpp>
|
||||||
|
|
||||||
#include "opencv2/core/hal/hal.hpp"
|
#include "opencv2/core/hal/hal.hpp"
|
||||||
@ -1494,7 +1495,26 @@ public:
|
|||||||
config.pad = pad;
|
config.pad = pad;
|
||||||
config.stride = stride;
|
config.stride = stride;
|
||||||
config.dilation = dilation;
|
config.dilation = dilation;
|
||||||
|
if (inputs[0].dims != 4 && inputs[0].dims != umat_blobs[0].dims)
|
||||||
|
{
|
||||||
|
static bool bypassCheck = utils::getConfigurationParameterBool("OPENCV_OCL4DNN_CONVOLUTION_IGNORE_INPUT_DIMS_4_CHECK", false);
|
||||||
|
if (!bypassCheck)
|
||||||
|
{
|
||||||
|
CV_LOG_ERROR(NULL, "DNN/OpenCL: Unsupported configuration: inputs[0].dims=" << inputs[0].dims << " umat_blobs[0].dims=" << umat_blobs[0].dims
|
||||||
|
<< ". Consider reporting complete reproducer to https://github.com/opencv/opencv/issues/20833."
|
||||||
|
<< " You can skip this check temporary through OPENCV_OCL4DNN_CONVOLUTION_IGNORE_INPUT_DIMS_4_CHECK=1"
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
config.group = inputs[0].size[1] / umat_blobs[0].size[1];
|
config.group = inputs[0].size[1] / umat_blobs[0].size[1];
|
||||||
|
if (config.group < 1) // config.group == 0 causes div by zero in ocl4dnn code
|
||||||
|
{
|
||||||
|
CV_LOG_WARNING(NULL, "DNN/OpenCL: Unsupported config.group=" << config.group
|
||||||
|
<< ". Consider reporting complete reproducer to https://github.com/opencv/opencv/issues/20833"
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
config.bias_term = umat_blobs.size() == 2;
|
config.bias_term = umat_blobs.size() == 2;
|
||||||
config.use_half = use_half;
|
config.use_half = use_half;
|
||||||
|
|
||||||
|
@ -167,6 +167,7 @@ OCL4DNNConvSpatial<Dtype>::OCL4DNNConvSpatial(OCL4DNNConvConfig config)
|
|||||||
channels_ = config.in_shape[dims - spatial_dims - 1];
|
channels_ = config.in_shape[dims - spatial_dims - 1];
|
||||||
num_output_ = config.out_shape[dims - spatial_dims - 1];
|
num_output_ = config.out_shape[dims - spatial_dims - 1];
|
||||||
group_ = config.group;
|
group_ = config.group;
|
||||||
|
CV_CheckGT(group_, 0, ""); // avoid div by zero below
|
||||||
|
|
||||||
fused_activ_ = OCL4DNN_CONV_FUSED_ACTIV_NONE;
|
fused_activ_ = OCL4DNN_CONV_FUSED_ACTIV_NONE;
|
||||||
fused_eltwise_ = false;
|
fused_eltwise_ = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user