code: def gen_code_from_model(self, model_name, pb_model, model_weights):
      net_def = pb_model
  
      # comput mem size and mem block offset and update the net_def,
      # should count before ProtoConverter
      mem_computer = MemComputer(net_def, self.np_data_type)
      tensor_mem_size = mem_computer.compute()
  
      # gen the c++ NetDef struct
      net_def_converter = ProtoConverter(
          self.offset16, self.write_magic, NetDefExcludeFields
      )
      net_def_bytes = net_def_converter.proto_to_bytes(net_def)
      mace_check(net_def_bytes is not None, "proto_to_bytes failed.")
      self.code_gen.gen_net_def_data(
          model_name,
          net_def_bytes,
          self.model_dir + "micro_net_def_data.h",
      )
  
      # gen operator array
      (
          op_src_path_list,
          op_class_name_list,
          scratch_buffer_size,
      ) = self.op_resolver.get_op_desc_list_from_model()
      self.code_gen.gen_ops_data(
          model_name,
          op_src_path_list,
          op_class_name_list,
          self.model_dir + "micro_ops_list.h",
      )
  
      # gen the c++ Graph struct
      graph = GraphBuilder(net_def, self.op_resolver).build()
      graph_converter = ProtoConverter(self.offset16, self.write_magic)
      graph_bytes = graph_converter.proto_to_bytes(graph)
      self.code_gen.gen_graph_data(
          model_name, graph_bytes, self.model_dir + "micro_graph_data.h"
      )
  
      # gen micro engine config
      engine_data = {}
      engine_data["tensor_mem_size"] = tensor_mem_size
      engine_data["input_size"] = len(net_def.input_info)
      engine_data["scratch_buffer_size"] = scratch_buffer_size
      self.code_gen.gen_engin_config(
          model_name,
          engine_data,
          self.model_dir + "micro_engine_config.cc",
      )
  
      # gen micro model tensor data
      tensor_bytes = bytearray(model_weights)
      self.code_gen.gen_model_data(
          model_name,
          tensor_bytes,
          self.model_dir + "micro_model_data.h",
      )
  
      net_def_bytes = bytearray(net_def_bytes)
      graph_bytes = bytearray(graph_bytes)
      model_bytes = tensor_bytes
      offsets = np.zeros(6, dtype=np.int64)
      offsets[0] = offsets.size * 8
      offsets[1] = offsets[0] + len(net_def_bytes)
      offsets[2] = offsets[1] + len(graph_bytes)
      offsets[3] = offsets[2] + len(model_bytes)
      offsets[4] = tensor_mem_size
      offsets[5] = scratch_buffer_size
      offset_bytes = bytearray(offsets.tobytes())
      const_mem_bytes = (
          offset_bytes + net_def_bytes + graph_bytes + model_bytes
      )
  
      if not path.exists(".model"):
          os.mkdir(".model")
  
      model_bin = open(path.join(".model", model_name + ".bin"), "wb")
      model_bin.write(const_mem_bytes)
  
imports: import os
  from os import path
  import shutil
  import numpy
  from micro.graph_builder import GraphBuilder
  from micro.mem_computer import MemComputer
  from micro.micro_codegen import MicroCodeGen
  from micro.micro_io_converter import MicroIoConverter
  from micro.micro_op_converter import MicroOpConverter
  from micro.micro_support_ops import OpResolver
  from micro.proto_to_bytes import ProtoConverter
  from micro.scratch_computer import ScratchComputer
  from py_proto import mace_pb2
  from utils import util
  from utils.config_parser import ModelKeys
  from utils.convert_util import data_type_to_np_dt
  from utils.util import mace_check
label_desc: Use image node_id 2 for calling the MicroConverter obj's underlying member method code with example usage: obj.gen_code_from_model(model_name, pb_model, model_weights) without return types