code: def assign_attr_value(attr, val):
      from mmdnn.conversion.common.IR.graph_pb2 import TensorShape
  
      """Assign value to AttrValue proto according to data type."""
      if isinstance(val, bool):
          attr.b = val
      elif isinstance(val, integer_types):
          attr.i = val
      elif isinstance(val, float):
          attr.f = val
      elif isinstance(val, binary_type) or isinstance(val, text_type):
          if hasattr(val, "encode"):
              val = val.encode()
          attr.s = val
      elif isinstance(val, TensorShape):
          attr.shape.MergeFromString(val.SerializeToString())
      elif isinstance(val, list):
          if not val:
              return
          if isinstance(val[0], integer_types):
              attr.list.i.extend(val)
          elif isinstance(val[0], TensorShape):
              attr.list.shape.extend(val)
          elif isinstance(val[0], float):
              attr.list.f.extend(val)
          else:
              raise NotImplementedError(
                  "AttrValue cannot be of list[{}].".format(val[0])
              )
      elif isinstance(val, np.ndarray):
          assign_attr_value(attr, val.tolist())
      else:
          raise NotImplementedError(
              "AttrValue cannot be of %s" % type(val)
          )
  
file_path: MMdnn/mmdnn/conversion/common/utils.py
imports: from __future__ import division
  import os
  import sys
  import numpy
  from six import text_type, binary_type, integer_types
  import mmdnn.conversion.common.IR.graph_pb2
label_desc: Use image node_id 1 for calling a global function with example usage: assign_attr_value(attr, val) without return types