<h5 dir="auto">System information (version)</h5>

<ul dir="auto">
<li>OpenCV =&gt;  4.5.1</li>
<li>Operating System / Platform =&gt; Linux Ubuntu18.04</li>
<li>Compiler =&gt; g++ 7.4.0</li>
<li>CUDA =&gt; 10.0</li>
<li>cudnn =&gt; 7.6.3</li>
<li>GPU=&gt; GTX1080</li>
</ul>
<h5 dir="auto">Detailed description</h5>
<p dir="auto">I use opencv dnn(gpu) to load onnx face detection model (centerface) for inference, The time used for single reasoning  on GTX1080  is 100ms ,  cpu time About 40 ms， （image size 480*640）</p>
<p dir="auto">My cmake config:</p>
<p dir="auto">cmake -D CMAKE_BUILD_TYPE=RELEASE <br>
-D CMAKE_INSTALL_PREFIX=/usr/local<br>
-D INSTALL_PYTHON_EXAMPLES=ON <br>
-D INSTALL_C_EXAMPLES=OFF <br>
-D OPENCV_ENABLE_NONFREE=ON <br>
-D WITH_CUDA=ON <br>
-D WITH_CUDNN=ON <br>
-D OPENCV_DNN_CUDA=ON <br>
-D ENABLE_FAST_MATH=1 <br>
-D CUDA_FAST_MATH=1 <br>
-D CUDA_ARCH_BIN=6.1 <br>
-D WITH_CUBLAS=1 <br>
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules <br>
-D BUILD_opencv_python2=OFF <br>
-D BUILD_opencv_python3=ON <br>
-D PYTHON_DEFAULT_EXECUTABLE=${VIRTUAL_PYTHON_PATH}/bin/python3 <br>
-D PYTHON3_EXCUTABLE=${VIRTUAL_PYTHON_PATH}/bin/python3 <br>
-D PYTHON3_LIBRARY=${VIRTUAL_PYTHON_PATH}/lib/lib${PYTHON_VERSION}m.so.1.0 <br>
-D PYTHON_NUMPY_PATH=${VIRTUAL_PYTHON_PATH}/lib/${PYTHON_VERSION}/site-packages <br>
-D BUILD_EXAMPLES=ON ../</p>
<h5 dir="auto">Steps to reproduce</h5>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import cv2
import time
import numpy as np

def transform(h, w):
    img_h_new, img_w_new = int(np.ceil(h / 32) * 32), int(np.ceil(w / 32) * 32)
    scale_h, scale_w = img_h_new / h, img_w_new / w
    return img_h_new, img_w_new, scale_h, scale_w


if __name__ == &quot;__main__&quot;:
    onnx_path = &quot;centerface.onnx&quot;
    net = cv2.dnn.readNetFromONNX(onnx_path)
    if cv2.cuda.getCudaEnabledDeviceCount():
        net.setPreferableBackend(cv2.dnn.DNN_BACKEND_CUDA)
        net.setPreferableTarget(cv2.dnn.DNN_TARGET_CUDA)

    img_path = &quot;test.jpg&quot;
    img = cv2.imread(img_path)
    height, width, _ = img.shape
    img_h_new, img_w_new, scale_h, scale_w = transform(height, width)

    blob = cv2.dnn.blobFromImage(img, scalefactor=1.0, size=(img_w_new, img_h_new), mean=(0, 0, 0), swapRB=True, crop=False)
    net.setInput(blob)
    for i in range(50):
        begin=time.time()
        heatmap, scale, offset, lms = net.forward([&quot;537&quot;, &quot;538&quot;, &quot;539&quot;, '540'])
        print(&quot;infer times = &quot;, time.time() - begin)"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">cv2</span>
<span class="pl-k">import</span> <span class="pl-s1">time</span>
<span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>

