code: def add_dt_cast_for_bf16(net_def):
      bf16_net_def = copy.deepcopy(net_def)
      op_num = len(bf16_net_def.op)
      for i in range(op_num):
          bf16_net_def.op.pop()
      model_input = {}
      for input_info in net_def.input_info:
          model_input[input_info.name] = input_info.dims
      model_output = {}
      for output_info in net_def.output_info:
          model_output[output_info.name] = output_info.dims
      for op_def in net_def.op:
          op_added = False
          if len(model_input) > 0:
              for i in range(len(op_def.input)):
                  input_name = op_def.input[i]
                  if input_name in model_input:
                      if op_added:
                          next_op = bf16_net_def.op.pop()
                      else:
                          next_op = copy.deepcopy(op_def)
                          op_added = True
  
                      op_cast = bf16_net_def.op.add()
                      op_cast.name = (
                          MaceOp.Cast.name + "_op_" + input_name
                      )
                      op_cast.type = MaceOp.Cast.name
                      op_cast.input.append(input_name)
                      trans_output_name = (
                          MaceOp.Cast.name + "_out_" + input_name
                      )
                      op_cast.output.append(trans_output_name)
                      data_type_arg = op_cast.arg.add()
                      data_type_arg.name = "T"
                      data_type_arg.i = mace_pb2.DT_FLOAT
                      op_cast.output_type.append(mace_pb2.DT_BFLOAT16)
                      output_shape = op_cast.output_shape.add()
                      output_shape.dims.extend(model_input[input_name])
  
                      next_op.input[i] = trans_output_name
                      bf16_net_def.op.append(next_op)
                      model_input.pop(input_name)
          if len(model_output) > 0:
              mace_check(
                  len(op_def.output) == 1, "Not support output num > 1"
              )
              output_name = op_def.output[0]
              if output_name in model_output:
                  if not op_added:
                      last_op = copy.deepcopy(op_def)
                      op_added = True
                  else:
                      last_op = bf16_net_def.op.pop()
                  last_op.output[0] = (
                      output_name + "_" + MaceOp.Cast.name
                  )
                  bf16_net_def.op.append(last_op)
  
                  op_cast = bf16_net_def.op.add()
                  op_cast.name = MaceOp.Cast.name + "_op_" + output_name
                  op_cast.type = MaceOp.Cast.name
                  op_cast.input.append(last_op.output[0])
                  op_cast.output.append(output_name)
                  data_type_arg = op_cast.arg.add()
                  data_type_arg.name = "T"
                  data_type_arg.i = mace_pb2.DT_BFLOAT16
                  op_cast.output_type.append(mace_pb2.DT_FLOAT)
                  output_shape = op_cast.output_shape.add()
                  output_shape.dims.extend(model_output[output_name])
                  model_output.pop(output_name)
          if not op_added:
              bf16_net_def.op.append(copy.deepcopy(op_def))
      return bf16_net_def
  
imports: from py_proto import mace_pb2
  from transform.base_converter import MaceOp
  from utils.util import mace_check
  import copy
label_desc: Use image node_id 1 for calling the MicroIoConverter obj's underlying member method code with example usage: obj.add_dt_cast_for_bf16(net_def) and returns: bf16_net_def