Repository: opencv
Issue: OpenCV 4.9.0 Huawei CANN support error: CANN graph check failed in function 'compileCannGraph'
Labels: bug,category: dnn

### System Information

OpenCV version: 4.9.0
Operation System:  Ubuntu 18.04.6 LTS
Compile : gcc (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04) 7.5.0
CANN : 6.0.1 
Python: 3.9.2

NPU info:
```
# npu-smi info
+--------------------------------------------------------------------------------------------------------+
| npu-smi 23.0.rc3                                 Version: 23.0.rc3                                     |
+-------------------------------+-----------------+------------------------------------------------------+
| NPU     Name                  | Health          | Power(W)     Temp(C)           Hugepages-Usage(page) |
| Chip    Device                | Bus-Id          | AICore(%)    Memory-Usage(MB)                        |
+===============================+=================+======================================================+
| 32800   310P3                 | OK              | NA           47                0     / 0             |
| 0       0                     | 0000:82:00.0    | 0            1764 / 21527                            |
+===============================+=================+======================================================+
+-------------------------------+-----------------+------------------------------------------------------+
| NPU     Chip                  | Process id      | Process name             | Process memory(MB)        |
+===============================+=================+======================================================+
| No running processes found in NPU 32800                                                                |
+===============================+=================+======================================================+
```

### Detailed description

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:

```
python /home/apulis/infer_test/reset50.py 
Ascend310P3
[ERROR:0@5.011] global net_cann.cpp:317 compileCannGraph CANN graph check failed, ret = 1343266818
Traceback (most recent call last):
  File "/home/apulis/infer_test/reset50.py", line 29, in <module>
    output_blob = net.forward("save_infer_model/scale_0.tmp_0")
cv2.error: OpenCV(4.9.0) /home/apulis/opencv_office/modules/dnn/src/net_cann.cpp:317: error: (-2:Unspecified error) CANN graph check failed in function 'compileCannGraph'

Ascend310P3
[ERROR:0@10.466] global net_cann.cpp:317 compileCannGraph CANN graph check failed, ret = 1343266818
Traceback (most recent call last):
  File "/home/apulis/infer_test/reset50.py", line 29, in <module>
    output_blob = net.forward("save_infer_model/scale_0.tmp_0")
cv2.error: OpenCV(4.9.0) /home/apulis/opencv_office/modules/dnn/src/net_cann.cpp:317: error: (-2:Unspecified error) CANN graph check failed in function 'compileCannGraph'

[ERROR:0@11.904] global op_cann.cpp:258 loadToDevice CANN check failed, ret = 100000
Traceback (most recent call last):
  File "/home/apulis/infer_test/reset50.py", line 29, in <module>
    output_blob = net.forward("save_infer_model/scale_0.tmp_0")
cv2.error: OpenCV(4.9.0) /home/apulis/opencv_office/modules/dnn/src/op_cann.cpp:258: error: (-2:Unspecified error) CANN check failed in function 'loadToDevice'

```

### Steps to reproduce


```
 cat /home/apulis/infer_test/reset50.py 
import numpy as np
import cv2 as cv

def preprocess(image):
    out = image.copy()

    out = cv.resize(out, (256, 256))
    out = out[16:240, 16:240, :]
    out = cv.dnn.blobFromImage(out, 1.0/255.0, mean=(0.485, 0.456, 0.406), swapRB=True)
    out = out / np.array([0.229, 0.224, 0.225]).reshape(1, -1, 1, 1)

    return out

def softmax(blob, axis=1):
    out = blob.copy().astype(np.float64)

    e_blob = np.exp(out)
    return e_blob / np.sum(e_blob, axis=axis)


image = cv.imread("/home/apulis/samples/inference/modelInference/sampleResnetQuickStart/data/dog1_1024_683.jpg") # replace with the path to your image
input_blob = preprocess(image)

net = cv.dnn.readNet("/home/apulis/pyacl/resnet50.onnx") # # replace with the path to the model
net.setPreferableBackend(cv.dnn.DNN_BACKEND_CANN)
net.setPreferableTarget(cv.dnn.DNN_TARGET_NPU)

net.setInput(input_blob)
output_blob = net.forward("save_infer_model/scale_0.tmp_0")

prob = softmax(output_blob, axis=1)
_, max_prob, _, max_loc = cv.minMaxLoc(prob)
print("cls = {}, score = {:.4f}".format(max_loc[0], max_prob))
```

### Issue submission checklist

- [X] I report the issue, it's not a question
- [ ] 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
- [ ] There is reproducer code and related data files (videos, images, onnx, etc)