There was a problem converting the model to onnx format

wangyaxin1998: <h2><a name="vesion-1" class="anchor" href="#vesion-1"></a>Vesion</h2>
<p>pytorch: 1.6.0</p>
<h2><a name="problem-description-2" class="anchor" href="#problem-description-2"></a>Problem description</h2>
<p>The model I use is pointnet++<br>
This is a website with network structure</p><aside class="onebox githubblob" data-onebox-src="https://github.com/yanx27/Pointnet_Pointnet2_pytorch/blob/master/models/pointnet_sem_seg.py">
  <header class="source">

      <a href="https://github.com/yanx27/Pointnet_Pointnet2_pytorch/blob/master/models/pointnet_sem_seg.py" target="_blank" rel="noopener nofollow ugc">github.com</a>
  </header>

  <article class="onebox-body">
    <h4><a href="https://github.com/yanx27/Pointnet_Pointnet2_pytorch/blob/master/models/pointnet_sem_seg.py" target="_blank" rel="noopener nofollow ugc">yanx27/Pointnet_Pointnet2_pytorch/blob/master/models/pointnet_sem_seg.py</a></h4>


      <pre><code class="lang-py">import torch
import torch.nn as nn
import torch.nn.parallel
import torch.utils.data
import torch.nn.functional as F
from pointnet_utils import PointNetEncoder, feature_transform_reguliarzer


class get_model(nn.Module):
    def __init__(self, num_class):
        super(get_model, self).__init__()
        self.k = num_class
        self.feat = PointNetEncoder(global_feat=False, feature_transform=True, channel=9)
        self.conv1 = torch.nn.Conv1d(1088, 512, 1)
        self.conv2 = torch.nn.Conv1d(512, 256, 1)
        self.conv3 = torch.nn.Conv1d(256, 128, 1)
        self.conv4 = torch.nn.Conv1d(128, self.k, 1)
        self.bn1 = nn.BatchNorm1d(512)
        self.bn2 = nn.BatchNorm1d(256)
        self.bn3 = nn.BatchNorm1d(128)
</code></pre>



  This file has been truncated. <a href="https://github.com/yanx27/Pointnet_Pointnet2_pytorch/blob/master/models/pointnet_sem_seg.py" target="_blank" rel="noopener nofollow ugc">show original</a>

  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>
<p>
I only changed the input of the model and changed 9 channels to 4 channels.<br>
For deployment, I want to convert the model to onnx format .<br>
The program has been stuck in <strong>torch onnx. export</strong>,and model conversion cannot be completed<br>
How can i solve this problem?</p>
<h2><a name="code-3" class="anchor" href="#code-3"></a>Code</h2>
<pre><code>model=MODEL.get_model(NUM_CLASSES)

model.load_state_dict(torch.load(checkpoint)['model_state_dict']) 

model=model.eval()

input = torch.randn(1, 4, 768)

torch.onnx.export(model, input, onnx_path,verbose=True,
 input_names=input_names, output_names=output_names,
  opset_version=11) 
print("Exporting .pth model to onnx model has been successful!")
</code></pre>
<p>The following is a warning message</p>
<h2><a name="warning-4" class="anchor" href="#warning-4"></a>Warning</h2>
<blockquote>
<p>/media/hust/File/wyx/Pointnet2_water/models/pointnet2_utils.py:75: TracerWarning: Converting a tensor to a Python integer might cause the trace to be incorrect. We can’t record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!<br>
farthest = torch.randint(0, N, (B,), dtype=torch.long).to(device)<br>
/media/hust/File/wyx/Pointnet2_water/models/pointnet2_utils.py:75: TracerWarning: Converting a tensor to a Python index might cause the trace to be incorrect. We can’t record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!<br>
farthest = torch.randint(0, N, (B,), dtype=torch.long).to(device)<br>
/media/hust/File/wyx/Pointnet2_water/models/pointnet2_utils.py:293: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can’t record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!<br>
if S == 1:<br>
/home/hust/miniconda3/envs/PointNet++/lib/python3.7/site-packages/torch/onnx/symbolic_opset9.py:2225: UserWarning: Exporting aten::index operator of advanced indexing in opset 11 is achieved by combination of multiple ONNX operators, including Reshape, Transpose, Concat, and Gather. If indices include negative values, the exported graph will produce incorrect results.<br>
“If indices include negative values, the exported graph will produce incorrect results.”)<br>
/home/hust/miniconda3/envs/PointNet++/lib/python3.7/site-packages/torch/onnx/symbolic_opset9.py:2179: UserWarning: Exporting aten::index operator with indices of type Byte. Only 1-D indices are supported. In any other case, this will produce an incorrect ONNX graph.<br>
warnings.warn("Exporting aten::index operator with indices of type Byte. "</p>
</blockquote>

saiabinesh: <p>Any updates to this?<br>
Having a similar problem in pytorch 1.11.0<br>
Still stuck at warnings and not exporting.</p>

Robin_maltaros: <p>Hey, because of the loop in FPS, the export is very long (took 9h for me). The problem is also mentioned here (Dec 2022 answer) <a href="https://github.com/pytorch/pytorch/issues/77222" class="inline-onebox" rel="noopener nofollow ugc">Error converting the pointnet++ model to ONNX · Issue #77222 · pytorch/pytorch · GitHub</a> .</p>