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


Python variable_pb2.VariableDef方法代码示例

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


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

示例1: to_proto

# 需要导入模块: from tensorflow.core.framework import variable_pb2 [as 别名]
# 或者: from tensorflow.core.framework.variable_pb2 import VariableDef [as 别名]
def to_proto(self, export_scope=None):
    """Converts a `Variable` to a `VariableDef` protocol buffer.

    Args:
      export_scope: Optional `string`. Name scope to remove.

    Returns:
      A `VariableDef` protocol buffer, or `None` if the `Variable` is not
      in the specified name scope.
    """
    if (export_scope is None or
        self._variable.name.startswith(export_scope)):
      var_def = variable_pb2.VariableDef()
      var_def.variable_name = ops.strip_name_scope(
          self._variable.name, export_scope)
      var_def.initializer_name = ops.strip_name_scope(
          self.initializer.name, export_scope)
      var_def.snapshot_name = ops.strip_name_scope(
          self._snapshot.name, export_scope)
      if self._save_slice_info:
        var_def.save_slice_info_def.MergeFrom(self._save_slice_info.to_proto(
            export_scope=export_scope))
      return var_def
    else:
      return None 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:27,代码来源:variables.py

示例2: _init_from_proto

# 需要导入模块: from tensorflow.core.framework import variable_pb2 [as 别名]
# 或者: from tensorflow.core.framework.variable_pb2 import VariableDef [as 别名]
def _init_from_proto(self, variable_def, import_scope=None):
    """Creates a new variable from `VariableDef` protocol buffer.

    Args:
      variable_def: `VariableDef` protocol buffer.
      import_scope: Optional `string`. Name scope to add.
    """
    assert isinstance(variable_def, variable_pb2.VariableDef)
    # Create from variable_def.
    g = ops.get_default_graph()
    self._variable = g.as_graph_element(
        ops.prepend_name_scope(variable_def.variable_name,
                               import_scope=import_scope))
    self._initializer_op = g.as_graph_element(
        ops.prepend_name_scope(variable_def.initializer_name,
                               import_scope=import_scope))
    self._snapshot = g.as_graph_element(
        ops.prepend_name_scope(variable_def.snapshot_name,
                               import_scope=import_scope))
    if variable_def.HasField("save_slice_info_def"):
      self._save_slice_info = Variable.SaveSliceInfo(
          save_slice_info_def=variable_def.save_slice_info_def)
    else:
      self._save_slice_info = None
    self._caching_device = None 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:27,代码来源:variables.py

示例3: _get_grads

# 需要导入模块: from tensorflow.core.framework import variable_pb2 [as 别名]
# 或者: from tensorflow.core.framework.variable_pb2 import VariableDef [as 别名]
def _get_grads(single_gpu_meta_graph_def):
    trainable_vars = []
    trainable_vars_defs = single_gpu_meta_graph_def.collection_def[tf.GraphKeys.TRAINABLE_VARIABLES]
    for var_def_string in trainable_vars_defs.bytes_list.value:
        var_def = variable_pb2.VariableDef()
        var_def.ParseFromString(var_def_string)
        trainable_vars.append(var_def.variable_name)
    sparse_grads = []
    dense_grads = []
    grad_info_defs = single_gpu_meta_graph_def.collection_def[tf.GraphKeys.GRADIENTS_INFO]
    for grad_info_def_string in grad_info_defs.bytes_list.value:
        gradients_info_def = gradients_info_pb2.GradientsInfoDef()
        gradients_info_def.ParseFromString(grad_info_def_string)
        if gradients_info_def.target_tensor_info.values_tensor_name not in trainable_vars:
            continue
        if gradients_info_def.grad_tensor_info.tensor_type == gradients_info_pb2.GradientsInfoDef.TensorInfoDef.INDEXED_SLICES:
            sparse_grads.append(gradients_info_def)
        else:
            dense_grads.append(gradients_info_def)
    assert len(sparse_grads) > 0 or len(dense_grads) > 0
    return sparse_grads, dense_grads 
开发者ID:snuspl,项目名称:parallax,代码行数:23,代码来源:runner.py

示例4: _init_from_proto

