Merge pull request #23319 from fengyuentau:fix_zoo_issue_136

Related issue: https://github.com/opencv/opencv_zoo/issues/136

Features added:

- Support operators with multiple output: ONNX Split.
- Support Slice without steps.

Bugs fixed:

- Wrong settings in ClipByValue (Relu6).
- Wrong calculation of pads in convolution layer (It is wrong generally but only fixed specifically for CANN for now).

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
Yuantao Feng
2023-03-14 02:46:33 +08:00
committed by GitHub
parent e03e2e7f94
commit b94e13c8ae
23 changed files with 317 additions and 202 deletions

View File

@@ -392,7 +392,8 @@ public:
#endif // HAVE_HALIDE
#ifdef HAVE_CANN
virtual Ptr<BackendNode> initCann(const std::vector<Ptr<BackendWrapper> > &inputsWrapper, const int index, const std::vector<Ptr<BackendNode> >& nodes) CV_OVERRIDE
virtual Ptr<BackendNode> initCann(const std::vector<Ptr<BackendWrapper> > &inputsWrapper,
const std::vector<Ptr<BackendNode> >& nodes) CV_OVERRIDE
{
CV_Assert(nodes.size() == 1);
CV_Assert(blobs.size() == 4); // must have scale, offset, mean and variance
@@ -401,8 +402,7 @@ public:
auto channel = x->host->size[1];
// create operator
std::string op_name = cv::format("bn_%d", index);
auto op = std::make_shared<ge::op::BatchNorm>(op_name);
auto op = std::make_shared<ge::op::BatchNorm>(name);
// set attributes
op->set_attr_epsilon(epsilon);
@@ -412,24 +412,24 @@ public:
// set inputs
// set inputs : x
auto op_x = nodes[0].dynamicCast<CannBackendNode>()->getOp();
op->set_input_x_by_name(*op_x, "y");
op->set_input_x_by_name(*op_x, x->name.c_str());
auto x_desc = x->getTensorDesc();
op->update_input_desc_x(*x_desc);
// set inputs : scale (blobs[2])
std::vector<int> shape_{channel};
auto op_const_scale = std::make_shared<CannConstOp>(blobs[2].data, blobs[2].type(), shape_, cv::format("%s_scale", op_name.c_str()));
auto op_const_scale = std::make_shared<CannConstOp>(blobs[2].data, blobs[2].type(), shape_, cv::format("%s_scale", name.c_str()));
op->set_input_scale(*(op_const_scale->getOp()));
op->update_input_desc_scale(*(op_const_scale->getTensorDesc()));
// set inputs : offset (blobs[3])
auto op_const_offset = std::make_shared<CannConstOp>(blobs[3].data, blobs[3].type(), shape_, cv::format("%s_offset", op_name.c_str()));
auto op_const_offset = std::make_shared<CannConstOp>(blobs[3].data, blobs[3].type(), shape_, cv::format("%s_offset", name.c_str()));
op->set_input_offset(*(op_const_offset->getOp()));
op->update_input_desc_offset(*(op_const_offset->getTensorDesc()));
// set inputs : mean (blobs[0])
auto op_const_mean = std::make_shared<CannConstOp>(blobs[0].data, blobs[0].type(), shape_, cv::format("%s_mean", op_name.c_str()));
auto op_const_mean = std::make_shared<CannConstOp>(blobs[0].data, blobs[0].type(), shape_, cv::format("%s_mean", name.c_str()));
op->set_input_mean(*(op_const_mean->getOp()));
op->update_input_desc_mean(*(op_const_mean->getTensorDesc()));
// set inputs : variance (blobs[1])
auto op_const_var = std::make_shared<CannConstOp>(blobs[1].data, blobs[1].type(), shape_, cv::format("%s_var", op_name.c_str()));
auto op_const_var = std::make_shared<CannConstOp>(blobs[1].data, blobs[1].type(), shape_, cv::format("%s_var", name.c_str()));
op->set_input_variance(*(op_const_var->getOp()));
op->update_input_desc_variance(*(op_const_var->getTensorDesc()));