当前位置: 首页>>代码示例>>Python>>正文


Python tensorflow.model_variables方法代码示例

本文整理汇总了Python中tensorflow.model_variables方法的典型用法代码示例。如果您正苦于以下问题:Python tensorflow.model_variables方法的具体用法?Python tensorflow.model_variables怎么用?Python tensorflow.model_variables使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tensorflow的用法示例。


在下文中一共展示了tensorflow.model_variables方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _checkpoint_var_search

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import model_variables [as 别名]
def _checkpoint_var_search(self, checkpoint_path):
        reader = tf.train.NewCheckpointReader(checkpoint_path)
        saved_shapes = reader.get_variable_to_shape_map()
        model_names = tf.model_variables()  # Used by tf.slim layers
        if not len(tf.model_variables()):
            model_names = tf.global_variables()  # Fallback when slim is not used
        model_names = set([v.name.split(':')[0] for v in model_names])
        checkpoint_names = set(saved_shapes.keys())
        found_names = model_names & checkpoint_names
        missing_names = model_names - checkpoint_names
        shape_conflicts = set()
        restored = []
        with tf.variable_scope('', reuse=True):
            for name in found_names:
                # print(tf.global_variables())
                # print(name, name in model_names, name in checkpoint_names)
                var = tf.get_variable(name)
                var_shape = var.get_shape().as_list()
                if var_shape == saved_shapes[name]:
                    restored.append(var)
                else:
                    shape_conflicts.add(name)
        found_names -= shape_conflicts
        return (restored, sorted(found_names),
                sorted(missing_names), sorted(shape_conflicts)) 
开发者ID:ethz-asl,项目名称:hierarchical_loc,代码行数:27,代码来源:base_model.py

示例2: from_previous_ckpt

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import model_variables [as 别名]
def from_previous_ckpt(self,sess):

        sess.run(tf.global_variables_initializer())
        for var in tf.trainable_variables(): # trainable weights, we need surgery
            print(var.name, var.eval().mean())

        print('Restoring model snapshots from {:s}'.format(self.pretrained_model))
        saver_t = {}

        saver_t  = [var for var in tf.model_variables() if 'fc_binary' not in var.name \
                                                       and 'binary_classification' not in var.name \
                                                       and 'conv1_pose_map' not in var.name \
                                                       and 'pool1_pose_map' not in var.name \
                                                       and 'conv2_pose_map' not in var.name \
                                                       and 'pool2_pose_map' not in var.name]

        self.saver_restore = tf.train.Saver(saver_t)
        self.saver_restore.restore(sess, self.pretrained_model)

        print("the variables is being trained now \n")
        for var in tf.trainable_variables():
           print(var.name, var.eval().mean()) 
开发者ID:DirtyHarryLYL,项目名称:Transferable-Interactiveness-Network,代码行数:24,代码来源:train_Solver_HICO_pose_pattern_inD_more_positive_coslr.py

示例3: from_previous_ckpt

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import model_variables [as 别名]
def from_previous_ckpt(self,sess):

        sess.run(tf.global_variables_initializer())
        for var in tf.trainable_variables(): # trainable weights, we need surgery
            print(var.name, var.eval().mean())

        print('Restoring model snapshots from {:s}'.format(self.pretrained_model))
        saver_t = {}

        saver_t  = [var for var in tf.model_variables()]

        self.saver_restore = tf.train.Saver(saver_t)
        self.saver_restore.restore(sess, self.pretrained_model)

        print("the variables is being trained now \n")
        for var in tf.trainable_variables():
           print(var.name, var.eval().mean()) 
开发者ID:DirtyHarryLYL,项目名称:Transferable-Interactiveness-Network,代码行数:19,代码来源:train_Solver_VCOCO_pose_pattern_inD_more_positive.py

示例4: get_init_fn

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import model_variables [as 别名]
def get_init_fn(scopes, init_model):
  """Initialize assigment operator function used while training."""
  if not init_model:
    return None

  for var in tf.trainable_variables():
    if not (var in tf.model_variables()):
      tf.contrib.framework.add_model_variable(var)
   
  is_trainable = lambda x: x in tf.trainable_variables()
  var_list = []
  for scope in scopes:
    var_list.extend(
      filter(is_trainable, tf.contrib.framework.get_model_variables(scope)))
    
  init_assign_op, init_feed_dict = slim.assign_from_checkpoint(
    init_model, var_list)
  
  def init_assign_function(sess):
    sess.run(init_assign_op, init_feed_dict)

  return init_assign_function 