# 需要导入模块: from tensorflow.core.framework import variable_pb2 [as 别名]
# 或者: from tensorflow.core.framework.variable_pb2 import VariableDef [as 别名]
def _init_from_proto(self, variable_def, import_scope=None):
    """Recreates the Variable object from a `VariableDef` protocol buffer.

    Args:
      variable_def: `VariableDef` protocol buffer, describing a variable
          whose nodes already exists in the graph.
      import_scope: Optional `string`. Name scope to add.
    """
    assert isinstance(variable_def, variable_pb2.VariableDef)
    # Create from variable_def.
    g = ops.get_default_graph()
    self._variable = g.as_graph_element(
        ops.prepend_name_scope(variable_def.variable_name,
                               import_scope=import_scope))
    self._initializer_op = g.as_graph_element(
        ops.prepend_name_scope(variable_def.initializer_name,
                               import_scope=import_scope))
    self._snapshot = g.as_graph_element(
        ops.prepend_name_scope(variable_def.snapshot_name,
                               import_scope=import_scope))
    if variable_def.HasField("save_slice_info_def"):
      self._save_slice_info = Variable.SaveSliceInfo(
          save_slice_info_def=variable_def.save_slice_info_def)
    else:
      self._save_slice_info = None
    self._caching_device = None 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:28,代码来源:variables.py

示例5: _init_from_proto

# 需要导入模块: from tensorflow.core.framework import variable_pb2 [as 别名]
# 或者: from tensorflow.core.framework.variable_pb2 import VariableDef [as 别名]
def _init_from_proto(self, variable_def, import_scope=None):
    """Initializes from `VariableDef` proto."""
    assert isinstance(variable_def, variable_pb2.VariableDef)
    if not variable_def.is_resource:
      raise ValueError("Trying to restore Variable as ResourceVariable.")

    # Create from variable_def.
    g = ops.get_default_graph()
    self._handle = g.as_graph_element(
        ops.prepend_name_scope(variable_def.variable_name,
                               import_scope=import_scope))
    self._initialize_op = g.as_graph_element(
        ops.prepend_name_scope(variable_def.initializer_name,
                               import_scope=import_scope))
    if variable_def.snapshot_name:
      self._cached_value = g.as_graph_element(
          ops.prepend_name_scope(variable_def.snapshot_name,
                                 import_scope=import_scope))
    else:
      self._cached_value = None
    if variable_def.HasField("save_slice_info_def"):
      self._save_slice_info = variables.Variable.SaveSliceInfo(
          save_slice_info_def=variable_def.save_slice_info_def)
    else:
      self._save_slice_info = None
    self._caching_device = None
    self._dtype = dtypes.as_dtype(self._handle.op.get_attr("dtype"))
    self._graph_element = self.value() 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:30,代码来源:resource_variable_ops.py

示例6: to_proto

# 需要导入模块: from tensorflow.core.framework import variable_pb2 [as 别名]
# 或者: from tensorflow.core.framework.variable_pb2 import VariableDef [as 别名]
def to_proto(self, export_scope=None):
    """Converts a `ResourceVariable` to a `VariableDef` protocol buffer.

    Args:
      export_scope: Optional `string`. Name scope to remove.

    Returns:
      A `VariableDef` protocol buffer, or `None` if the `Variable` is not
      in the specified name scope.
    """
    if (export_scope is None or
        self.handle.name.startswith(export_scope)):
      var_def = variable_pb2.VariableDef()
      var_def.variable_name = ops.strip_name_scope(
          self.handle.name, export_scope)
      var_def.initializer_name = ops.strip_name_scope(
          self.initializer.name, export_scope)
      if self._cached_value is not None:
        var_def.snapshot_name = ops.strip_name_scope(
            self._cached_value.name, export_scope)
      var_def.is_resource = True
      if self._save_slice_info:
        var_def.save_slice_info_def.MergeFrom(self._save_slice_info.to_proto(
            export_scope=export_scope))
      return var_def
    else:
      return None 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:29,代码来源:resource_variable_ops.py

示例7: _from_proto_fn

