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

<ul dir="auto">
<li>OpenCV =&gt; 4.1.0</li>
<li>python 3.7.3</li>
<li>Operating System / Platform =&gt; Ubuntu 64 Bit</li>
<li>PyTorch =&gt; 1.1.0</li>
<li>onnx =&gt; 1.5.0</li>
<li>conda =&gt; 4.6.14</li>
</ul>
<h5 dir="auto">Detailed description</h5>
<p dir="auto">I'm trying to export a model from PyTorch to ONNX to be run in OpenCV, but am getting an error when running cv2.dnn.readNetFromONNX. I've isolated the cause of the error to slicing a tensor. As an example, I've attached a file that attempts to follow these steps for a simple model. The model slices the last dimension of the input and returns.</p>
<p dir="auto">Script:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import torch
import torch.nn as nn
import onnx
import cv2 

class Net(nn.Module):

    def __init__(self):
        super(Net, self).__init__()

    def forward(self, x): 
        return x[...,2:5]

dummy = torch.rand((4,3,10,10))
net = Net()
torch.onnx.export(net, dummy, 'test.onnx', verbose=True)

model_cv2 = cv2.dnn.readNetFromONNX('test.onnx')"><pre class="notranslate"><code class="notranslate">import torch
import torch.nn as nn
import onnx
import cv2 

class Net(nn.Module):

    def __init__(self):
        super(Net, self).__init__()

    def forward(self, x): 
        return x[...,2:5]

dummy = torch.rand((4,3,10,10))
net = Net()
torch.onnx.export(net, dummy, 'test.onnx', verbose=True)

model_cv2 = cv2.dnn.readNetFromONNX('test.onnx')
</code></pre></div>
<p dir="auto">I get the following error:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="cv2.error: OpenCV(4.1.0) /io/opencv/modules/dnn/src/layers/slice_layer.cpp:147: error: (-215:Assertion failed) requiredOutputs &gt; 0 &amp;&amp; inpShape[axis] % requiredOutputs == 0 in function 'getMemoryShapes'"><pre class="notranslate"><code class="notranslate">cv2.error: OpenCV(4.1.0) /io/opencv/modules/dnn/src/layers/slice_layer.cpp:147: error: (-215:Assertion failed) requiredOutputs &gt; 0 &amp;&amp; inpShape[axis] % requiredOutputs == 0 in function 'getMemoryShapes'
</code></pre></div>
<p dir="auto">The ONNX graph:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="graph(%0 : Float(4, 3, 10, 10)):
  %1 : Float(4, 3, 10!, 3) = onnx::Slice[axes=[3], ends=[5], starts=[2]](%0), scope: Net
  return (%1) "><pre class="notranslate"><code class="notranslate">graph(%0 : Float(4, 3, 10, 10)):
  %1 : Float(4, 3, 10!, 3) = onnx::Slice[axes=[3], ends=[5], starts=[2]](%0), scope: Net
  return (%1) 
</code></pre></div>
<h5 dir="auto">Steps to reproduce</h5>
<p dir="auto">I've attached a python script to reproduce.</p>
<p dir="auto">I've also attached the ONNX model.<br>
<a href="https://github.com/opencv/opencv/files/3232949/files.zip">files.zip</a></p>
<p dir="auto">Transferred from <a href="http://code.opencv.org/issues/1682" rel="nofollow">http://code.opencv.org/issues/1682</a></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="|| Andrey Kamaev on 2012-03-13 12:37
|| Priority: Low
|| Affected: None
|| Category: highgui-images
|| Tracker: Feature
|| Difficulty: None
|| PR: None
|| Platform: None / None"><pre class="notranslate"><code class="notranslate">|| Andrey Kamaev on 2012-03-13 12:37
|| Priority: Low
|| Affected: None
|| Category: highgui-images
|| Tracker: Feature
|| Difficulty: None
|| PR: None
|| Platform: None / None
</code></pre></div>
<h2 dir="auto">Utility functions from highgui duplicate functionality of cvtColor function</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="See http://code.opencv.org/projects/opencv/repository/revisions/7485/entry/trunk/opencv/modules/highgui/src/utils.cpp"><pre class="notranslate"><code class="notranslate">See http://code.opencv.org/projects/opencv/repository/revisions/7485/entry/trunk/opencv/modules/highgui/src/utils.cpp
</code></pre></div>
<h2 dir="auto">History</h2>
<h5 dir="auto">Alexander Shishkov on 2012-03-20 12:21</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="-   Target version deleted ()"><pre class="notranslate"><code class="notranslate">-   Target version deleted ()
</code></pre></div>
<h5 dir="auto">Alexander Shishkov on 2012-03-25 20:14</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="-   Priority changed from Normal to Low"><pre class="notranslate"><code class="notranslate">-   Priority changed from Normal to Low
</code></pre></div>
<h5 dir="auto">Alexander Shishkov on 2012-03-25 20:48</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="-   Assignee deleted (Alexander Reshetnikov)"><pre class="notranslate"><code class="notranslate">-   Assignee deleted (Alexander Reshetnikov)
</code></pre></div>
<h5 dir="auto">Alexander Shishkov on 2012-04-05 12:47</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="-   Target version deleted ()"><pre class="notranslate"><code class="notranslate">-   Target version deleted ()
</code></pre></div>
<h5 dir="auto">Vadim Pisarevsky on 2012-10-04 14:48</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="looks like this is a feature request
-   Tracker changed from Bug to Feature"><pre class="notranslate"><code class="notranslate">looks like this is a feature request
-   Tracker changed from Bug to Feature
</code></pre></div>