code: def merge_params(net_def, data_type):
      def tensor_to_bytes(tensor):
          if tensor.data_type == mace_pb2.DT_HALF:
              data = bytearray(
                  np.array(tensor.float_data)
                  .astype(np.float16)
                  .tobytes()
              )
              tensor.data_size = len(tensor.float_data)
          elif tensor.data_type == mace_pb2.DT_FLOAT:
              data = bytearray(
                  np.array(tensor.float_data)
                  .astype(np.float32)
                  .tobytes()
              )
              tensor.data_size = len(tensor.float_data)
          elif tensor.data_type == mace_pb2.DT_INT32:
              data = bytearray(
                  np.array(tensor.int32_data).astype(np.int32).tobytes()
              )
              tensor.data_size = len(tensor.int32_data)
          elif tensor.data_type == mace_pb2.DT_UINT8:
              data = bytearray(
                  np.array(tensor.int32_data).astype(np.uint8).tolist()
              )
              tensor.data_size = len(tensor.int32_data)
          elif tensor.data_type == mace_pb2.DT_INT8:
              data = bytearray(
                  np.array(tensor.int32_data).astype(np.uint8).tolist()
              )
              tensor.data_size = len(tensor.int32_data)
          elif tensor.data_type == mace_pb2.DT_FLOAT16:
              data = bytearray(
                  np.array(tensor.float_data)
                  .astype(np.float16)
                  .tobytes()
              )
              tensor.data_size = len(tensor.float_data)
          elif tensor.data_type == mace_pb2.DT_BFLOAT16:
              data = Float2BFloat16Bytes(tensor.float_data)
              tensor.data_size = len(tensor.float_data)
          elif tensor.data_type == mace_pb2.DT_INT16:
              data = bytearray(
                  np.array(tensor.int32_data).astype(np.int16).tobytes()
              )
              tensor.data_size = len(tensor.int32_data)
          else:
              raise Exception(
                  "Tensor data type %s not supported" % tensor.data_type
              )
          return data
  
      model_data = []
      offset = 0
      for tensor in net_def.tensors:
          if tensor.data_type == mace_pb2.DT_FLOAT:
              tensor.data_type = data_type
          raw_data = tensor_to_bytes(tensor)
          if tensor.data_type != mace_pb2.DT_UINT8 and offset % 4 != 0:
              padding = 4 - offset % 4
              model_data.extend(bytearray([0] * padding))
              offset += padding
  
          tensor.offset = offset
          model_data.extend(raw_data)
          offset += len(raw_data)
  
      for tensor in net_def.tensors:
          if (
              tensor.data_type == mace_pb2.DT_FLOAT
              or tensor.data_type == mace_pb2.DT_HALF
              or tensor.data_type == mace_pb2.DT_FLOAT16
              or tensor.data_type == mace_pb2.DT_BFLOAT16
          ):
              del tensor.float_data[:]
          elif tensor.data_type == mace_pb2.DT_INT32:
              del tensor.int32_data[:]
          elif tensor.data_type == mace_pb2.DT_INT16:
              del tensor.int32_data[:]
          elif tensor.data_type == mace_pb2.DT_UINT8:
              del tensor.int32_data[:]
          elif tensor.data_type == mace_pb2.DT_INT8:
              del tensor.int32_data[:]
  
      return net_def, model_data
  
imports: import array
  import numpy
  import struct
  from py_proto import mace_pb2
label_desc: Use image node_id 2 for calling a global function with example usage: merge_params(net_def, data_type) and returns: net_def,  model_data, data