<span class="pl-k">def</span> <span class="pl-en">transform</span>(<span class="pl-s1">h</span>, <span class="pl-s1">w</span>):
    <span class="pl-s1">img_h_new</span>, <span class="pl-s1">img_w_new</span> <span class="pl-c1">=</span> <span class="pl-en">int</span>(<span class="pl-s1">np</span>.<span class="pl-en">ceil</span>(<span class="pl-s1">h</span> <span class="pl-c1">/</span> <span class="pl-c1">32</span>) <span class="pl-c1">*</span> <span class="pl-c1">32</span>), <span class="pl-en">int</span>(<span class="pl-s1">np</span>.<span class="pl-en">ceil</span>(<span class="pl-s1">w</span> <span class="pl-c1">/</span> <span class="pl-c1">32</span>) <span class="pl-c1">*</span> <span class="pl-c1">32</span>)
    <span class="pl-s1">scale_h</span>, <span class="pl-s1">scale_w</span> <span class="pl-c1">=</span> <span class="pl-s1">img_h_new</span> <span class="pl-c1">/</span> <span class="pl-s1">h</span>, <span class="pl-s1">img_w_new</span> <span class="pl-c1">/</span> <span class="pl-s1">w</span>
    <span class="pl-k">return</span> <span class="pl-s1">img_h_new</span>, <span class="pl-s1">img_w_new</span>, <span class="pl-s1">scale_h</span>, <span class="pl-s1">scale_w</span>


<span class="pl-k">if</span> <span class="pl-s1">__name__</span> <span class="pl-c1">==</span> <span class="pl-s">"__main__"</span>:
    <span class="pl-s1">onnx_path</span> <span class="pl-c1">=</span> <span class="pl-s">"centerface.onnx"</span>
    <span class="pl-s1">net</span> <span class="pl-c1">=</span> <span class="pl-s1">cv2</span>.<span class="pl-s1">dnn</span>.<span class="pl-en">readNetFromONNX</span>(<span class="pl-s1">onnx_path</span>)
    <span class="pl-k">if</span> <span class="pl-s1">cv2</span>.<span class="pl-s1">cuda</span>.<span class="pl-en">getCudaEnabledDeviceCount</span>():
        <span class="pl-s1">net</span>.<span class="pl-en">setPreferableBackend</span>(<span class="pl-s1">cv2</span>.<span class="pl-s1">dnn</span>.<span class="pl-v">DNN_BACKEND_CUDA</span>)
        <span class="pl-s1">net</span>.<span class="pl-en">setPreferableTarget</span>(<span class="pl-s1">cv2</span>.<span class="pl-s1">dnn</span>.<span class="pl-v">DNN_TARGET_CUDA</span>)

    <span class="pl-s1">img_path</span> <span class="pl-c1">=</span> <span class="pl-s">"test.jpg"</span>
    <span class="pl-s1">img</span> <span class="pl-c1">=</span> <span class="pl-s1">cv2</span>.<span class="pl-en">imread</span>(<span class="pl-s1">img_path</span>)
    <span class="pl-s1">height</span>, <span class="pl-s1">width</span>, <span class="pl-s1">_</span> <span class="pl-c1">=</span> <span class="pl-s1">img</span>.<span class="pl-s1">shape</span>
    <span class="pl-s1">img_h_new</span>, <span class="pl-s1">img_w_new</span>, <span class="pl-s1">scale_h</span>, <span class="pl-s1">scale_w</span> <span class="pl-c1">=</span> <span class="pl-en">transform</span>(<span class="pl-s1">height</span>, <span class="pl-s1">width</span>)

    <span class="pl-s1">blob</span> <span class="pl-c1">=</span> <span class="pl-s1">cv2</span>.<span class="pl-s1">dnn</span>.<span class="pl-en">blobFromImage</span>(<span class="pl-s1">img</span>, <span class="pl-s1">scalefactor</span><span class="pl-c1">=</span><span class="pl-c1">1.0</span>, <span class="pl-s1">size</span><span class="pl-c1">=</span>(<span class="pl-s1">img_w_new</span>, <span class="pl-s1">img_h_new</span>), <span class="pl-s1">mean</span><span class="pl-c1">=</span>(<span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>), <span class="pl-s1">swapRB</span><span class="pl-c1">=</span><span class="pl-c1">True</span>, <span class="pl-s1">crop</span><span class="pl-c1">=</span><span class="pl-c1">False</span>)
    <span class="pl-s1">net</span>.<span class="pl-en">setInput</span>(<span class="pl-s1">blob</span>)
    <span class="pl-k">for</span> <span class="pl-s1">i</span> <span class="pl-c1">in</span> <span class="pl-en">range</span>(<span class="pl-c1">50</span>):
        <span class="pl-s1">begin</span><span class="pl-c1">=</span><span class="pl-s1">time</span>.<span class="pl-en">time</span>()
        <span class="pl-s1">heatmap</span>, <span class="pl-s1">scale</span>, <span class="pl-s1">offset</span>, <span class="pl-s1">lms</span> <span class="pl-c1">=</span> <span class="pl-s1">net</span>.<span class="pl-en">forward</span>([<span class="pl-s">"537"</span>, <span class="pl-s">"538"</span>, <span class="pl-s">"539"</span>, <span class="pl-s">'540'</span>])
        <span class="pl-en">print</span>(<span class="pl-s">"infer times = "</span>, <span class="pl-s1">time</span>.<span class="pl-en">time</span>() <span class="pl-c1">-</span> <span class="pl-s1">begin</span>)</pre></div>
