code: def _load_value(context, value_spec):
      if not isinstance(value_spec, pm.Value):
          raise TypeError("Invalid Value spec object")
  
      if value_spec.docString:
          raise ValueError("Docstring would get lost in the process.")
  
      if value_spec.type.WhichOneof("type") == "tensorType":
          valuetype = proto_to_types(value_spec.type)
  
          is_tensor = types.is_tensor(valuetype)
  
          dtype = (
              valuetype if not is_tensor else valuetype.get_primitive()
          )
          shape = () if not is_tensor else valuetype.get_shape()
  
          if value_spec.WhichOneof("value") == "immediateValue":
              value = _load_immediate_value(value_spec.immediateValue)
          else:
              value = _load_file_value(
                  context, value_spec.blobFileValue, dtype
              )
  
          if dtype in helper.IMMEDIATE_VALUE_TYPES_IN_BYTES:
              value = np.frombuffer(
                  value, types.nptype_from_builtin(dtype)
              ).reshape(shape)
          elif dtype == types.str and shape == ():
              value = str(value[0])
          elif dtype in (
              types.fp32,
              types.str,
              types.bool,
              types.int32,
              types.int64,
          ):
              value = (
                  np.array(value)
                  .astype(types.nptype_from_builtin(dtype))
                  .reshape(shape)
              )
          else:
              raise ValueError("Invalid dtype for tensor value")
      else:
          raise NotImplementedError(
              "Only value of tensorType implemented yet"
          )
  
      if not is_tensor and not isinstance(value, str):
          value = types.nptype_from_builtin(dtype)(value.item())
  
      return value
  
imports: import os
  import numpy
  from coremltools import _logger
  from coremltools.converters.mil._deployment_compatibility import AvailableTarget
  from coremltools.converters.mil.backend.mil import helper
  from coremltools.converters.mil.mil import Block
  from coremltools.converters.mil.mil import Builder
  from coremltools.converters.mil.mil import Function, ListVar, Placeholder, Program, TupleInputType, Var, mil_list, types
  from coremltools.converters.mil.mil.block import curr_block
  from coremltools.converters.mil.mil.ops.registry import SSAOpRegistry
  from coremltools.proto import MIL_pb2
  from coremltools.proto import Model_pb2
  from .helper import proto_to_types
label_desc: Use image node_id 4 for calling a global function with example usage: _load_value(context, value_spec) and returns: value