Repository: opencv
Issue: DNN test verification failed running wechat_qrcode detector using DNN_TARGET_OPENCL
Labels: category: ocl,category: dnn

##### System information (version)
- OpenCV => 4.6.0
- Operating System / Platform => Fedora 37 (rawhide) 64 Bit
- Compiler => gcc 12.1.1

##### Detailed description

Got many ```test verification failed``` errors trying to run wechat_qrcode detector using DNN_TARGET_OPENCL:
```
[ INFO:0@0.033] global /builddir/build/BUILD/opencv-4.6.0/modules/core/src/parallel/registry_parallel.impl.hpp (96) ParallelBackendRegistry core(parallel): Enabled backends(2, sorted by priority): TBB(1000); OPENMP(990)
[ INFO:0@0.033] global /builddir/build/BUILD/opencv-4.6.0/modules/core/include/opencv2/core/parallel/backend/parallel_for.tbb.hpp (54) ParallelForBackend Initializing TBB parallel backend: TBB_INTERFACE_VERSION=11103
[ INFO:0@0.033] global /builddir/build/BUILD/opencv-4.6.0/modules/core/src/parallel/parallel.cpp (77) createParallelForAPI core(parallel): using backend: TBB (priority=1000)
Attempting to upgrade batch norm layers using deprecated params: detect.prototxt
Successfully upgraded batch norm layers using deprecated params.
Attempting to upgrade batch norm layers using deprecated params: detect.caffemodel
Successfully upgraded batch norm layers using deprecated params.
[ INFO:0@0.052] global /builddir/build/BUILD/opencv-4.6.0/modules/core/src/ocl.cpp (1186) haveOpenCL Initialize OpenCL runtime...
[ INFO:0@0.101] global /builddir/build/BUILD/opencv-4.6.0/modules/core/src/ocl.cpp (1192) haveOpenCL OpenCL: found 1 platforms
[ INFO:0@0.101] global /builddir/build/BUILD/opencv-4.6.0/modules/core/src/ocl.cpp (984) getInitializedExecutionContext OpenCL: initializing thread execution context
[ INFO:0@0.101] global /builddir/build/BUILD/opencv-4.6.0/modules/core/src/ocl.cpp (994) getInitializedExecutionContext OpenCL: creating new execution context...
[ INFO:0@0.101] global /builddir/build/BUILD/opencv-4.6.0/modules/core/src/ocl.cpp (1012) getInitializedExecutionContext OpenCL: device=Intel(R) UHD Graphics 600 [0x3185]
[ INFO:0@0.106] global /builddir/build/BUILD/opencv-4.6.0/modules/core/src/ocl.cpp (5370) __init_buffer_pools OpenCL: Initializing buffer pool for context@0 with max capacity: poolSize=134217728 poolSizeHostPtr=134217728
[ INFO:0@0.134] global /builddir/build/BUILD/opencv-4.6.0/modules/core/src/ocl.cpp (410) OpenCLBinaryCacheConfigurator Successfully initialized OpenCL cache directory: /root/.cache/opencv/4.6/opencl_cache/
[ INFO:0@0.134] global /builddir/build/BUILD/opencv-4.6.0/modules/core/src/ocl.cpp (434) prepareCacheDirectoryForContext Preparing OpenCL cache configuration for context: 32-bit--Intel_R__Corporation--Intel_R__UHD_Graphics_600__0x3185_--22_26_23599
[ WARN:0@0.140] global /builddir/build/BUILD/opencv-4.6.0/modules/dnn/src/ocl4dnn/src/ocl4dnn_conv_spatial.cpp (1924) loadTunedConfig OpenCV(ocl4dnn): consider to specify kernel configuration cache directory through OPENCV_OCL4DNN_CONFIG_PATH parameter.
[ERROR:0@0.158] global /builddir/build/BUILD/opencv-4.6.0/modules/dnn/src/ocl4dnn/src/ocl4dnn_conv_spatial.cpp (1204) verifyResult Kernel: U_GEMM_LIKE_CONV_k1x1_cn24_g1_s1x1_d1x1_b1_in144x80_p0x0_num1_M16_activ1_eltwise0_FP32_5_1_8_32_SIMD8
[ERROR:0@0.158] global /builddir/build/BUILD/opencv-4.6.0/modules/dnn/src/ocl4dnn/src/ocl4dnn_conv_spatial.cpp (1207) verifyResult test verification failed @ image 0 group 0 out_ch 8 h 0 w 0 (offset: 79800) got 0 expected 0.41817
[ERROR:0@0.158] global /builddir/build/BUILD/opencv-4.6.0/modules/dnn/src/ocl4dnn/src/ocl4dnn_conv_spatial.cpp (1207) verifyResult test verification failed @ image 0 group 0 out_ch 8 h 0 w 1 (offset: 79801) got 0 expected 0.450706
[ERROR:0@0.158] global /builddir/build/BUILD/opencv-4.6.0/modules/dnn/src/ocl4dnn/src/ocl4dnn_conv_spatial.cpp (1207) verifyResult test verification failed @ image 0 group 0 out_ch 8 h 0 w 2 (offset: 79802) got 0 expected 0.450878
[ERROR:0@0.158] global /builddir/build/BUILD/opencv-4.6.0/modules/dnn/src/ocl4dnn/src/ocl4dnn_conv_spatial.cpp (1207) verifyResult test verification failed @ image 0 group 0 out_ch 8 h 0 w 3 (offset: 79803) got 0 expected 0.455803
[ERROR:0@0.158] global /builddir/build/BUILD/opencv-4.6.0/modules/dnn/src/ocl4dnn/src/ocl4dnn_conv_spatial.cpp (1207) verifyResult test verification failed @ image 0 group 0 out_ch 8 h 0 w 4 (offset: 79804) got 0 expected 0.459062
[ERROR:0@0.158] global /builddir/build/BUILD/opencv-4.6.0/modules/dnn/src/ocl4dnn/src/ocl4dnn_conv_spatial.cpp (1207) verifyResult test verification failed @ image 0 group 0 out_ch 8 h 0 w 5 (offset: 79805) got 0 expected 0.458867
[ERROR:0@0.158] global /builddir/build/BUILD/opencv-4.6.0/modules/dnn/src/ocl4dnn/src/ocl4dnn_conv_spatial.cpp (1207) verifyResult test verification failed @ image 0 group 0 out_ch 8 h 0 w 6 (offset: 79806) got 0 expected 0.460624
[ERROR:0@0.158] global /builddir/build/BUILD/opencv-4.6.0/modules/dnn/src/ocl4dnn/src/ocl4dnn_conv_spatial.cpp (1207) verifyResult test verification failed @ image 0 group 0 out_ch 8 h 0 w 7 (offset: 79807) got 0 expected 0.459307
[ERROR:0@0.158] global /builddir/build/BUILD/opencv-4.6.0/modules/dnn/src/ocl4dnn/src/ocl4dnn_conv_spatial.cpp (1207) verifyResult test verification failed @ image 0 group 0 out_ch 8 h 0 w 8 (offset: 79808) got 0 expected 0.462349
[ERROR:0@0.158] global /builddir/build/BUILD/opencv-4.6.0/modules/dnn/src/ocl4dnn/src/ocl4dnn_conv_spatial.cpp (1207) verifyResult test verification failed @ image 0 group 0 out_ch 8 h 0 w 9 (offset: 79809) got 0 expected 0.457633
[ERROR:0@0.166] global /builddir/build/BUILD/opencv-4.6.0/modules/dnn/src/ocl4dnn/src/ocl4dnn_conv_spatial.cpp (1204) verifyResult Kernel: U_GEMM_LIKE_CONV_k1x1_cn16_g1_s1x1_d1x1_b1_in80x48_p0x0_num1_M64_activ1_eltwise0_FP32_5_1_8_32_SIMD8
[ERROR:0@0.167] global /builddir/build/BUILD/opencv-4.6.0/modules/dnn/src/ocl4dnn/src/ocl4dnn_conv_spatial.cpp (1207) verifyResult test verification failed @ image 0 group 0 out_ch 8 h 0 w 0 (offset: 20368) got -0 expected 0.583859
[ERROR:0@0.167] global /builddir/build/BUILD/opencv-4.6.0/modules/dnn/src/ocl4dnn/src/ocl4dnn_conv_spatial.cpp (1207) verifyResult test verification failed @ image 0 group 0 out_ch 8 h 0 w 1 (offset: 20369) got -0 expected 0.687613
[ERROR:0@0.167] global /builddir/build/BUILD/opencv-4.6.0/modules/dnn/src/ocl4dnn/src/ocl4dnn_conv_spatial.cpp (1207) verifyResult test verification failed @ image 0 group 0 out_ch 8 h 0 w 2 (offset: 20370) got -0 expected 0.702017
[ERROR:0@0.167] global /builddir/build/BUILD/opencv-4.6.0/modules/dnn/src/ocl4dnn/src/ocl4dnn_conv_spatial.cpp (1207) verifyResult test verification failed @ image 0 group 0 out_ch 8 h 0 w 3 (offset: 20371) got -0 expected 0.707679
[ERROR:0@0.167] global /builddir/build/BUILD/opencv-4.6.0/modules/dnn/src/ocl4dnn/src/ocl4dnn_conv_spatial.cpp (1207) verifyResult test verification failed @ image 0 group 0 out_ch 8 h 0 w 4 (offset: 20372) got -0 expected 0.689535
[ERROR:0@0.167] global /builddir/build/BUILD/opencv-4.6.0/modules/dnn/src/ocl4dnn/src/ocl4dnn_conv_spatial.cpp (1207) verifyResult test verification failed @ image 0 group 0 out_ch 8 h 0 w 5 (offset: 20373) got -0 expected 0.700073
[ERROR:0@0.167] global /builddir/build/BUILD/opencv-4.6.0/modules/dnn/src/ocl4dnn/src/ocl4dnn_conv_spatial.cpp (1207) verifyResult test verification failed @ image 0 group 0 out_ch 8 h 0 w 6 (offset: 20374) got -0 expected 0.710513
[ERROR:0@0.167] global /builddir/build/BUILD/opencv-4.6.0/modules/dnn/src/ocl4dnn/src/ocl4dnn_conv_spatial.cpp (1207) verifyResult test verification failed @ image 0 group 0 out_ch 8 h 0 w 7 (offset: 20375) got -0 expected 0.700632
[ERROR:0@0.167] global /builddir/build/BUILD/opencv-4.6.0/modules/dnn/src/ocl4dnn/src/ocl4dnn_conv_spatial.cpp (1207) verifyResult test verification failed @ image 0 group 0 out_ch 8 h 0 w 8 (offset: 20376) got -0 expected 0.72938
[ERROR:0@0.167] global /builddir/build/BUILD/opencv-4.6.0/modules/dnn/src/ocl4dnn/src/ocl4dnn_conv_spatial.cpp (1207) verifyResult test verification failed @ image 0 group 0 out_ch 8 h 0 w 9 (offset: 20377) got -0 expected 0.708224
...
```

