code: def save_cntk_data_as_onnx_tensor(
      file_path, variable, data, onnx_value_info_proto
  ):
      # sequence mode data shape: (batch, sequecen, ...)
      # to make onnx model work, batch must be 1
      # swith to onnx shape: (sequence, batch, ...)
      if is_list_of_sparse(data):
          data = sparse_to_dense(data)
      elif type(data) == scipy.sparse.csr.csr_matrix:
          data = data.todense()
  
      # compare free_dim indices between variable with onnx_value_info_proto
      # they are at index 0 and 1.
      if compare_output_for_data_transpose(
          variable, onnx_value_info_proto
      ):
          data = transpose_dynamic_axis(data)
  
      tp = onnx.TensorProto()
      tp.name = onnx_value_info_proto.name
  
      shape = np.shape(data)
      for i in range(0, len(shape)):
          tp.dims.append(shape[i])
  
      if type(data) == list:
          # this is probably because of batch (list of samples)
          data = data[0]
  
      tp.data_type = onnx_value_info_proto.type.tensor_type.elem_type
      if (
          onnx_value_info_proto.type.tensor_type.elem_type
          == onnx.TensorProto.DOUBLE
      ):
          data = data.astype(np.double)
          tp.raw_data = data.tobytes()
      elif (
          onnx_value_info_proto.type.tensor_type.elem_type
          == onnx.TensorProto.FLOAT
      ):
          tp.raw_data = data.tobytes()
      elif (
          onnx_value_info_proto.type.tensor_type.elem_type
          == onnx.TensorProto.FLOAT16
      ):
          tp.raw_data = data.tobytes()
      elif (
          onnx_value_info_proto.type.tensor_type.elem_type
          == onnx.TensorProto.INT64
      ):
          data = data.astype(np.int64)
          tp.raw_data = data.tobytes()
      elif (
          onnx_value_info_proto.type.tensor_type.elem_type
          == onnx.TensorProto.INT32
      ):
          data = data.astype(np.int)
          tp.raw_data = data.tobytes()
      elif (
          onnx_value_info_proto.type.tensor_type.elem_type
          == onnx.TensorProto.BOOL
      ):
          data = data.astype(np.bool)
          tp.raw_data = data.tobytes()
      else:
          assert False, (
              R"Tensor element type not supported: "
              + onnx.TensorProto.DataType.Name(
                  onnx_value_info_proto.type.tensor_type.elem_type
              )
          )
  
      with open(file_path, "wb") as f:
          f.write(tp.SerializeToString())
  
imports: import os
  import re
  import shutil
  import numpy
  import scipy
  import cntk
  import pytest
  from .onnx_verify_helper import verify_results_with_onnxruntime, get_onnx_test_runner_callscript
label_desc: Use image node_id 8 for calling a global function with example usage: save_cntk_data_as_onnx_tensor(file_path, variable, data, onnx_value_info_proto) without return types