# 需要导入模块: from tensorflow.core.framework import variable_pb2 [as 别名]
# 或者: from tensorflow.core.framework.variable_pb2 import VariableDef [as 别名]
def _from_proto_fn(v, import_scope=None):
  """Creates Variable or ResourceVariable from VariableDef as needed."""
  if v.is_resource:
    return ResourceVariable.from_proto(v, import_scope=import_scope)
  return variables.Variable.from_proto(v, import_scope=import_scope) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:7,代码来源:resource_variable_ops.py

示例8: update_snapshot_name

# 需要导入模块: from tensorflow.core.framework import variable_pb2 [as 别名]
# 或者: from tensorflow.core.framework.variable_pb2 import VariableDef [as 别名]
def update_snapshot_name(self, var_coll_name):
    var_list = self._metagraph.collection_def[var_coll_name]
    for i, value in enumerate(var_list.bytes_list.value):
      var_def = variable_pb2.VariableDef()
      var_def.ParseFromString(value)
      # Somehow node Model/global_step/read doesn't have any fanout and seems to
      # be only used for snapshot; this is different from all other variables.
      if var_def.snapshot_name != "Model/global_step/read:0":
        var_def.snapshot_name = with_autoparallel_prefix(
            0, var_def.snapshot_name)
      value = var_def.SerializeToString()
      var_list.bytes_list.value[i] = value 
开发者ID:rky0930,项目名称:yolo_v2,代码行数:14,代码来源:util.py

示例9: update_local_variables

# 需要导入模块: from tensorflow.core.framework import variable_pb2 [as 别名]
# 或者: from tensorflow.core.framework.variable_pb2 import VariableDef [as 别名]
def update_local_variables(multi_gpu_meta_graph_def, op_names_to_replicate,
                            num_replicas):
    def _get_new_var_def(var_def, prefix):
        new_var_def = variable_pb2.VariableDef()
        new_var_def.CopyFrom(var_def)
        new_var_def.variable_name = \
            ops.prepend_name_scope(var_def.variable_name, prefix)
        new_var_def.initializer_name = \
            ops.prepend_name_scope(var_def.initializer_name, prefix)
        new_var_def.snapshot_name = \
            ops.prepend_name_scope(var_def.snapshot_name, prefix)
        return new_var_def

    if tf.GraphKeys.LOCAL_VARIABLES not in multi_gpu_meta_graph_def.collection_def:
        return

    lv_collection = \
        multi_gpu_meta_graph_def.collection_def[tf.GraphKeys.LOCAL_VARIABLES]
    new_lv_col = meta_graph_pb2.CollectionDef()
    for var_def_string in lv_collection.bytes_list.value:
        var_def = variable_pb2.VariableDef()
        var_def.ParseFromString(var_def_string)
        if _get_op_name(var_def.variable_name) in op_names_to_replicate:
            new_var_defs = \
                [_get_new_var_def(var_def, parallax_replica_prefix(i))
                 for i in range(num_replicas)]
            new_lv_col.bytes_list.value.extend(
                [new_var_def.SerializeToString()
                 for new_var_def in new_var_defs])
        else:
            new_lv_col.bytes_list.value.append(var_def.SerializeToString())
    multi_gpu_meta_graph_def.collection_def[tf.GraphKeys.LOCAL_VARIABLES]\
        .Clear()
    multi_gpu_meta_graph_def.collection_def[tf.GraphKeys.LOCAL_VARIABLES]\
        .CopyFrom(new_lv_col)
    if len(lv_collection.bytes_list.value) == 0:
        del multi_gpu_meta_graph_def\
            .collection_def[tf.GraphKeys.LOCAL_VARIABLES] 
开发者ID:snuspl,项目名称:parallax,代码行数:40,代码来源:graph_transform_lib.py

示例10: strip_meta_graph