开发者ID:xcyan,项目名称:eccv18_mtvae,代码行数:24,代码来源:model_utils.py

示例5: _checkpoint_var_search

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import model_variables [as 别名]
def _checkpoint_var_search(self, checkpoint_path):
        reader = tf.train.NewCheckpointReader(checkpoint_path)
        saved_shapes = reader.get_variable_to_shape_map()
        model_names = tf.model_variables()  # Used by tf.slim layers
        if not len(tf.model_variables()):
            model_names = tf.global_variables()  # Fallback when slim is not used
        model_names = set([v.name.split(':')[0] for v in model_names])
        checkpoint_names = set(saved_shapes.keys())
        found_names = model_names & checkpoint_names
        missing_names = model_names - checkpoint_names
        shape_conflicts = set()
        restored = []
        with tf.variable_scope('', reuse=True):
            for name in found_names:
                var = tf.get_variable(name)
                var_shape = var.get_shape().as_list()
                if var_shape == saved_shapes[name]:
                    restored.append(var)
                else:
                    shape_conflicts.add(name)
        found_names -= shape_conflicts
        return (restored, sorted(found_names),
                sorted(missing_names), sorted(shape_conflicts)) 
开发者ID:ethz-asl,项目名称:hfnet,代码行数:25,代码来源:base_model.py

示例6: get_var_list_to_restore

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import model_variables [as 别名]
def get_var_list_to_restore():
  """Choose which vars to restore, ignore vars by setting --checkpoint_exclude_scopes """

  variables_to_restore = []
  if FLAGS.checkpoint_exclude_scopes is not None:
    exclusions = [scope.strip()
                  for scope in FLAGS.checkpoint_exclude_scopes.split(',')]

    # build restore list
    for var in tf.model_variables():
      for exclusion in exclusions:
        if var.name.startswith(exclusion):
          break
      else:
        variables_to_restore.append(var)
  else:
    variables_to_restore = tf.model_variables()

  variables_to_restore_final = []
  if FLAGS.checkpoint_include_scopes is not None:
      includes = [
              scope.strip()
              for scope in FLAGS.checkpoint_include_scopes.split(',')
              ]
      for var in variables_to_restore:
          for include in includes:
              if var.name.startswith(include):
                  variables_to_restore_final.append(var)
                  break
  else:
      variables_to_restore_final = variables_to_restore

  return variables_to_restore_final 
开发者ID:wuzheng-sjtu,项目名称:FastFPN,代码行数:35,代码来源:train_utils.py

示例7: get_var_list_to_restore

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import model_variables [as 别名]
def get_var_list_to_restore():
  """Choosing which vars to restore, ignore vars by setting --checkpoint_exclude_scopes """

  variables_to_restore = []
  if FLAGS.checkpoint_exclude_scopes is not None:
    exclusions = [scope.strip()
                  for scope in FLAGS.checkpoint_exclude_scopes.split(',')]

    # build restore list
    for var in tf.model_variables():
      excluded = False
      for exclusion in exclusions:
        if var.name.startswith(exclusion):
          excluded = True
          break
      if not excluded:
        variables_to_restore.append(var)
  else:
    variables_to_restore = tf.model_variables()

  variables_to_restore_final = []
  if FLAGS.checkpoint_include_scopes is not None:
      includes = [
              scope.strip()
              for scope in FLAGS.checkpoint_include_scopes.split(',')
              ]
      for var in variables_to_restore:
          included = False
          for include in includes:
              if var.name.startswith(include):
                  included = True
                  break
          if included:
              variables_to_restore_final.append(var)
  else:
      variables_to_restore_final = variables_to_restore

  return variables_to_restore_final 
开发者ID:CharlesShang,项目名称:FastMaskRCNN,代码行数:40,代码来源:train_utils.py

示例8: get_model_gradient_multipliers

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import model_variables [as 别名]
def get_model_gradient_multipliers(last_layers, last_layer_gradient_multiplier):
  """Gets the gradient multipliers.

  The gradient multipliers will adjust the learning rates for model
  variables. For the task of semantic segmentation, the models are
  usually fine-tuned from the models trained on the task of image
  classification. To fine-tune the models, we usually set larger (e.g.,
  10 times larger) learning rate for the parameters of last layer.

  Args:
    last_layers: Scopes of last layers.
    last_layer_gradient_multiplier: The gradient multiplier for last layers.

  Returns:
    The gradient multiplier map with variables as key, and multipliers as value.
  """
  gradient_multipliers = {}

  for var in tf.model_variables():
    # Double the learning rate for biases.
    if 'biases' in var.op.name:
      gradient_multipliers[var.op.name] = 2.

    # Use larger learning rate for last layer variables.
    for layer in last_layers:
      if layer in var.op.name and 'biases' in var.op.name:
        gradient_multipliers[var.op.name] = 2 * last_layer_gradient_multiplier
        break
      elif layer in var.op.name:
        gradient_multipliers[var.op.name] = last_layer_gradient_multiplier
        break

  return gradient_multipliers 
