本文整理匯總了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)
示例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)
示例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))
示例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)))
示例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)))
示例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)