# 需要导入模块: from tensorflow.core.framework import variable_pb2 [as 别名]
# 或者: from tensorflow.core.framework.variable_pb2 import VariableDef [as 别名]
def strip_meta_graph(meta_graph_def, node_names, var_names):
  node_names = node_names[:]
  collections = meta_graph_def.collection_def

  # Look for matching variable names and initializers and keep them too.
  var_def = variable_pb2.VariableDef()
  for var_col_name in ["variables", "trainable_variables"]:
    var_def_bs = collections[var_col_name].bytes_list.value
    for var_def_b in var_def_bs:
      var_def.ParseFromString(var_def_b)
      if var_def.variable_name not in var_names:
        # TODO(adamb) Should remove variable from collection.
        continue
      node_names.append(var_def.initializer_name)

  wc_def = control_flow_pb2.WhileContextDef()
  wc_values = collections["while_context"].bytes_list.value
  for wc_ix in range(len(wc_values) - 1, -1, -1):
    wc_bytes = wc_values[wc_ix]
    wc_def.ParseFromString(wc_bytes)
    unused = True
    wc_pivot_name = wc_def.pivot_name
    for name in node_names:
      if name.startswith(wc_pivot_name):
        unused = False
        break

    if unused:
      del wc_values[wc_ix]

  graph_def = meta_graph_def.graph_def
  eprint("only keeping", node_names, "from", [n.name for n in graph_def.node])
  graph_def = graph_util.extract_sub_graph(graph_def, node_names)
  meta_graph_def.graph_def.CopyFrom(graph_def) 
开发者ID:tensorlang,项目名称:tensorlang,代码行数:36,代码来源:graph_xform.py

示例11: _init_from_proto

# 需要导入模块: from tensorflow.core.framework import variable_pb2 [as 别名]
# 或者: from tensorflow.core.framework.variable_pb2 import VariableDef [as 别名]
def _init_from_proto(self, variable_def, import_scope=None):
    """Recreates the Variable object from a `VariableDef` protocol buffer.

    Args:
      variable_def: `VariableDef` protocol buffer, describing a variable
          whose nodes already exists in the graph.
      import_scope: Optional `string`. Name scope to add.
    """
    assert isinstance(variable_def, variable_pb2.VariableDef)
    # Create from variable_def.
    g = ops.get_default_graph()
    self._variable = g.as_graph_element(
        ops.prepend_name_scope(variable_def.variable_name,
                               import_scope=import_scope))
    self._initializer_op = g.as_graph_element(
        ops.prepend_name_scope(variable_def.initializer_name,
                               import_scope=import_scope))
    # Tests whether initial_value_name exists first for backwards compatibility.
    if (hasattr(variable_def, "initial_value_name") and
        variable_def.initial_value_name):
      self._initial_value = g.as_graph_element(
          ops.prepend_name_scope(variable_def.initial_value_name,
                                 import_scope=import_scope))
    else:
      self._initial_value = None
    self._snapshot = g.as_graph_element(
        ops.prepend_name_scope(variable_def.snapshot_name,
                               import_scope=import_scope))
    if variable_def.HasField("save_slice_info_def"):
      self._save_slice_info = Variable.SaveSliceInfo(
          save_slice_info_def=variable_def.save_slice_info_def)
    else:
      self._save_slice_info = None
    self._caching_device = None
    self._constraint = None 
开发者ID:PacktPublishing,项目名称:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代码行数:37,代码来源:variables.py

示例12: to_proto

# 需要导入模块: from tensorflow.core.framework import variable_pb2 [as 别名]
# 或者: from tensorflow.core.framework.variable_pb2 import VariableDef [as 别名]
def to_proto(self, export_scope=None):
    """Converts a `Variable` to a `VariableDef` protocol buffer.

    Args:
      export_scope: Optional `string`. Name scope to remove.

    Returns:
      A `VariableDef` protocol buffer, or `None` if the `Variable` is not
      in the specified name scope.
    """
    if (export_scope is None or
        self._variable.name.startswith(export_scope)):
      var_def = variable_pb2.VariableDef()
      var_def.variable_name = ops.strip_name_scope(
          self._variable.name, export_scope)
      if self._initial_value is not None:
        # For backwards compatibility.
        var_def.initial_value_name = ops.strip_name_scope(
            self._initial_value.name, export_scope)
      var_def.initializer_name = ops.strip_name_scope(
          self.initializer.name, export_scope)
      var_def.snapshot_name = ops.strip_name_scope(
          self._snapshot.name, export_scope)
      if self._save_slice_info:
        var_def.save_slice_info_def.MergeFrom(self._save_slice_info.to_proto(
            export_scope=export_scope))
      return var_def
    else:
      return None 
