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


Python tensorflow.is_variable_initialized方法代碼示例

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


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

示例1: init_uninited_vars

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import is_variable_initialized [as 別名]
def init_uninited_vars(vars=None):
    if vars is None: vars = tf.global_variables()
    test_vars = []; test_ops = []
    with tf.control_dependencies(None): # ignore surrounding control_dependencies
        for var in vars:
            assert is_tf_expression(var)
            try:
                tf.get_default_graph().get_tensor_by_name(var.name.replace(':0', '/IsVariableInitialized:0'))
            except KeyError:
                # Op does not exist => variable may be uninitialized.
                test_vars.append(var)
                with absolute_name_scope(var.name.split(':')[0]):
                    test_ops.append(tf.is_variable_initialized(var))
    init_vars = [var for var, inited in zip(test_vars, run(test_ops)) if not inited]
    run([var.initializer for var in init_vars])

#----------------------------------------------------------------------------
# Set the values of given tf.Variables.
# Equivalent to the following, but more efficient and does not bloat the tf graph:
#   tfutil.run([tf.assign(var, value) for var, value in var_to_value_dict.items()] 
開發者ID:zalandoresearch,項目名稱:disentangling_conditional_gans,代碼行數:22,代碼來源:tfutil.py

示例2: _create_autosummary_var

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import is_variable_initialized [as 別名]
def _create_autosummary_var(name, value_expr):
    assert not _autosummary_finalized
    v = tf.cast(value_expr, tf.float32)
    if v.shape.ndims is 0:
        v = [v, np.float32(1.0)]
    elif v.shape.ndims is 1:
        v = [tf.reduce_sum(v), tf.cast(tf.shape(v)[0], tf.float32)]
    else:
        v = [tf.reduce_sum(v), tf.reduce_prod(tf.cast(tf.shape(v), tf.float32))]
    v = tf.cond(tf.is_finite(v[0]), lambda: tf.stack(v), lambda: tf.zeros(2))
    with tf.control_dependencies(None):
        var = tf.Variable(tf.zeros(2)) # [numerator, denominator]
    update_op = tf.cond(tf.is_variable_initialized(var), lambda: tf.assign_add(var, v), lambda: tf.assign(var, v))
    if name in _autosummary_vars:
        _autosummary_vars[name].append(var)
    else:
        _autosummary_vars[name] = [var]
    return update_op

#----------------------------------------------------------------------------
# Call filewriter.add_summary() with all summaries in the default graph,
# automatically finalizing and merging them on the first call. 
開發者ID:zalandoresearch,項目名稱:disentangling_conditional_gans,代碼行數:24,代碼來源:tfutil.py

示例3: initialize_uninitialized_global_variables

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import is_variable_initialized [as 別名]
def initialize_uninitialized_global_variables(sess):
    """
    Only initializes the variables of a TensorFlow session that were not
    already initialized.
    :param sess: the TensorFlow session
    :return:
    """
    # List all global variables
    global_vars = tf.global_variables()

    # Find initialized status for all variables
    is_var_init = [tf.is_variable_initialized(var) for var in global_vars]
    is_initialized = sess.run(is_var_init)

    # List all variables that were not initialized previously
    not_initialized_vars = [var for (var, init) in
                            zip(global_vars, is_initialized) if not init]

    # Initialize all uninitialized variables found, if any
    if len(not_initialized_vars):
        sess.run(tf.variables_initializer(not_initialized_vars)) 
開發者ID:StephanZheng,項目名稱:neural-fingerprinting,代碼行數:23,代碼來源:utils_tf.py

示例4: testPrepareSessionDidNotInitLocalVariable

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import is_variable_initialized [as 別名]
def testPrepareSessionDidNotInitLocalVariable(self):
    with tf.Graph().as_default():
      v = tf.Variable(1, name="v")
      w = tf.Variable(
          v,
          trainable=False,
          collections=[tf.GraphKeys.LOCAL_VARIABLES],
          name="w")
      with self.test_session():
        self.assertEqual(False, tf.is_variable_initialized(v).eval())
        self.assertEqual(False, tf.is_variable_initialized(w).eval())
      sm2 = tf.train.SessionManager(
          ready_op=tf.report_uninitialized_variables())
      with self.assertRaisesRegexp(RuntimeError,
                                   "Init operations did not make model ready"):
        sm2.prepare_session("", init_op=v.initializer) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:18,代碼來源:session_manager_test.py

