<h3 dir="auto">System Information</h3>
<p dir="auto">System: Ubuntu 20.04<br>
Complier: GCC 7.5.0<br>
OpenCV version: 4.7.0 (build from source)<br>
Torch version: 2.0.0+cpu<br>
Torchvision version: 0.15.1+cpu<br>
Onnx version: 1.11.0</p>
<h3 dir="auto">Detailed description</h3>
<p dir="auto">Following assertion in raised when TopK layer is being parsed. It seems that TopK layer in C++ is absent.</p>
<div class="highlight highlight-text-shell-session notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="[ INFO:0@0.967] global onnx_importer.cpp:1006 handleNode DNN/ONNX: processing node with 2 inputs and 2 outputs: [TopK]:(onnx_node!/TopK) from domain='ai.onnx'
[ INFO:0@0.968] global onnx_importer.cpp:3333 parseCustomLayer DNN/ONNX: unknown node type, try using custom handler for node with 2 inputs and 2 outputs: [TopK]:(onnx_node!/TopK)
OpenCV(4.7.0-dev) Error: Unspecified error (Can't create layer &quot;onnx_node!/TopK&quot; of type &quot;TopK&quot;) in getLayerInstance, file opencv/modules/dnn/src/net_impl.hpp, line 108
[ERROR:0@0.968] global onnx_importer.cpp:1064 handleNode DNN/ONNX: ERROR during processing node with 2 inputs and 2 outputs: [TopK]:(onnx_node!/TopK) from domain='ai.onnx'
[ INFO:0@0.968] global onnx_importer.cpp:1068 handleNode     Input[0] = 'input'
[ INFO:0@0.968] global onnx_importer.cpp:1068 handleNode     Input[1] = '/Constant_output_0'
[ INFO:0@0.968] global onnx_importer.cpp:1072 handleNode     Output[0] = 'output'
[ INFO:0@0.968] global onnx_importer.cpp:1072 handleNode     Output[1] = '5'
OpenCV(4.7.0-dev) Error: Unspecified error (&gt; Node [TopK@ai.onnx]:(onnx_node!/TopK) parse error: OpenCV(4.7.0-dev) opencv/modules/dnn/src/net_impl.hpp:108: error: (-2:Unspecified error) Can't create layer &quot;onnx_node!/TopK&quot; of type &quot;TopK&quot; in function 'getLayerInstance'
&gt; ) in handleNode, file opencv/modules/dnn/src/onnx/onnx_importer.cpp, line 1083
[DEBUG:0@0.968] global system.cpp:2881 restoreFPDenormalsState core: restore FP mxcsr flags = 0x00001fa3
Traceback (most recent call last):
  File &quot;topk.py&quot;, line 43, in &lt;module&gt;
    opencv_net = cv2.dnn.readNetFromONNX(full_model_path)
cv2.error: OpenCV(4.7.0-dev) opencv/modules/dnn/src/onnx/onnx_importer.cpp:1083: error: (-2:Unspecified error) in function 'handleNode'"><pre class="notranslate"><span class="pl-c1">[ INFO:0@0.967] global onnx_importer.cpp:1006 handleNode DNN/ONNX: processing node with 2 inputs and 2 outputs: [TopK]:(onnx_node!/TopK) from domain='ai.onnx'</span>
<span class="pl-c1">[ INFO:0@0.968] global onnx_importer.cpp:3333 parseCustomLayer DNN/ONNX: unknown node type, try using custom handler for node with 2 inputs and 2 outputs: [TopK]:(onnx_node!/TopK)</span>
<span class="pl-c1">OpenCV(4.7.0-dev) Error: Unspecified error (Can't create layer "onnx_node!/TopK" of type "TopK") in getLayerInstance, file opencv/modules/dnn/src/net_impl.hpp, line 108</span>
<span class="pl-c1">[ERROR:0@0.968] global onnx_importer.cpp:1064 handleNode DNN/ONNX: ERROR during processing node with 2 inputs and 2 outputs: [TopK]:(onnx_node!/TopK) from domain='ai.onnx'</span>
<span class="pl-c1">[ INFO:0@0.968] global onnx_importer.cpp:1068 handleNode     Input[0] = 'input'</span>
<span class="pl-c1">[ INFO:0@0.968] global onnx_importer.cpp:1068 handleNode     Input[1] = '/Constant_output_0'</span>
<span class="pl-c1">[ INFO:0@0.968] global onnx_importer.cpp:1072 handleNode     Output[0] = 'output'</span>
<span class="pl-c1">[ INFO:0@0.968] global onnx_importer.cpp:1072 handleNode     Output[1] = '5'</span>
<span class="pl-c1">OpenCV(4.7.0-dev) Error: Unspecified error (&gt; Node [TopK@ai.onnx]:(onnx_node!/TopK) parse error: OpenCV(4.7.0-dev) opencv/modules/dnn/src/net_impl.hpp:108: error: (-2:Unspecified error) Can't create layer "onnx_node!/TopK" of type "TopK" in function 'getLayerInstance'</span>
&gt; <span class="pl-s1">) <span class="pl-k">in</span> handleNode, file opencv/modules/dnn/src/onnx/onnx_importer.cpp, line 1083</span>
<span class="pl-c1">[DEBUG:0@0.968] global system.cpp:2881 restoreFPDenormalsState core: restore FP mxcsr flags = 0x00001fa3</span>
<span class="pl-c1">Traceback (most recent call last):</span>
<span class="pl-c1">  File "topk.py", line 43, in &lt;module&gt;</span>
<span class="pl-c1">    opencv_net = cv2.dnn.readNetFromONNX(full_model_path)</span>
<span class="pl-c1">cv2.error: OpenCV(4.7.0-dev) opencv/modules/dnn/src/onnx/onnx_importer.cpp:1083: error: (-2:Unspecified error) in function 'handleNode'</span></pre></div>
<h3 dir="auto">Steps to reproduce</h3>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="

import cv2
import onnx, os
import torch
import torch.nn as nn
from onnx import shape_inference
from onnxsim import simplify

class TopK(nn.Module):

    def forward(self, x):
        return torch.topk(x, 3)

if __name__ == &quot;__main__&quot;:

    onnx_model_path = &quot;models&quot;
    onnx_model_name = &quot;topk.onnx&quot;
    full_model_path = os.path.join(onnx_model_path, onnx_model_name)

    topk = TopK()
    x = torch.arange(1., 6.)
    v, i = topk(x)

    torch.onnx.export(
        topk,
        x,
        full_model_path,
        verbose=False,
        input_names=[&quot;input&quot;],
        output_names=[&quot;output&quot;],
        opset_version=11
    )
    
    onnx_model = onnx.load(full_model_path)
    onnx.checker.check_model(onnx_model)

    onnx_model = shape_inference.infer_shapes(onnx_model)
    onnx.save(onnx_model, full_model_path)

    opencv_net = cv2.dnn.readNetFromONNX(full_model_path)"><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">onnx</span>, <span class="pl-s1">os</span>
<span class="pl-k">import</span> <span class="pl-s1">torch</span>
<span class="pl-k">import</span> <span class="pl-s1">torch</span>.<span class="pl-s1">nn</span> <span class="pl-k">as</span> <span class="pl-s1">nn</span>
<span class="pl-k">from</span> <span class="pl-s1">onnx</span> <span class="pl-k">import</span> <span class="pl-s1">shape_inference</span>
<span class="pl-k">from</span> <span class="pl-s1">onnxsim</span> <span class="pl-k">import</span> <span class="pl-s1">simplify</span>

<span class="pl-k">class</span> <span class="pl-v">TopK</span>(<span class="pl-s1">nn</span>.<span class="pl-v">Module</span>):

    <span class="pl-k">def</span> <span class="pl-en">forward</span>(<span class="pl-s1">self</span>, <span class="pl-s1">x</span>):
        <span class="pl-k">return</span> <span class="pl-s1">torch</span>.<span class="pl-en">topk</span>(<span class="pl-s1">x</span>, <span class="pl-c1">3</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_model_path</span> <span class="pl-c1">=</span> <span class="pl-s">"models"</span>
    <span class="pl-s1">onnx_model_name</span> <span class="pl-c1">=</span> <span class="pl-s">"topk.onnx"</span>
    <span class="pl-s1">full_model_path</span> <span class="pl-c1">=</span> <span class="pl-s1">os</span>.<span class="pl-s1">path</span>.<span class="pl-en">join</span>(<span class="pl-s1">onnx_model_path</span>, <span class="pl-s1">onnx_model_name</span>)

    <span class="pl-s1">topk</span> <span class="pl-c1">=</span> <span class="pl-v">TopK</span>()
    <span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-s1">torch</span>.<span class="pl-en">arange</span>(<span class="pl-c1">1.</span>, <span class="pl-c1">6.</span>)
    <span class="pl-s1">v</span>, <span class="pl-s1">i</span> <span class="pl-c1">=</span> <span class="pl-en">topk</span>(<span class="pl-s1">x</span>)

    <span class="pl-s1">torch</span>.<span class="pl-s1">onnx</span>.<span class="pl-en">export</span>(
        <span class="pl-s1">topk</span>,
        <span class="pl-s1">x</span>,
        <span class="pl-s1">full_model_path</span>,
        <span class="pl-s1">verbose</span><span class="pl-c1">=</span><span class="pl-c1">False</span>,
        <span class="pl-s1">input_names</span><span class="pl-c1">=</span>[<span class="pl-s">"input"</span>],
        <span class="pl-s1">output_names</span><span class="pl-c1">=</span>[<span class="pl-s">"output"</span>],
        <span class="pl-s1">opset_version</span><span class="pl-c1">=</span><span class="pl-c1">11</span>
    )
    
    <span class="pl-s1">onnx_model</span> <span class="pl-c1">=</span> <span class="pl-s1">onnx</span>.<span class="pl-en">load</span>(<span class="pl-s1">full_model_path</span>)
    <span class="pl-s1">onnx</span>.<span class="pl-s1">checker</span>.<span class="pl-en">check_model</span>(<span class="pl-s1">onnx_model</span>)

    <span class="pl-s1">onnx_model</span> <span class="pl-c1">=</span> <span class="pl-s1">shape_inference</span>.<span class="pl-en">infer_shapes</span>(<span class="pl-s1">onnx_model</span>)
    <span class="pl-s1">onnx</span>.<span class="pl-en">save</span>(<span class="pl-s1">onnx_model</span>, <span class="pl-s1">full_model_path</span>)

    <span class="pl-s1">opencv_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">full_model_path</span>)</pre></div>
<h3 dir="auto">Issue submission checklist</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I report the issue, it's not a question</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I updated to the latest OpenCV version and the issue is still there</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> There is reproducer code and related data files (videos, images, onnx, etc)</li>
</ul>
<h5 dir="auto">System information (version)</h5>

<ul dir="auto">
<li>OpenCV =&gt; :4.0</li>
<li>Operating System / Platform =&gt; : linux mint (ubuntu 16.04) 64 bit</li>
<li>Compiler =&gt; :gcc</li>
</ul>
<h5 dir="auto">Detailed description</h5>
<p dir="auto">when i have run the command make -j4 .<br>
I got error with description that<br>
"<br>
/anaconda3/lib/libgsttag-1.0.so.0: undefined reference to <code class="notranslate">gst_make_element_message_details' /anaconda3/lib/libgsttag-1.0.so.0: undefined reference to </code>gst_element_message_full_with_details'<br>
collect2: error: ld returned 1 exit status<br>
modules/videoio/CMakeFiles/opencv_test_videoio.dir/build.make:286: recipe for target 'bin/opencv_test_videoio' failed<br>
make[2]: *** [bin/opencv_test_videoio] Error 1</p>
<p dir="auto">CMakeFiles/Makefile2:9038: recipe for target 'modules/videoio/CMakeFiles/opencv_test_videoio.dir/all' failed<br>
make[1]: *** [modules/videoio/CMakeFiles/opencv_test_videoio.dir/all] Error 2<br>
make[1]: *** Waiting for unfinished jobs....<br>
"<br>
This was the error .<br>
I have tried to install all dependencies several times but i have got same result.</p>

<h5 dir="auto">Steps to reproduce</h5>
<p dir="auto">cmake -D CMAKE_BUILD_TYPE=RELEASE <br>
-D CMAKE_INSTALL_PREFIX=$cwd/installation/OpenCV-"$cvVersion" <br>
-D INSTALL_C_EXAMPLES=ON <br>
-D INSTALL_PYTHON_EXAMPLES=ON <br>
-D WITH_TBB=ON <br>
-D WITH_V4L=ON <br>
-D OPENCV_PYTHON3_INSTALL_PATH=$cwd/OpenCV-$cvVersion-py3/lib/python3.5/site-packages <br>
-D WITH_QT=ON <br>
-D WITH_OPENGL=ON <br>
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules <br>
-D BUILD_EXAMPLES=ON ..</p>
<p dir="auto">then i have use make -j4</p>