No errors on CPU target.

`detect.prototxt` and `detect.caffeemodel` from wechat qrcode repo:
https://github.com/WeChatCV/opencv_3rdparty

Test image `289.jpg`:
![289](https://user-images.githubusercontent.com/15442365/178624357-a7a2ef8d-e4d8-4df6-8d59-f88cb7692b54.jpg)

[clinfo.txt](https://github.com/opencv/opencv/files/9097892/clinfo.txt)

##### Steps to reproduce

Compile and run the following code:
```.cpp
#include <opencv2/opencv.hpp>

using namespace cv;
using namespace cv::dnn;

int main(int, char**)
{
    Mat img = imread("289.jpg");

    Mat gray;
    cvtColor(img, gray, COLOR_BGR2GRAY);

    Net net = readNetFromCaffe(
        "detect.prototxt",
        "detect.caffemodel"
    );
    net.setPreferableBackend(DNN_BACKEND_OPENCV);
    net.setPreferableTarget(DNN_TARGET_OPENCL);

    Mat detect;
    resize(gray, detect, Size(533, 300), 0, 0, INTER_LINEAR);

    Mat blob = blobFromImage(detect, 1.0 / 255, Size(detect.cols, detect.rows),
                             {0.0f, 0.0f, 0.0f}, false, false);

    net.setInput(blob, "data");
    net.forward("detection_output");

    return 0;
}

```



##### Issue submission checklist

 - [x] I report the issue, it's not a question
   <!--
   OpenCV team works with forum.opencv.org, Stack Overflow and other communities
   to discuss problems. Tickets with questions without a real issue statement will be
   closed.
   -->
 - [x] I checked the problem with documentation, FAQ, open issues,
       forum.opencv.org, Stack Overflow, etc and have not found any solution
   <!--
   Places to check:
   * OpenCV documentation: https://docs.opencv.org
   * FAQ page: https://github.com/opencv/opencv/wiki/FAQ
   * OpenCV forum: https://forum.opencv.org
   * OpenCV issue tracker: https://github.com/opencv/opencv/issues?q=is%3Aissue
   * Stack Overflow branch: https://stackoverflow.com/questions/tagged/opencv
   -->
 - [x] I updated to the latest OpenCV version and the issue is still there
   <!--
   master branch for OpenCV 4.x and 3.4 branch for OpenCV 3.x releases.
   OpenCV team supports only the latest release for each branch.
   The ticket is closed if the problem is not reproduced with the modern version.
   -->
 - [x] There is reproducer code and related data files: videos, images, onnx, etc
   <!--
   The best reproducer -- test case for OpenCV that we can add to the library.
   Recommendations for media files and binary files:
   * Try to reproduce the issue with images and videos in opencv_extra repository
     to reduce attachment size
   * Use PNG for images, if you report some CV related bug, but not image reader
     issue
   * Attach the image as an archive to the ticket, if you report some reader issue.
     Image hosting services compress images and it breaks the repro code.
   * Provide ONNX file for some public model or ONNX file with random weights,
     if you report ONNX parsing or handling issue. Architecture details diagram
     from netron tool can be very useful too. See https://lutzroeder.github.io/netron/
   -->