示例5: testPrepareSessionWithReadyNotReadyForLocal

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import is_variable_initialized [as 別名]
def testPrepareSessionWithReadyNotReadyForLocal(self):
    with tf.Graph().as_default():
      v = tf.Variable(1, name="v")
      w = tf.Variable(
          v,
          trainable=False,
          collections=[tf.GraphKeys.LOCAL_VARIABLES],
          name="w")
      with self.test_session():
        self.assertEqual(False, tf.is_variable_initialized(v).eval())
        self.assertEqual(False, tf.is_variable_initialized(w).eval())
      sm2 = tf.train.SessionManager(
          ready_op=tf.report_uninitialized_variables(),
          ready_for_local_init_op=tf.report_uninitialized_variables(
              tf.all_variables()),
          local_init_op=w.initializer)
      with self.assertRaisesRegexp(
          RuntimeError,
          "Init operations did not make model ready for local_init"):
        sm2.prepare_session("", init_op=None) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:22,代碼來源:session_manager_test.py

示例6: init_and_reload

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import is_variable_initialized [as 別名]
def init_and_reload(self):

         ##########
         # this function is only used for the gan training with reload
         ##########

         params = [param for param in tf.trainable_variables() if 'generate' in param.name]
         #params = [param for param in tf.all_variables()]
         if not self.sess.run(tf.is_variable_initialized(params[0])):
            #init_op = tf.initialize_variables(params)
            init_op = tf.global_variables_initializer()  ## this is important here to initialize_all_variables()
            self.sess.run(init_op)

         saver = tf.train.Saver(params)
         self.saver=saver
         
         if self.gen_reload:                                     ##here must be true
           print('reloading params from %s '% self.saveto)
           self.saver.restore(self.sess, './'+self.saveto)
           print('reloading params done')
         else:
           print('error, reload must be true!!') 
開發者ID:ZhenYangIACAS,項目名稱:NMT_GAN,代碼行數:24,代碼來源:nmt_generator.py

示例7: initialize_uninitialized

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import is_variable_initialized [as 別名]
def initialize_uninitialized(sess):
    """
    Function to initialize only uninitialized variables in a session graph

    Parameters
    ----------
    sess : tf.Session()

    """

    global_vars = tf.global_variables()
    is_not_initialized = sess.run(
        [tf.is_variable_initialized(var) for var in global_vars])

    not_initialized_vars = [v for (v, f) in zip(
        global_vars, is_not_initialized) if not f]

    if not_initialized_vars:
        sess.run(tf.variables_initializer(not_initialized_vars)) 
開發者ID:delira-dev,項目名稱:delira,代碼行數:21,代碼來源:utils.py

示例8: initialize_uninitialized_variables

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import is_variable_initialized [as 別名]
def initialize_uninitialized_variables(sess):
    """
    Only initialize the weights that have not yet been initialized by other
    means, such as importing a metagraph and a checkpoint. It's useful when
    extending an existing model.
    """
    uninit_vars    = []
    uninit_tensors = []
    for var in tf.global_variables():
        uninit_vars.append(var)
        uninit_tensors.append(tf.is_variable_initialized(var))
    uninit_bools = sess.run(uninit_tensors)
    uninit = zip(uninit_bools, uninit_vars)
    uninit = [var for init, var in uninit if not init]
    sess.run(tf.variables_initializer(uninit))

#------------------------------------------------------------------------------- 
開發者ID:ljanyst,項目名稱:ssd-tensorflow,代碼行數:19,代碼來源:utils.py

示例9: initialize_uninitialized

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import is_variable_initialized [as 別名]
def initialize_uninitialized(self, ):
        """Only initializes the variables of a TensorFlow session that were not
        already initialized.
        """
        # List all global variables.
        sess = self.sess
        global_vars = tf.global_variables()

        # Find initialized status for all variables.
        is_var_init = [tf.is_variable_initialized(var) for var in global_vars]
        is_initialized = sess.run(is_var_init)

        # List all variables that were not previously initialized.
        not_initialized_vars = [var for (var, init) in
                                zip(global_vars, is_initialized) if not init]
        for v in not_initialized_vars:
            print('[!] not init: {}'.format(v.name))
        # Initialize all uninitialized variables found, if any.
        if len(not_initialized_vars):
            sess.run(tf.variables_initializer(not_initialized_vars)) 
開發者ID:kabkabm,項目名稱:defensegan,代碼行數:22,代碼來源:base_model.py

