[Help] torch to onnx export

Petro_Malesh: <p>Hi guys<br>
I tried to export <a href="https://github.com/autonomousvision/unimatch" class="inline-onebox" rel="noopener nofollow ugc">GitHub - autonomousvision/unimatch: [TPAMI'23] Unifying Flow, Stereo and Depth Estimation</a> model to onnx</p>
<p><code> torch.onnx.export(model,         # model being run
                  args=(right, left, 'self_swin2d_cross_swin1d',
                        [2, 8], [-1, 4],
                        [-1, 1], 3,
                        False, 'stereo', None, None,
                        1. / 0.5, 1. / 10, 64,
                        False, False),                         # model input (or a tuple for multiple inputs)
                  f="test.onnx",   # where to save the model (can be a file or file-like object)
                  verbose=True,
                  export_params=True,        # store the trained parameter weights inside the model file
                  opset_version=16,          # the ONNX version to export the model to
                  do_constant_folding=True,  # whether to execute constant folding for optimization
                  input_names = ['img0', 'img1', 'attn_type',
                                 'attn_splits_list', 'corr_radius_list',
                                 'prop_radius_list', 'num_reg_refine',
                                 'pred_bidir_flow' , 'task', 'intrinsics', 'pose',
                                 'min_depth', 'max_depth', 'num_depth_candidates',
                                 'depth_from_argmax', 'pred_bidir_depth'],   # the model's input names
                  output_names = ['flow_preds']) </code><br>
The code runs fine, no error message is shown, but here comes the problem with exporting:</p>
<p>[code] File c:\ProgramData\Anaconda3\lib\site-packages\torch\onnx\utils.py:506, in export(model, args, f, export_params, verbose, training, input_names, output_names, operator_export_type, opset_version, do_constant_folding, dynamic_axes, keep_initializers_as_inputs, custom_opsets, export_modules_as_functions)<br>
188 <span class="mention">@_beartype.beartype</span><br>
189 def export(<br>
190     model: Union[torch.nn.Module, torch.jit.ScriptModule, torch.jit.ScriptFunction],<br>
(…)<br>
206     export_modules_as_functions: Union[bool, Collection[Type[torch.nn.Module]]] = False,<br>
207 ) → None:<br>
208     r""“Exports a model into ONNX format.<br>
209<br>
210     If <code>model</code> is not a :class:<code>torch.jit.ScriptModule</code> nor a<br>
(…)<br>
503             All errors are subclasses of :class:<code>errors.OnnxExporterError</code>.<br>
504     “””<br>
 → 506     _export(<br>
507         model,<br>
508         args,<br>
509         f,<br>
510         export_params,<br>
511         verbose,<br>
512         training,<br>
513         input_names,<br>
514         output_names,<br>
515         operator_export_type=operator_export_type,<br>
516         opset_version=opset_version,<br>
517         do_constant_folding=do_constant_folding,<br>
518         dynamic_axes=dynamic_axes,<br>
519         keep_initializers_as_inputs=keep_initializers_as_inputs,<br>
520         custom_opsets=custom_opsets,<br>
521         export_modules_as_functions=export_modules_as_functions,<br>
522     )</p>
<p>File c:\ProgramData\Anaconda3\lib\site-packages\torch\onnx\utils.py:1551, in _export(model, args, f, export_params, verbose, training, input_names, output_names, operator_export_type, export_type, opset_version, do_constant_folding, dynamic_axes, keep_initializers_as_inputs, fixed_batch_size, custom_opsets, add_node_names, onnx_shape_inference, export_modules_as_functions)<br>
1548     dynamic_axes = {}<br>
1549 _validate_dynamic_axes(dynamic_axes, model, input_names, output_names)<br>
 → 1551 graph, params_dict, torch_out = _model_to_graph(<br>
1552     model,<br>
1553     args,<br>
1554     verbose,<br>
1555     input_names,<br>
1556     output_names,<br>
1557     operator_export_type,<br>
1558     val_do_constant_folding,<br>
1559     fixed_batch_size=fixed_batch_size,<br>
1560     training=training,<br>
1561     dynamic_axes=dynamic_axes,<br>
1562 )<br>
1564 # TODO: Don’t allocate a in-memory string for the protobuf<br>
1565 defer_weight_export = (<br>
1566     export_type is not _exporter_states.ExportTypes.PROTOBUF_FILE<br>
1567 )</p>
<p>File c:\ProgramData\Anaconda3\lib\site-packages\torch\onnx\utils.py:1163, in _model_to_graph(model, args, verbose, input_names, output_names, operator_export_type, do_constant_folding, _disable_torch_constant_prop, fixed_batch_size, training, dynamic_axes)<br>
1156     # print(type(output_tensors))<br>
1157     # print(output_tensors)<br>
1158     # print(type(graph[0]))<br>
1159     # assign_output_shape pass is not compatible with quantized outputs.<br>
1160     # Quantized outputs are flattened to 3 values in ONNX, while packed as<br>
1161     # single value in PyTorch.<br>
1162     if not any(getattr(out, “is_quantized”, False) for out in output_tensors):<br>
 → 1163         _C._jit_pass_onnx_assign_output_shape(<br>
1164             graph,<br>
1165             output_tensors,<br>
1166             out_desc,<br>
1167             GLOBALS.onnx_shape_inference,<br>
1168             is_script,<br>
1169             GLOBALS.export_onnx_opset_version,<br>
1170         )<br>
1172 _set_input_and_output_names(graph, input_names, output_names)<br>
1173 params_dict = _get_named_param_dict(graph, params)</p>
<p>RuntimeError: Expected a sequence type, but received a non-iterable type in graph output index 0 [/code]</p>
<p>I would be very grateful for any help or advice</p>