當前位置: 首頁>>代碼示例>>Python>>正文


Python io_ops.restore_v2方法代碼示例

本文整理匯總了Python中tensorflow.python.ops.io_ops.restore_v2方法的典型用法代碼示例。如果您正苦於以下問題:Python io_ops.restore_v2方法的具體用法?Python io_ops.restore_v2怎麽用?Python io_ops.restore_v2使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tensorflow.python.ops.io_ops的用法示例。


在下文中一共展示了io_ops.restore_v2方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: ReadNpArrays

# 需要導入模塊: from tensorflow.python.ops import io_ops [as 別名]
# 或者: from tensorflow.python.ops.io_ops import restore_v2 [as 別名]
def ReadNpArrays(file_prefix, nmap):
  """Reads from a tf checkpoint to fill in values of a NesteMap.

  Args:
    file_prefix: A TF checkpoint filename prefix.
    nmap: A NestedMap of numpy dtypes.

  Returns:
    A NestedMap with numpy arrays compatible w/ nmap.
  """
  g = tf.Graph()
  with g.as_default():
    reads = []
    for name, dtype in nmap.FlattenItems():
      reads.append(
          io_ops.restore_v2(
              prefix=file_prefix,
              tensor_names=[name],
              shape_and_slices=[""],
              dtypes=[dtype])[0])

  with tf.Session(graph=g) as sess:
    vals = sess.run(reads)

  return nmap.Pack(vals) 
開發者ID:tensorflow,項目名稱:lingvo,代碼行數:27,代碼來源:saver.py

示例2: _set_checkpoint_initializer

# 需要導入模塊: from tensorflow.python.ops import io_ops [as 別名]
# 或者: from tensorflow.python.ops.io_ops import restore_v2 [as 別名]
def _set_checkpoint_initializer(variable,
                                ckpt_file,
                                tensor_name,
                                slice_spec,
                                name="checkpoint_initializer"):
  """Overrides given variable's initialization op.

  Sets variable initializer to assign op that initializes variable from tensor's
  value in the checkpoint.

  Args:
    variable: `tf.Variable` object.
    ckpt_file: string, full path of the checkpoint.
    tensor_name: Name of the tensor to load from the checkpoint.
    slice_spec: Slice specification for loading partitioned tensors.
    name: Name of the operation.
  """
  base_type = variable.dtype.base_dtype
  restore_op = io_ops.restore_v2(
      ckpt_file, [tensor_name], [slice_spec], [base_type], name=name)[0]
  variable._initializer_op = state_ops.assign(variable, restore_op)  # pylint:disable=protected-access 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:23,代碼來源:checkpoint_utils.py

示例3: restore_op

# 需要導入模塊: from tensorflow.python.ops import io_ops [as 別名]
# 或者: from tensorflow.python.ops.io_ops import restore_v2 [as 別名]
def restore_op(self, filename_tensor, saveable, preferred_shard):
    tensors = []
    for spec in saveable.specs:
      # Ignore the moving_mean and moving_variance in other towers.
      if spec.name.startswith('replicated_'):
        if not spec.name.startswith('replicated_0') and 'BatchNorm/moving_' in spec.name:
          continue
        tensors.append(
              io_ops.restore_v2(
                filename_tensor,
                ['/'.join(spec.name.split('/')[1:])],
                [spec.slice_spec],
                [spec.tensor.dtype])[0])
      else:
        tensors.append(
              io_ops.restore_v2(
                  filename_tensor,
                  [spec.name],
                  [spec.slice_spec],
                  [spec.tensor.dtype])[0])

    return tensors 
開發者ID:medivhna,項目名稱:TF_Face_Toolbox,代碼行數:24,代碼來源:saver.py

示例4: _set_checkpoint_initializer

# 需要導入模塊: from tensorflow.python.ops import io_ops [as 別名]
# 或者: from tensorflow.python.ops.io_ops import restore_v2 [as 別名]
def _set_checkpoint_initializer(variable,
                                ckpt_file,
                                tensor_name,
                                slice_spec,
                                name="checkpoint_initializer"):
  """Overrides given variable's initialization op.

  Sets variable initializer to assign op that initializes variable from tensor's
  value in the checkpoint.

  Args:
    variable: `tf.Variable` object.
    ckpt_file: string, full path of the checkpoint.
    tensor_name: Name of the tensor to load from the checkpoint.
    slice_spec: Slice specification for loading partitioned tensors.
    name: Name of the operation.
  """
  base_type = variable.dtype.base_dtype
  with ops.colocate_with(variable):
    restore_op = io_ops.restore_v2(
        ckpt_file, [tensor_name], [slice_spec], [base_type], name=name)[0]
    variable._initializer_op = state_ops.assign(variable, restore_op)  # pylint:disable=protected-access 
開發者ID:PacktPublishing,項目名稱:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代碼行數:24,代碼來源:checkpoint_utils.py

示例5: _InputBatch