开发者ID:IBM,项目名称:MAX-Image-Segmenter,代码行数:35,代码来源:train_utils.py

示例9: _log_summaries

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import model_variables [as 别名]
def _log_summaries(input_image, label, num_of_classes, output):
  """Logs the summaries for the model.

  Args:
    input_image: Input image of the model. Its shape is [batch_size, height,
      width, channel].
    label: Label of the image. Its shape is [batch_size, height, width].
    num_of_classes: The number of classes of the dataset.
    output: Output of the model. Its shape is [batch_size, height, width].
  """
  # Add summaries for model variables.
  for model_var in tf.model_variables():
    tf.summary.histogram(model_var.op.name, model_var)

  # Add summaries for images, labels, semantic predictions.
  if FLAGS.save_summaries_images:
    tf.summary.image('samples/%s' % common.IMAGE, input_image)

    # Scale up summary image pixel values for better visualization.
    pixel_scaling = max(1, 255 // num_of_classes)
    summary_label = tf.cast(label * pixel_scaling, tf.uint8)
    tf.summary.image('samples/%s' % common.LABEL, summary_label)

    predictions = tf.expand_dims(tf.argmax(output, 3), -1)
    summary_predictions = tf.cast(predictions * pixel_scaling, tf.uint8)
    tf.summary.image('samples/%s' % common.OUTPUT_TYPE, summary_predictions) 
开发者ID:IBM,项目名称:MAX-Image-Segmenter,代码行数:28,代码来源:train.py

示例10: _shadow_model_variables

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import model_variables [as 别名]
def _shadow_model_variables(shadow_vars):
        """
        Create shadow vars for model_variables as well, and add to the list of ``shadow_vars``.

        Returns:
            list of (shadow_model_var, local_model_var) used for syncing.
        """
        G = tf.get_default_graph()
        curr_shadow_vars = set([v.name for v in shadow_vars])
        model_vars = tf.model_variables()
        shadow_model_vars = []
        for v in model_vars:
            assert v.name.startswith('tower'), "Found some MODEL_VARIABLES created outside of the tower function!"
            stripped_op_name, stripped_var_name = get_op_tensor_name(re.sub('^tower[0-9]+/', '', v.name))
            if stripped_op_name in curr_shadow_vars:
                continue
            try:
                G.get_tensor_by_name(stripped_var_name)
                logger.warn("Model Variable {} also appears in other collections.".format(stripped_var_name))
                continue
            except KeyError:
                pass
            new_v = tf.get_variable(stripped_op_name, dtype=v.dtype.base_dtype,
                                    initializer=v.initial_value,
                                    trainable=False)

            curr_shadow_vars.add(stripped_op_name)  # avoid duplicated shadow_model_vars
            shadow_vars.append(new_v)
            shadow_model_vars.append((new_v, v))  # only need to sync model_var from one tower
        return shadow_model_vars 
开发者ID:microsoft,项目名称:petridishnn,代码行数:32,代码来源:distributed.py

示例11: _get_sync_model_vars_op

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import model_variables [as 别名]
def _get_sync_model_vars_op(self):
        """
        Get the op to sync local model_variables to PS.
        """
        ops = []
        for (shadow_v, local_v) in self._shadow_model_vars:
            ops.append(shadow_v.assign(local_v.read_value()))
        assert len(ops)
        return tf.group(*ops, name='sync_{}_model_variables_to_ps'.format(len(ops))) 
开发者ID:microsoft,项目名称:petridishnn,代码行数:11,代码来源:distributed.py

示例12: _shadow_model_variables

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import model_variables [as 别名]
def _shadow_model_variables(shadow_vars):
        """
        Create shadow vars for model_variables as well, and add to the list of ``shadow_vars``.

        Returns:
            list of (shadow_model_var, local_model_var) used for syncing.
        """
        G = tf.get_default_graph()
        curr_shadow_vars = {v.name for v in shadow_vars}
        model_vars = tf.model_variables()
        shadow_model_vars = []
        for v in model_vars:
            assert v.name.startswith('tower'), "Found some MODEL_VARIABLES created outside of the tower function!"
            stripped_op_name, stripped_var_name = get_op_tensor_name(re.sub('^tower[0-9]+/', '', v.name))
            if stripped_op_name in curr_shadow_vars:
                continue
            try:
                G.get_tensor_by_name(stripped_var_name)
                logger.warn("Model Variable {} also appears in other collections.".format(stripped_var_name))
                continue
            except KeyError:
                pass
            new_v = tf.get_variable(stripped_op_name, dtype=v.dtype.base_dtype,
                                    initializer=v.initial_value,
                                    trainable=False)

            curr_shadow_vars.add(stripped_op_name)  # avoid duplicated shadow_model_vars
            shadow_vars.append(new_v)
            shadow_model_vars.append((new_v, v))  # only need to sync model_var from one tower
        return shadow_model_vars 
开发者ID:junsukchoe,项目名称:ADL,代码行数:32,代码来源:distributed.py

示例13: __init__

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import model_variables [as 别名]
def __init__(self, cfg, ckpt, 
                 is_calibrated=True, 
                 use_fcrn=False, 
                 use_regressor=True, 
                 image_dims=None,
                 mode='keyframe'):

        self.cfg = cfg
        self.ckpt = ckpt 
        self.mode = mode

        self.use_fcrn = use_fcrn
        self.use_regressor = use_regressor
        self.is_calibrated = is_calibrated

        if image_dims is not None:
            self.image_dims = image_dims
        else:
            if cfg.STRUCTURE.MODE == 'concat':
                self.image_dims = [cfg.INPUT.FRAMES, cfg.INPUT.HEIGHT, cfg.INPUT.WIDTH]
            else:
                self.image_dims = [None, cfg.INPUT.HEIGHT, cfg.INPUT.WIDTH]

        self.outputs = {}
        self._create_placeholders()
        self._build_motion_graph()
        self._build_depth_graph()
        self._build_reprojection_graph()
        self._build_visibility_graph()
        self._build_point_cloud_graph()

        self.depths = []
        self.poses = []

        if self.use_fcrn:
            self._build_fcrn_graph()

        self.saver = tf.train.Saver(tf.model_variables()) 
开发者ID:princeton-vl,项目名称:DeepV2D,代码行数:40,代码来源:deepv2d.py

示例14: __init__

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import model_variables [as 别名]
def __init__(self, cfg, ckpt, n_keyframes=2, rate=2, use_fcrn=True, 
            viz=True, mode='global', image_dims=[None, 192, 1088]):
        
        self.cfg = cfg
        self.ckpt = ckpt

        self.viz = viz
        self.mode = mode
        self.use_fcrn = use_fcrn
        self.image_dims = image_dims

        self.index = 0
        self.keyframe_inds = []

        self.images = []
        self.depths = []
        self.poses = []

        # tracking config parameters
        self.n_keyframes = n_keyframes # number of keyframes to use
        self.rate = rate # how often to sample new frames
        self.window = 3  # add edges if frames are within distance

        # build tensorflow graphs
        self.outputs = {}
        self._create_placeholders()
        self._build_motion_graph()
        self._build_depth_graph()
        self._build_reprojection_graph()
        self._build_point_cloud_graph()

        self.saver = tf.train.Saver(tf.model_variables()) 
开发者ID:princeton-vl,项目名称:DeepV2D,代码行数:34,代码来源:slam_kitti.py

示例15: __init__

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import model_variables [as 别名]
def __init__(self, cfg, ckpt, n_keyframes=1, rate=2, use_fcrn=True, 
            viz=True, mode='global', image_dims=[None, 480, 640]):
        
        self.cfg = cfg
        self.ckpt = ckpt

        self.viz = viz
        self.mode = mode
        self.use_fcrn = use_fcrn
        self.image_dims = image_dims

        self.index = 0
        self.keyframe_inds = []

        self.images = []
        self.depths = []
        self.poses = []

        # tracking config parameters
        self.n_keyframes = n_keyframes # number of keyframes to use
        self.rate = rate # how often to sample new frames
        self.window = 3  # add edges if frames are within distance

        # build tensorflow graphs
        self.outputs = {}
        self._create_placeholders()
        self._build_motion_graph()
        self._build_depth_graph()
        self._build_reprojection_graph()
        self._build_visibility_graph()
        self._build_point_cloud_graph()

        if self.use_fcrn:
            self._build_fcrn_graph()

        self.saver = tf.train.Saver(tf.model_variables()) 
开发者ID:princeton-vl,项目名称:DeepV2D,代码行数:38,代码来源:slam.py


注:本文中的tensorflow.model_variables方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。