code: def _export(
      model,
      args,
      filename,
      export_params,
      graph_name,
      save_text,
      opset_version,
      input_names,
      output_names,
      return_named_inout,
      external_converters,
      external_opset_imports,
      input_shapes,
  ):
      if opset_version is None:
          opset_version = min(
              int(onnx.defs.onnx_opset_version()), MAXIMUM_OPSET_VERSION
          )
      elif (
          opset_version < MINIMUM_OPSET_VERSION
          or opset_version > MAXIMUM_OPSET_VERSION
      ):
          warnings.warn(
              "ONNX-Chainer has been tested only with opset_version {} ~ {}"
              "The ONNX file exported with your requested opset_version ({}) "
              "may cause some problems because the converters used for the "
              "opset_version have not been tested.".format(
                  MINIMUM_OPSET_VERSION,
                  MAXIMUM_OPSET_VERSION,
                  opset_version,
              )
          )
  
      if input_shapes is not None:
          # if input shapes are invalid, raise exception before forwarding.
          input_shapes = format_customized_shapes(args, input_shapes)
  
      with RetainInputHook(), mapping.patch_functions():
          # Forward computation
          context = Context(model)
          network_inputs = OrderedDict()
          if isinstance(args, tuple):
              args = list(args)
          if isinstance(args, list):
              for i, arg in enumerate(args):
                  if isinstance(arg, chainer.get_array_types()):
                      args[i] = chainer.Variable(arg)
                  network_inputs[context.get_name(args[i])] = args[i]
              outputs = model(*args)
          elif isinstance(args, dict):
              for key, arg in args.items():
                  if isinstance(arg, chainer.get_array_types()):
                      args[key] = chainer.Variable(arg)
                  network_inputs[context.get_name(args[key])] = args[
                      key
                  ]
              outputs = model(**args)
          elif isinstance(args, chainer.get_array_types()):
              args = chainer.Variable(args)
              network_inputs[context.get_name(args)] = args
              outputs = model(args)
          elif isinstance(args, chainer.Variable):
              network_inputs[context.get_name(args)] = args
              outputs = model(args)
          else:
              raise ValueError(
                  "The 'args' argument should be a list, tuple, dict, "
                  "numpy array, or Chainer Variable. But a {} object was "
                  "given.".format(type(args))
              )
          rename_variable_name(
              context, args, network_inputs, input_names
          )
  
          initializers = []
          input_tensors = []
          param_names = set()
          for org_name, param in model.namedparams():
              # `model.namedparams()` has `include_uninit` flag but not use, to
              # output user warning
              if param.array is None:
                  warnings.warn(
                      "The parameter '{}' is not initialized, skip setting to "
                      "ONNX graph".format(org_name)
                  )
                  continue
              name = context.get_name(param)
              param_names.add(name)
              tensor = convert_parameter(param, context)
              initializers.append(tensor)
              input_tensors.append(
                  helper.make_tensor_value_info(
                      name, tensor.data_type, tensor.dims
                  )
              )
  
          for i, (name, var) in enumerate(network_inputs.items()):
              shape = (
                  var.shape if input_shapes is None else input_shapes[i]
              )
              input_tensors.append(
                  helper.make_tensor_value_info(
                      name, NP_TYPE_TO_TENSOR_TYPE[var.dtype], shape
                  )
              )
  
          if external_converters:
              chainer.utils.experimental("external_converters")
              converters = dict(
                  mapping.converters, **external_converters
              )
          else:
              converters = mapping.converters
  
          if isinstance(outputs, (list, tuple)):
              flat_outputs = outputs
          elif isinstance(outputs, dict):
              flat_outputs = list(outputs.values())
          elif isinstance(outputs, chainer.Variable):
              flat_outputs = [outputs]
          else:
              raise RuntimeError(
                  "Unexpected output type from the model: {}".format(
                      type(outputs)
                  )
              )
          if not all(
              [isinstance(o, chainer.Variable) for o in flat_outputs]
          ):
              raise ValueError(
                  "The all 'outputs' must be Chainer Variable"
              )
          network_outputs = OrderedDict(
              [(context.get_name(var), var) for var in flat_outputs]
          )
          if output_names:
              rename_variable_name(
                  context, outputs, network_outputs, output_names
              )
  
          o = Graph(
              context,
              converters,
              opset_version,
              param_names | set(network_inputs.keys()),
              network_outputs,
          )
          o.to_onnx_graph()
  
      implicit_input_names = set(context.implicit_inputs.keys())
      for name in implicit_input_names:
          tensor = convert_parameter(
              context.implicit_inputs[name], context
          )
          initializers.append(tensor)
          input_tensors.append(
              helper.make_tensor_value_info(
                  name, tensor.data_type, tensor.dims
              )
          )
  
      # If additional parameters are created during conversion
      for param in context.parameters:
          tensor = convert_parameter(param, context)
          initializers.append(tensor)
          input_tensors.append(
              helper.make_tensor_value_info(
                  context.get_name(param), tensor.data_type, tensor.dims
              )
          )
  
      # Convert output tensors
      output_tensors = []
      for name, var in network_outputs.items():
          output_tensors.append(
              helper.make_tensor_value_info(
                  name, NP_TYPE_TO_TENSOR_TYPE[var.dtype], var.shape
              )
          )
  
      if not export_params:
          initializers = []
  
      onnx_graph = helper.make_graph(
          o.graph,
          graph_name,
          input_tensors,
          output_tensors,
          initializer=initializers,
      )
  
      opset_imports = [helper.make_operatorsetid("", opset_version)]
      if external_opset_imports:
          chainer.utils.experimental("external_opset_imports")
          for domain, version in external_opset_imports.items():
              opset_imports.append(
                  helper.make_operatorsetid(domain, version)
              )
      model = helper.make_model(
          onnx_graph,
          producer_name="Chainer",
          producer_version=chainer.__version__,
          opset_imports=opset_imports,
      )
  
      model.ir_version = onnx.IR_VERSION
      check_onnx_model(
          model, external_converters, external_opset_imports
      )
  
      if input_shapes is not None:
          for output in model.graph.output:
              for d in output.type.tensor_type.shape.dim:
                  d.Clear()
          model = shape_inference.infer_shapes(model)
          check_onnx_model(
              model, external_converters, external_opset_imports
          )
  
      if filename is not None and isinstance(filename, str):
          with open(filename, "wb") as fp:
              fp.write(model.SerializeToString())
          if save_text:
              with open(filename + ".txt", "w") as fp:
                  print(model, file=fp)
      elif hasattr(filename, "write"):
          filename.write(model.SerializeToString())
  
      if return_named_inout:
          chainer.utils.experimental("return_named_inout")
          return model, network_inputs, network_outputs
      return model
  
file_path: chainer/onnx_chainer/export.py
imports: from __future__ import print_function
  from collections import OrderedDict
  import warnings
  import chainer
label_desc: Use image node_id 6 for calling a global function with example usage: _export(model, args, filename, export_params, graph_name, save_text, opset_version, input_names, output_names, return_named_inout, external_converters, external_opset_imports, input_shapes) and returns: model, model,  network_inputs,  network_outputs