original_docstring:  Loads a snapshot into a session from a weight path. Will only load the
          weights that are both in the weight_path file and the passed var_candidates.
docstring: Loads a snapshot into a session from a weight path. Will only load the
  weights that are both in the weight_path file and the passed var_candidates.
docstring_tokens: Loads a snapshot into a session from a weight path . Will only load the weights that are both in the weight_path file and the passed var_candidates .
code: def load_snapshot(sess, weight_path, var_candidates):
      """ Loads a snapshot into a session from a weight path. Will only load the
          weights that are both in the weight_path file and the passed var_candidates."""
      logging.info("Loading weights from pretrained model - %s ", weight_path)
      reader = tf.train.NewCheckpointReader(weight_path)
      var_map = reader.get_variable_to_shape_map()
      _rename = False
      if var_candidates[0].name.startswith("inf/"):
          var_candidates2 = []
          for var in var_candidates:
              # n_name = '/'.join(var.name.split('/')[1:]).split(':')[0]
              n_name = var.name.replace('inf', 'train').split(':')[0]
              var = tf.Variable(var, name=n_name)
              var_candidates2.append(var)
          var_candidates = var_candidates2
          _rename = True
          # var_map2 = dict()
          # for name, value in var_map.items():
          #     new_name = '/'.join(name.split('/')[1:])
          #     var_map2[new_name] = value
          # var_map = var_map2
      # inf/model/conv2d_9/bias:0
      # Only obtain all the variables that are [in the current graph] AND [in the checkpoint]
      vars_restore = []
      for vt in var_candidates:
          for vm in var_map.keys():
              if vt.name.split(':')[0] == vm:
                  if ("global_step" not in vt.name) and not (vt.name.startswith("train/")):
                      vars_restore.append(vt)
                      logging.info('restoring %s -> %s' % (vm, vt.name))
                  elif _rename:
                      vars_restore.append(vt)
                  else:
                      logging.info('NOT restoring %s -> %s' % (vm, vt.name))
      logging.info('Restoring %s variable ops.' % len(vars_restore))
      tf.train.Saver(vars_restore, max_to_keep=0, sharded=True).restore(sess, weight_path)
      logging.info('Variables restored.')
code_tokens: def load_snapshot ( sess , weight_path , var_candidates ) : logging . info ( "Loading weights from pretrained model - %s " , weight_path ) reader = tf . train . NewCheckpointReader ( weight_path ) var_map = reader . get_variable_to_shape_map ( ) _rename = False if var_candidates [ 0 ] . name . startswith ( "inf/" ) : var_candidates2 = [ ] for var in var_candidates : n_name = var . name . replace ( 'inf' , 'train' ) . split ( ':' ) [ 0 ] var = tf . Variable ( var , name = n_name ) var_candidates2 . append ( var ) var_candidates = var_candidates2 _rename = True vars_restore = [ ] for vt in var_candidates : for vm in var_map . keys ( ) : if vt . name . split ( ':' ) [ 0 ] == vm : if ( "global_step" not in vt . name ) and not ( vt . name . startswith ( "train/" ) ) : vars_restore . append ( vt ) logging . info ( 'restoring %s -> %s' % ( vm , vt . name ) ) elif _rename : vars_restore . append ( vt ) else : logging . info ( 'NOT restoring %s -> %s' % ( vm , vt . name ) ) logging . info ( 'Restoring %s variable ops.' % len ( vars_restore ) ) tf . train . Saver ( vars_restore , max_to_keep = 0 , sharded = True ) . restore ( sess , weight_path ) logging . info ( 'Variables restored.' )
short_docstring: Loads a snapshot into a session from a weight path.
short_docstring_tokens: Loads a snapshot into a session from a weight path .
comment: """ Loads a snapshot into a session from a weight path. Will only load the
          weights that are both in the weight_path file and the passed var_candidates."""$SEP$# n_name = '/'.join(var.name.split('/')[1:]).split(':')[0]$SEP$# var_map2 = dict()$SEP$# for name, value in var_map.items():$SEP$#     new_name = '/'.join(name.split('/')[1:])$SEP$#     var_map2[new_name] = value$SEP$# var_map = var_map2$SEP$# inf/model/conv2d_9/bias:0$SEP$# Only obtain all the variables that are [in the current graph] AND [in the checkpoint]