开发者ID:PacktPublishing,项目名称:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代码行数:31,代码来源:variables.py

示例13: _init_from_proto

# 需要导入模块: from tensorflow.core.framework import variable_pb2 [as 别名]
# 或者: from tensorflow.core.framework.variable_pb2 import VariableDef [as 别名]
def _init_from_proto(self, variable_def, import_scope=None):
    """Initializes from `VariableDef` proto."""
    # Note that init_from_proto is currently not supported in Eager mode.
    assert context.in_graph_mode()
    self._in_graph_mode = True
    assert isinstance(variable_def, variable_pb2.VariableDef)
    if not variable_def.is_resource:
      raise ValueError("Trying to restore Variable as ResourceVariable.")

    # Create from variable_def.
    g = ops.get_default_graph()
    self._handle = g.as_graph_element(
        ops.prepend_name_scope(
            variable_def.variable_name, import_scope=import_scope))
    self._graph_shape = tensor_shape.TensorShape(
        self._handle.op.get_attr("shape"))
    self._handle_device = self._handle.device
    self._handle_name = self._handle.name
    self._initializer_op = g.as_graph_element(
        ops.prepend_name_scope(
            variable_def.initializer_name, import_scope=import_scope))
    if variable_def.snapshot_name:
      self._cached_value = g.as_graph_element(
          ops.prepend_name_scope(
              variable_def.snapshot_name, import_scope=import_scope))
    else:
      self._cached_value = None
    if variable_def.HasField("save_slice_info_def"):
      self._save_slice_info = variables.Variable.SaveSliceInfo(
          save_slice_info_def=variable_def.save_slice_info_def)
    else:
      self._save_slice_info = None
    self._caching_device = None
    self._dtype = dtypes.as_dtype(self._handle.op.get_attr("dtype"))
    self._graph_element = self.value()
    self._constraint = None
  # LINT.ThenChange(//tensorflow/python/eager/graph_callable.py) 
开发者ID:PacktPublishing,项目名称:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代码行数:39,代码来源:resource_variable_ops.py

示例14: to_proto

# 需要导入模块: from tensorflow.core.framework import variable_pb2 [as 别名]
# 或者: from tensorflow.core.framework.variable_pb2 import VariableDef [as 别名]
def to_proto(self, export_scope=None):
    """Converts a `ResourceVariable` to a `VariableDef` protocol buffer.

    Args:
      export_scope: Optional `string`. Name scope to remove.

    Raises:
      RuntimeError: If run in EAGER mode.

    Returns:
      A `VariableDef` protocol buffer, or `None` if the `Variable` is not
      in the specified name scope.
    """
    if context.in_eager_mode():
      raise RuntimeError("to_proto not supported in EAGER mode.")
    if export_scope is None or self.handle.name.startswith(export_scope):
      var_def = variable_pb2.VariableDef()
      var_def.variable_name = ops.strip_name_scope(self.handle.name,
                                                   export_scope)
      var_def.initializer_name = ops.strip_name_scope(self.initializer.name,
                                                      export_scope)
      if self._cached_value is not None:
        var_def.snapshot_name = ops.strip_name_scope(self._cached_value.name,
                                                     export_scope)
      var_def.is_resource = True
      if self._save_slice_info:
        var_def.save_slice_info_def.MergeFrom(
            self._save_slice_info.to_proto(export_scope=export_scope))
      return var_def
    else:
      return None 
开发者ID:PacktPublishing,项目名称:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代码行数:33,代码来源:resource_variable_ops.py

示例15: _to_proto_fn

# 需要导入模块: from tensorflow.core.framework import variable_pb2 [as 别名]
# 或者: from tensorflow.core.framework.variable_pb2 import VariableDef [as 别名]
def _to_proto_fn(v, export_scope=None):
  """Converts Variable and ResourceVariable to VariableDef for collections."""
  return v.to_proto(export_scope=export_scope) 
开发者ID:PacktPublishing,项目名称:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代码行数:5,代码来源:resource_variable_ops.py


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