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


Python variables.variables_initializer方法代碼示例

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


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

示例1: create_checkpoint_from_values

# 需要導入模塊: from tensorflow.python.ops import variables [as 別名]
# 或者: from tensorflow.python.ops.variables import variables_initializer [as 別名]
def create_checkpoint_from_values(self,
                                    var_names_to_values,
                                    checkpoint_dir,
                                    global_step=None):
    """Creates a checkpoint from a mapping of name to values in model_dir.

    Args:
      var_names_to_values: a map from variable names to values.
      checkpoint_dir: the directory where the checkpoint will be saved.
      global_step: the global step used to save the checkpoint.

    Returns:
      the model_path to the checkpoint.
    """
    var_list = []
    with session.Session('', graph=ops.Graph()) as sess:
      # Create a set of variables to save in the checkpoint.
      for var_name in var_names_to_values:
        var_value = var_names_to_values[var_name]
        var_list.append(variables_lib.VariableV1(var_value, name=var_name))
      saver = saver_lib.Saver(var_list)
      init_op = variables_lib.variables_initializer(var_list)
      sess.run(init_op)
      # Save the initialized values in the file at 'checkpoint_dir'
      return saver.save(sess, checkpoint_dir, global_step=global_step) 
開發者ID:google-research,項目名稱:tf-slim,代碼行數:27,代碼來源:variables_test.py

示例2: _initialize_variables

# 需要導入模塊: from tensorflow.python.ops import variables [as 別名]
# 或者: from tensorflow.python.ops.variables import variables_initializer [as 別名]
def _initialize_variables(session):
  """Utility to initialize uninitialized variables on the fly."""
  variables = variables_module.global_variables()
  candidate_vars = []
  for v in variables:
    if not getattr(v, '_keras_initialized', False):
      candidate_vars.append(v)
  # This step is expensive, so we only run it on variables not already
  # marked as initialized.
  is_initialized = session.run(
      [variables_module.is_variable_initialized(v) for v in candidate_vars])
  uninitialized_vars = []
  for flag, v in zip(is_initialized, candidate_vars):
    if not flag:
      uninitialized_vars.append(v)
    v._keras_initialized = True
  if uninitialized_vars:
    session.run(variables_module.variables_initializer(uninitialized_vars)) 
開發者ID:PacktPublishing,項目名稱:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代碼行數:20,代碼來源:backend.py

示例3: initialize_op

# 需要導入模塊: from tensorflow.python.ops import variables [as 別名]
# 或者: from tensorflow.python.ops.variables import variables_initializer [as 別名]
def initialize_op(self):
    """Returns an op for initializing tensorflow variables."""
    all_vars = self._row_factors + self._col_factors
    all_vars.extend([self._row_gramian, self._col_gramian])
    if self._row_weights is not None:
      assert self._col_weights is not None
      all_vars.extend(self._row_weights + self._col_weights)
    return variables.variables_initializer(all_vars) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:10,代碼來源:factorization_ops.py

示例4: _initialize_variables

# 需要導入模塊: from tensorflow.python.ops import variables [as 別名]
# 或者: from tensorflow.python.ops.variables import variables_initializer [as 別名]
def _initialize_variables():
  """Utility to initialize uninitialized variables on the fly.
  """
  variables = variables_module.global_variables()
  uninitialized_variables = []
  for v in variables:
    if not hasattr(v, '_keras_initialized') or not v._keras_initialized:
      uninitialized_variables.append(v)
      v._keras_initialized = True
  if uninitialized_variables:
    sess = get_session()
    sess.run(variables_module.variables_initializer(uninitialized_variables)) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:14,代碼來源:backend.py

示例5: test_local_variable

# 需要導入模塊: from tensorflow.python.ops import variables [as 別名]
# 或者: from tensorflow.python.ops.variables import variables_initializer [as 別名]
def test_local_variable(self):
    with self.cached_session() as sess:
      self.assertEqual([], variables_lib.local_variables())
      value0 = 42
      variables_lib2.local_variable(value0)
      value1 = 43
      variables_lib2.local_variable(value1)
      variables = variables_lib.local_variables()
      self.assertEqual(2, len(variables))
      self.assertRaises(errors_impl.OpError, sess.run, variables)
      variables_lib.variables_initializer(variables).run()
      self.assertAllEqual(set([value0, value1]), set(sess.run(variables))) 
開發者ID:google-research,項目名稱:tf-slim,代碼行數:14,代碼來源:variables_test.py

示例6: test_global_variable

# 需要導入模塊: from tensorflow.python.ops import variables [as 別名]
# 或者: from tensorflow.python.ops.variables import variables_initializer [as 別名]
def test_global_variable(self):
    with self.cached_session() as sess:
      self.assertEqual([], variables_lib.global_variables())
      value0 = 42
      variables_lib2.global_variable(value0)
      value1 = 43
      variables_lib2.global_variable(value1)
      variables = variables_lib.global_variables()
      self.assertEqual(2, len(variables))
      with self.assertRaises(errors_impl.FailedPreconditionError):
        sess.run(variables)
      variables_lib.variables_initializer(variables).run()
      self.assertAllEqual(set([value0, value1]), set(sess.run(variables))) 
開發者ID:google-research,項目名稱:tf-slim,代碼行數:15,代碼來源:variables_test.py

示例7: __init__

# 需要導入模塊: from tensorflow.python.ops import variables [as 別名]
# 或者: from tensorflow.python.ops.variables import variables_initializer [as 別名]
def __init__(self,
               var_list=None,
               init_uninitialized_variables=False,
               **kwargs):
    kwargs['restore_sequentially'] = False
    kwargs['builder'] = BaseSaverBuilder()
    super(OptimisticRestoreSaver, self).__init__(var_list=var_list, **kwargs)
    self.init_uninitialized_variables = init_uninitialized_variables
    if self.init_uninitialized_variables:
      self.uninit_vars_op = variables.report_uninitialized_variables(
          var_list=self._var_list)
      self.init_ops = dict((v.name, variables.variables_initializer([v]))
                           for v in self._var_list) 
開發者ID:google,項目名稱:active-qa,代碼行數:15,代碼來源:optimistic_restore_saver.py


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