kkk
January 31, 2023, 2:38am
1
hello, I’m testing Huawei Ascend CANN.
according to guide Huawei CANN Backend · opencv/opencv Wiki · GitHub
but the sample code result in error:
[ERROR:0@0.822] global net_cann.cpp:286 compileCannGraph CANN graph check failed, ret = 4294967295
terminate called after throwing an instance of ‘cv::Exception’
what(): OpenCV(4.7.0) /usr/huaweitest1/OpenCV_4.7/opencv-4.7.0/modules/dnn/src/net_cann.cpp:286: error: (-2:Unspecified error) CANN graph check failed in function ‘compileCannGraph’
[ERROR:0@1.427] global net_cann.cpp:286 compileCannGraph CANN graph check failed, ret = 4294967295
terminate called after throwing an instance of ‘cv::Exception’
what(): OpenCV(4.7.0) /usr/huaweitest1/OpenCV_4.7/opencv-4.7.0/modules/dnn/src/net_cann.cpp:286: error: (-2:Unspecified error) CANN graph check failed in function ‘compileCannGraph’
[ERROR:0@1.959] global op_cann.cpp:258 loadToDevice CANN check failed, ret = 100000
terminate called after throwing an instance of ‘cv::Exception’
what(): OpenCV(4.7.0) /usr/huaweitest1/OpenCV_4.7/opencv-4.7.0/modules/dnn/src/op_cann.cpp:258: error: (-2:Unspecified error) CANN check failed in function ‘loadToDevice’
Aborted (core dumped)
I checked OpenCV 4.7 and CANN installation, seems fine.
Anyone knows about this issue?
appears to have been reported already (by yourself?)
opened 03:22AM - 31 Jan 23 UTC
bug
### System Information
OpenCV version: 4.7.0
Operating System / Platform: Ubun… tu 18.04
Compiler & compiler version: GCC 7.5.0
### Detailed description
I’m testing Huawei Ascend CANN hardware.
The example code is as in [Huawei CANN Backend · opencv/opencv Wiki · GitHub](https://github.com/opencv/opencv/wiki/Huawei-CANN-Backend)
but the sample code result in error:
```
[ERROR:0@0.822] global net_cann.cpp:286 compileCannGraph CANN graph check failed, ret = 4294967295
terminate called after throwing an instance of ‘cv::Exception’
what(): OpenCV(4.7.0) /usr/huaweitest1/OpenCV_4.7/opencv-4.7.0/modules/dnn/src/net_cann.cpp:286: error: (-2:Unspecified error) CANN graph check failed in function ‘compileCannGraph’
[ERROR:0@1.427] global net_cann.cpp:286 compileCannGraph CANN graph check failed, ret = 4294967295
terminate called after throwing an instance of ‘cv::Exception’
what(): OpenCV(4.7.0) /usr/huaweitest1/OpenCV_4.7/opencv-4.7.0/modules/dnn/src/net_cann.cpp:286: error: (-2:Unspecified error) CANN graph check failed in function ‘compileCannGraph’
[ERROR:0@1.959] global op_cann.cpp:258 loadToDevice CANN check failed, ret = 100000
terminate called after throwing an instance of ‘cv::Exception’
what(): OpenCV(4.7.0) /usr/huaweitest1/OpenCV_4.7/opencv-4.7.0/modules/dnn/src/op_cann.cpp:258: error: (-2:Unspecified error) CANN check failed in function ‘loadToDevice’
Aborted (core dumped)
```
I checked OpenCV 4.7 and CANN installation, seems fine. CANN's own sample code could run as well.
### Steps to reproduce
```
#include <iostream>
#include <vector>
#include "opencv2/opencv.hpp"
void preprocess(const cv::Mat& src, cv::Mat& dst)
{
src.convertTo(dst, CV_32FC3);
cv::cvtColor(dst, dst, cv::COLOR_BGR2RGB);
// center crop
cv::resize(dst, dst, cv::Size(256, 256));
cv::Rect roi(16, 16, 224, 224);
dst = dst(roi);
dst = cv::dnn::blobFromImage(dst, 1.0/255.0, cv::Size(), cv::Scalar(0.485, 0.456, 0.406));
cv::divide(dst, cv::Scalar(0.229, 0.224, 0.225), dst);
}
void softmax(const cv::Mat& src, cv::Mat& dst, int axis=1)
{
using namespace cv::dnn;
LayerParams lp;
Net netSoftmax;
netSoftmax.addLayerToPrev("softmaxLayer", "Softmax", lp);
netSoftmax.setPreferableBackend(DNN_BACKEND_OPENCV);
netSoftmax.setInput(src);
cv::Mat out = netSoftmax.forward();
out.copyTo(dst);
}
int main(int argc, char** argv)
{
using namespace cv;
Mat image = imread("/path/to/image"); // replace with the path to your image
Mat input_blob;
preprocess(image, input_blob);
dnn::Net net = dnn::readNet("/path/to/image_classification_ppresnet50_2022jan.onnx"); // replace with the path to the model
net.setPreferableBackend(dnn::DNN_BACKEND_CANN);
net.setPreferableTarget(dnn::DNN_TARGET_NPU);
net.setInput(input_blob);
Mat out = net.forward("save_infer_model/scale_0.tmp_0");
Mat prob;
softmax(out, prob, 1);
double min_val, max_val;
Point min_loc, max_loc;
minMaxLoc(prob, &min_val, &max_val, &min_loc, &max_loc);
std::cout << cv::format("cls = %d, score = %.4f\n", max_loc.x, max_val);
return 0;
}
```
The onnx model is as link https://github.com/opencv/opencv_zoo/blob/master/models/image_classification_ppresnet/image_classification_ppresnet50_2022jan.onnx
### Issue submission checklist
- [x] I report the issue, it's not a question
- [X] I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
- [X] I updated to the latest OpenCV version and the issue is still there
- [X] There is reproducer code and related data files (videos, images, onnx, etc)
kkk
February 1, 2023, 1:51am
3
Yes. I’m not sure the forum or github will have the solution.