code: def TranslateModel(
      cls,
      caffe_net,
      pretrained_net,
      is_test=False,
      net_state=None,
      remove_legacy_pad=False,
      input_dims=None,
  ):
      net_state = (
          caffe_pb2.NetState() if net_state is None else net_state
      )
      net = caffe2_pb2.NetDef()
      net.name = caffe_net.name
      net_params = caffe2_pb2.TensorProtos()
      if len(caffe_net.layers) > 0:
          raise ValueError(
              "I think something is wrong. This translation script "
              "only accepts new style layers that are stored in the "
              "layer field."
          )
      if not input_dims:
          input_dims = _GetInputDims(caffe_net)
      for layer in caffe_net.layer:
          if not _ShouldInclude(net_state, layer):
              log.info(
                  "Current net state does not need layer {}".format(
                      layer.name
                  )
              )
              continue
          log.info("Translate layer {}".format(layer.name))
          # Get pretrained one
          pretrained_layers = [
              l for l in pretrained_net.layer if l.name == layer.name
          ] + [l for l in pretrained_net.layers if l.name == layer.name]
          if len(pretrained_layers) > 1:
              raise ValueError(
                  "huh? more than one pretrained layer of one name?"
              )
          elif len(pretrained_layers) == 1:
              pretrained_blobs = [
                  utils.CaffeBlobToNumpyArray(blob)
                  for blob in pretrained_layers[0].blobs
              ]
          else:
              # No pretrained layer for the given layer name. We'll just pass
              # no parameter blobs.
              # print 'No pretrained layer for layer', layer.name
              pretrained_blobs = []
          operators, params = cls.TranslateLayer(
              layer,
              pretrained_blobs,
              is_test,
              net=net,
              net_params=net_params,
              input_dims=input_dims,
          )
          net.op.extend(operators)
          net_params.protos.extend(params)
      if remove_legacy_pad:
          assert (
              input_dims
          ), "Please specify input_dims to remove legacy_pad"
          net = _RemoveLegacyPad(net, net_params, input_dims)
      return net, net_params
  
imports: import argparse
  import copy
  import logging
  import re
  import numpy
  from caffe2.proto import caffe2_pb2, caffe2_legacy_pb2
  from caffe.proto import caffe_pb2
  from caffe2.python import core, utils, workspace
  from google.protobuf import text_format
label_desc: Use image node_id 3 for calling the TranslatorRegistry obj's underlying member method code with example usage: obj.TranslateModel(cls, caffe_net, pretrained_net, is_test, net_state, remove_legacy_pad, input_dims) and returns: net,  net_params