示例10: initialize_uninitialized_variables

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import is_variable_initialized [as 別名]
def initialize_uninitialized_variables(variables=None):
    if variables is None:
        variables = tf.global_variables()

    if not variables:
        return

    session = tensorflow_session()
    is_not_initialized = session.run([
        tf.is_variable_initialized(var) for var in variables])

    not_initialized_vars = [
        v for (v, f) in zip(variables, is_not_initialized) if not f]

    if len(not_initialized_vars):
        session.run(tf.variables_initializer(not_initialized_vars)) 
開發者ID:itdxer,項目名稱:neupy,代碼行數:18,代碼來源:tf_utils.py

示例11: initialize_uninitialized_global_variables

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import is_variable_initialized [as 別名]
def initialize_uninitialized_global_variables(sess):
  """
  Only initializes the variables of a TensorFlow session that were not
  already initialized.
  :param sess: the TensorFlow session
  :return:
  """
  # List all global variables
  global_vars = tf.global_variables()

  # Find initialized status for all variables
  is_var_init = [tf.is_variable_initialized(var) for var in global_vars]
  is_initialized = sess.run(is_var_init)

  # List all variables that were not initialized previously
  not_initialized_vars = [var for (var, init) in
                          zip(global_vars, is_initialized) if not init]

  # Initialize all uninitialized variables found, if any
  if len(not_initialized_vars):
    sess.run(tf.variables_initializer(not_initialized_vars)) 
開發者ID:tensorflow,項目名稱:cleverhans,代碼行數:23,代碼來源:utils_tf.py

示例12: initialize_uninitialized

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import is_variable_initialized [as 別名]
def initialize_uninitialized(sess):
    global_vars = tf.global_variables()
    is_not_initialized = sess.run([tf.is_variable_initialized(var) for var in global_vars])
    not_initialized_vars = [v for (v, f) in zip(global_vars, is_not_initialized) if not f]

    if len(not_initialized_vars):
        sess.run(tf.variables_initializer(not_initialized_vars)) 
開發者ID:eth-nn-physics,項目名稱:nn_physical_concepts,代碼行數:9,代碼來源:model.py

示例13: init_uninitialized_vars

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import is_variable_initialized [as 別名]
def init_uninitialized_vars(target_vars: List[tf.Variable] = None) -> None:
    """Initialize all tf.Variables that have not already been initialized.

    Equivalent to the following, but more efficient and does not bloat the tf graph:
    tf.variables_initializer(tf.report_uninitialized_variables()).run()
    """
    assert_tf_initialized()
    if target_vars is None:
        target_vars = tf.global_variables()

    test_vars = []
    test_ops = []

    with tf.control_dependencies(None):  # ignore surrounding control_dependencies
        for var in target_vars:
            assert is_tf_expression(var)

            try:
                tf.get_default_graph().get_tensor_by_name(var.name.replace(":0", "/IsVariableInitialized:0"))
            except KeyError:
                # Op does not exist => variable may be uninitialized.
                test_vars.append(var)

                with absolute_name_scope(var.name.split(":")[0]):
                    test_ops.append(tf.is_variable_initialized(var))

    init_vars = [var for var, inited in zip(test_vars, run(test_ops)) if not inited]
    run([var.initializer for var in init_vars]) 
開發者ID:produvia,項目名稱:ai-platform,代碼行數:30,代碼來源:tfutil.py

示例14: initialize_uninitialized

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import is_variable_initialized [as 別名]
def initialize_uninitialized(sess):
  global_vars = tf.global_variables()
  is_not_initialized = sess.run([tf.is_variable_initialized(var) for var in global_vars])
  not_initialized_vars = [v for (v,f) in zip(global_vars, is_not_initialized) if not f]

  print [str(i.name) for i in not_initialized_vars] 
開發者ID:LeeDoYup,項目名稱:AnoGAN-tf,代碼行數:8,代碼來源:utils.py

示例15: testIsVariableInitialized

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import is_variable_initialized [as 別名]
def testIsVariableInitialized(self):
    for use_gpu in [True, False]:
      with self.test_session(use_gpu=use_gpu):
        v0 = state_ops.variable_op([1, 2], tf.float32)
        self.assertEqual(False, tf.is_variable_initialized(v0).eval())
        tf.assign(v0, [[2.0, 3.0]]).eval()
        self.assertEqual(True, tf.is_variable_initialized(v0).eval()) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:9,代碼來源:variable_ops_test.py


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