# 需要導入模塊: from tensorflow.python.ops import io_ops [as 別名]
# 或者: from tensorflow.python.ops.io_ops import restore_v2 [as 別名]
def _InputBatch(self):
    p = self.params

    @tf.function
    def ReadData():
      x, y = io_ops.restore_v2(p.ckpt, [p.data, p.label], [''] * 2,
                               [p.data_dtype, p.label_dtype])
      # Always convert to float32.
      return tf.cast(x, tf.float32), tf.cast(y, tf.float32)

    # Loads data and label into memory and keep it around.
    data, label = ops.cached_call(
        f=ReadData.get_concrete_function(), T=[tf.float32, tf.float32])
    b, shape = self.InfeedBatchSize(), list(p.data_shape)
    data = tf.reshape(data, [-1] + shape)
    label = tf.reshape(label, [-1])
    label = py_utils.HasShape(label, [tf.shape(data)[0]])
    sample_ids = ops.random_permutation_sequence(
        num=p.num_samples,
        batch=b,
        repeat=p.repeat,
        seed=p.random_seed if p.random_seed else 0)
    n = tf.shape(sample_ids)[0]
    raw = py_utils.PadOrTrimTo(tf.gather(data, sample_ids), [b] + shape)
    ret = py_utils.NestedMap(
        raw=raw,
        data=self._Preprocess(raw),
        label=py_utils.PadOrTrimTo(tf.gather(label, sample_ids), [b]),
        weight=py_utils.PadOrTrimTo(tf.ones([n], dtype=tf.float32), [b]))
    if not py_utils.use_tpu():
      ret['sample_ids'] = sample_ids
    return ret 
開發者ID:tensorflow,項目名稱:lingvo,代碼行數:34,代碼來源:base_input_generator.py

示例6: _BuildRestore

# 需要導入模塊: from tensorflow.python.ops import io_ops [as 別名]
# 或者: from tensorflow.python.ops.io_ops import restore_v2 [as 別名]
def _BuildRestore(self):
    """Builds restore ops."""
    assign_ops = []
    for var in self._vars:
      val, = io_ops.restore_v2(
          prefix=self._restore_prefix_ph,
          tensor_names=[_VarKey(var)],
          shape_and_slices=[""],
          dtypes=[var.dtype])
      assign_ops.append(var.assign(val))
    self._restore_op = tf.group(*assign_ops) 
開發者ID:tensorflow,項目名稱:lingvo,代碼行數:13,代碼來源:saver.py

示例7: restore_op

# 需要導入模塊: from tensorflow.python.ops import io_ops [as 別名]
# 或者: from tensorflow.python.ops.io_ops import restore_v2 [as 別名]
def restore_op(self, filename_tensor, saveable, preferred_shard):
    """Create ops to restore 'saveable'.

    This is intended to be overridden by subclasses that want to generate
    different Ops.

    Args:
      filename_tensor: String Tensor.
      saveable: A BaseSaverBuilder.SaveableObject object.
      preferred_shard: Int.  Shard to open first when loading a sharded file.

    Returns:
      A list of Tensors resulting from reading 'saveable' from
        'filename'.
    """
    # pylint: disable=protected-access
    tensors = []
    for spec in saveable.specs:
      tensors.append(
          io_ops.restore_v2(
              filename_tensor,
              [spec.name],
              [spec.slice_spec],
              [spec.tensor.dtype])[0])

    return tensors
  # pylint: enable=unused-argument 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:29,代碼來源:saver.py

示例8: _set_checkpoint_initializer

# 需要導入模塊: from tensorflow.python.ops import io_ops [as 別名]
# 或者: from tensorflow.python.ops.io_ops import restore_v2 [as 別名]
def _set_checkpoint_initializer(variable, file_pattern, tensor_name, slice_spec,
                                name="checkpoint_initializer"):
  """Sets variable initializer to assign op form value in checkpoint's tensor.

  Args:
    variable: `Variable` object.
    file_pattern: string, where to load checkpoints from.
    tensor_name: Name of the `Tensor` to load from checkpoint reader.
    slice_spec: Slice specification for loading partitioned variables.
    name: Name of the operation.
  """
  base_type = variable.dtype.base_dtype
  restore_op = io_ops.restore_v2(
      file_pattern, [tensor_name], [slice_spec], [base_type], name=name)[0]
  variable._initializer_op = state_ops.assign(variable, restore_op) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:17,代碼來源:checkpoint_utils.py

示例9: _set_checkpoint_initializer

# 需要導入模塊: from tensorflow.python.ops import io_ops [as 別名]
# 或者: from tensorflow.python.ops.io_ops import restore_v2 [as 別名]
def _set_checkpoint_initializer(variable,
                                ckpt_file,
                                tensor_name,
                                slice_spec,
                                name="checkpoint_initializer"):
  """Overrides given variable's initialization op.

  Sets variable initializer to assign op that initializes variable from tensor's
  value in the checkpoint.

  Args:
    variable: `tf.Variable` object.
    ckpt_file: string, full path of the checkpoint.
    tensor_name: Name of the tensor to load from the checkpoint.
    slice_spec: Slice specification for loading partitioned tensors.
    name: Name of the operation.
  """
  base_type = variable.dtype.base_dtype
  # Do not colocate with variable since RestoreV2 op only runs on CPU and
  # colocation will force variable (and other ops that colocate with variable)
  # to be on CPU as well. It is okay to place the variable's initializer op on
  # CPU since it will only be run once at the start.
  with ops.device(variable.device), ops.device("/cpu:0"):
    restore_op = io_ops.restore_v2(
        ckpt_file, [tensor_name], [slice_spec], [base_type], name=name)[0]

    names_to_saveables = saveable_object_util.op_list_to_dict([variable])
    saveable_objects = []
    for name, op in names_to_saveables.items():
      for s in saveable_object_util.saveable_objects_for_op(op, name):
        saveable_objects.append(s)

    assert len(saveable_objects) == 1  # Should be only one variable.
  init_op = saveable_objects[0].restore([restore_op], restored_shapes=None)

  # pylint:disable=protected-access
  variable._initializer_op = init_op
  restore_op.set_shape(variable.shape)
  variable._initial_value = restore_op
  # pylint:enable=protected-access 
開發者ID:artyompal,項目名稱:tpu_models,代碼行數:42,代碼來源:checkpoint_utils.py


注:本文中的tensorflow.python.ops.io_ops.restore_v2方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。