code: def save_model_to_weights_file(weights_file, model):
      """Stash model weights in a dictionary and pickle them to a file. We map
      GPU device scoped names to unscoped names (e.g., 'gpu_0/conv1_w' ->
      'conv1_w').
      """
      logger.info(
          "Saving parameters and momentum to {}".format(
              os.path.abspath(weights_file)
          )
      )
      blobs = {}
      # Save all parameters
      for param in model.params:
          scoped_name = str(param)
          unscoped_name = c2_utils.UnscopeName(scoped_name)
          if unscoped_name not in blobs:
              logger.debug(
                  " {:s} -> {:s}".format(scoped_name, unscoped_name)
              )
              blobs[unscoped_name] = workspace.FetchBlob(scoped_name)
      # Save momentum
      for param in model.TrainableParams():
          scoped_name = str(param) + "_momentum"
          unscoped_name = c2_utils.UnscopeName(scoped_name)
          if unscoped_name not in blobs:
              logger.debug(
                  " {:s} -> {:s}".format(scoped_name, unscoped_name)
              )
              blobs[unscoped_name] = workspace.FetchBlob(scoped_name)
      # Save preserved blobs
      for scoped_name in workspace.Blobs():
          if scoped_name.startswith("__preserve__/"):
              unscoped_name = c2_utils.UnscopeName(scoped_name)
              if unscoped_name not in blobs:
                  logger.debug(
                      " {:s} -> {:s} (preserved)".format(
                          scoped_name, unscoped_name
                      )
                  )
                  blobs[unscoped_name] = workspace.FetchBlob(
                      scoped_name
                  )
      cfg_yaml = yaml.dump(cfg)
      save_object(dict(blobs=blobs, cfg=cfg_yaml), weights_file)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from __future__ import unicode_literals
  from collections import OrderedDict
  import cPickle
  import logging
  import numpy
  import os
  import pprint
  import yaml
  from caffe2.python import core
  from caffe2.python import workspace
  from detectron.core.config import cfg
  from detectron.core.config import load_cfg
  from detectron.utils.io import save_object
  import detectron.utils.c2
label_desc: Use image node_id 3 for calling a global function with example usage: save_model_to_weights_file(weights_file, model) without return types