code: def types_to_proto(valuetype):
      if types.is_tensor(valuetype):
          primitive = types_to_proto_primitive(
              valuetype.get_primitive()
          )
          return create_valuetype_tensor(
              valuetype.get_shape(), primitive
          )
      elif types.is_tuple(valuetype):
          v_type = pm.ValueType()
          t_type = v_type.tupleType
          for t in valuetype.T:
              new_v_type = t_type.types.add()
              new_v_type.CopyFrom(types_to_proto(t))
          return v_type
      elif types.is_list(valuetype):
          elem = valuetype.T[0]
          length = valuetype.T[1]
          if types.is_tensor(elem):
              dtype = types_to_proto_primitive(elem.get_primitive())
              elem_shape = elem.get_shape()
          elif types.is_scalar(elem):
              dtype = types_to_proto_primitive(valuetype)
              elem_shape = ()
          elif types.is_str(elem):
              dtype = types_to_proto_primitive(elem)
              elem_shape = ()
          else:
              raise NotImplementedError(
                  "Only list of either tensors or scalars supported. "
                  "Got element of type {}".format(elem.__type_info__())
              )
          return create_valuetype_list(
              length=length, elem_shape=elem_shape, dtype=dtype
          )
      elif types.is_dict(valuetype):
          return create_valuetype_dict(valuetype.T[0], valuetype.T[1])
      else:
          return create_valuetype_scalar(
              types_to_proto_primitive(valuetype)
          )
  
imports: import os
  import numpy
  import coremltools.proto.FeatureTypes_pb2
  import coremltools.proto.MIL_pb2
  from coremltools.converters.mil.mil import types
  from coremltools.converters.mil.mil.types import BUILTIN_TO_PROTO_TYPES, builtin_to_string, numpy_type_to_builtin_type, type_to_builtin_type
  from coremltools.converters.mil.mil.types.type_mapping import np_val_to_py_type
  from coremltools.models.utils import _WEIGHTS_DIR_NAME, _WEIGHTS_FILE_NAME
label_desc: Use image node_id 16 for calling a global function with example usage: types_to_proto(valuetype) and returns: create_valuetype_tensor, v_type, create_valuetype_list, create_valuetype_dict, create_valuetype_scalar