<p dir="auto">test [onnx model] (<a href="https://github.com/Star-Clouds/CenterFace/tree/master/models/onnx/centerface.onnx">https://github.com/Star-Clouds/CenterFace/tree/master/models/onnx/centerface.onnx</a>)<br>
test picture ：any picture , maybe use time is different, but the use time ratio is the same</p>
<h5 dir="auto">Issue submission checklist</h5>
<ul class="contains-task-list">
<li class="task-list-item">
<p dir="auto"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I report the issue, it's not a question</p>

</li>
<li class="task-list-item">
<p dir="auto"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I checked the problem with documentation, FAQ, open issues,<br>
forum.opencv.org, Stack Overflow, etc and have not found solution</p>

</li>
<li class="task-list-item">
<p dir="auto"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked="">  I updated to latest OpenCV version and the issue is still there</p>
 
</li>
<li class="task-list-item">
<p dir="auto"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> There is reproducer code and related data files: videos, images, onnx, etc</p>

</li>
</ul>
<h5 dir="auto">System information (version)</h5>
<ul dir="auto">
<li>OpenCV =&gt; 4.5.0</li>
<li>Operating System / Platform =&gt; Linux</li>
</ul>
<h5 dir="auto">Detailed description</h5>
<p dir="auto">I'm getting FPS: 10-12 using DNN with CPU. But when I use DNN with CUDA then I'm getting FPS 1-2.</p>
<p dir="auto">Using DNN with CUDA by following code:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="NET = cv2.dnn.readNetFromCaffe(
                            &quot;model/ssd/MobileNetSSD.prototxt&quot;,
                            &quot;model/ssd/MobileNetSSD.caffemodel&quot;)
NET.setPreferableBackend(cv2.dnn.DNN_BACKEND_CUDA)
NET.setPreferableTarget(cv2.dnn.DNN_TARGET_CUDA)
"><pre class="notranslate"><code class="notranslate">NET = cv2.dnn.readNetFromCaffe(
                            "model/ssd/MobileNetSSD.prototxt",
                            "model/ssd/MobileNetSSD.caffemodel")
NET.setPreferableBackend(cv2.dnn.DNN_BACKEND_CUDA)
NET.setPreferableTarget(cv2.dnn.DNN_TARGET_CUDA)

</code></pre></div>
<p dir="auto">Also my cmake conf are as follows:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="PREFIX_MAIN=`pyenv virtualenv-prefix`
PREFIX=`pyenv prefix`

cmake -D CMAKE_BUILD_TYPE=RELEASE \
        -D WITH_CUDA=ON \
	-D CUDA_ARCH_PTX=&quot;&quot; \
	-D CUDA_ARCH_BIN=&quot;5.3,6.2,7.2&quot; \
	-D WITH_CUBLAS=ON \
	-D WITH_LIBV4L=ON \
	-D BUILD_opencv_python3=ON \
	-D BUILD_opencv_python2=OFF \
	-D BUILD_opencv_java=OFF \
	-D WITH_GSTREAMER=ON \
	-D WITH_GTK=ON \
	-D BUILD_TESTS=OFF \
	-D BUILD_PERF_TESTS=OFF \
	-D BUILD_EXAMPLES=OFF \
	-D OPENCV_ENABLE_NONFREE=ON \
        -D CUDA_FAST_MATH=ON \
        -D ENABLE_NEON=ON \
        -D OPENCV_DNN_CUDA=ON \
        -D WITH_CUDNN=ON \
        -D WITH_OPENGL=ON \
        -D CMAKE_INSTALL_PREFIX=&quot;$PREFIX&quot; \
        -D PYTHON3_EXECUTABLE=&quot;$PREFIX&quot;/bin/python3 \
        -D PYTHON3_PACKAGES_PATH=&quot;$PREFIX&quot;/lib/python3.7/site-packages \
        -D PYTHON3_LIBRARY=&quot;$PREFIX_MAIN&quot;/lib/libpython3.7m.a \
        -D PYTHON3_INCLUDE_DIR=&quot;$PREFIX_MAIN&quot;/include/python3.7m \
	-D OPENCV_EXTRA_MODULES_PATH=/home/jetson-tx2-2/tmp/opencv_contrib/modules .."><pre class="notranslate"><code class="notranslate">PREFIX_MAIN=`pyenv virtualenv-prefix`
PREFIX=`pyenv prefix`

cmake -D CMAKE_BUILD_TYPE=RELEASE \
        -D WITH_CUDA=ON \
	-D CUDA_ARCH_PTX="" \
	-D CUDA_ARCH_BIN="5.3,6.2,7.2" \
	-D WITH_CUBLAS=ON \
	-D WITH_LIBV4L=ON \
	-D BUILD_opencv_python3=ON \
	-D BUILD_opencv_python2=OFF \
	-D BUILD_opencv_java=OFF \
	-D WITH_GSTREAMER=ON \
	-D WITH_GTK=ON \
	-D BUILD_TESTS=OFF \
	-D BUILD_PERF_TESTS=OFF \
	-D BUILD_EXAMPLES=OFF \
	-D OPENCV_ENABLE_NONFREE=ON \
        -D CUDA_FAST_MATH=ON \
        -D ENABLE_NEON=ON \
        -D OPENCV_DNN_CUDA=ON \
        -D WITH_CUDNN=ON \
        -D WITH_OPENGL=ON \
        -D CMAKE_INSTALL_PREFIX="$PREFIX" \
        -D PYTHON3_EXECUTABLE="$PREFIX"/bin/python3 \
        -D PYTHON3_PACKAGES_PATH="$PREFIX"/lib/python3.7/site-packages \
        -D PYTHON3_LIBRARY="$PREFIX_MAIN"/lib/libpython3.7m.a \
        -D PYTHON3_INCLUDE_DIR="$PREFIX_MAIN"/include/python3.7m \
	-D OPENCV_EXTRA_MODULES_PATH=/home/jetson-tx2-2/tmp/opencv_contrib/modules ..
</code></pre></div>
<p dir="auto">There were no errors during build and installation.<br>
I don't know what's the reason for such low FPS with CUDA. I've searched for solutions but failed. Please let me know if there is any issue with opencv 4.5.0.</p>
<p dir="auto">Other necessary info:</p>
<p dir="auto"><code class="notranslate">Jetpack: 4.3</code></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="NVIDIA CUDA:                   YES (ver 10.0, CUFFT CUBLAS FAST_MATH)
    NVIDIA GPU arch:             53 62 72
    NVIDIA PTX archs:

cuDNN:                         YES (ver 7.6.3)"><pre class="notranslate"><code class="notranslate">NVIDIA CUDA:                   YES (ver 10.0, CUFFT CUBLAS FAST_MATH)
    NVIDIA GPU arch:             53 62 72
    NVIDIA PTX archs:

cuDNN:                         YES (ver 7.6.3)
</code></pre></div>