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


Python tensorflow.moving_average_variables方法代碼示例

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


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

示例1: batch_norm

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import moving_average_variables [as 別名]
def batch_norm(x, train, name, decay=0.99, epsilon=1e-5):
    shape = x.get_shape().as_list()
    with tf.variable_scope(name):
        beta = tf.get_variable('beta', [shape[-1]], initializer=tf.constant_initializer(0.))
        gamma = tf.get_variable('gamma', [shape[-1]], initializer=tf.random_normal_initializer(1., 0.02))
        pop_mean = tf.get_variable('pop_mean', [shape[-1]], initializer=tf.constant_initializer(0.), trainable=False)
        pop_var = tf.get_variable('pop_var', [shape[-1]], initializer=tf.constant_initializer(1.), trainable=False)

        if pop_mean not in tf.moving_average_variables():
            tf.add_to_collection(tf.GraphKeys.MOVING_AVERAGE_VARIABLES, pop_mean)
            tf.add_to_collection(tf.GraphKeys.MOVING_AVERAGE_VARIABLES, pop_var)

        def func1():
            # Execute at training time
            batch_mean, batch_var = tf.nn.moments(x, range(len(shape) - 1))
            update_mean = tf.assign_sub(pop_mean, (1 - decay)*(pop_mean - batch_mean))
            update_var = tf.assign_sub(pop_var, (1 - decay)*(pop_var - batch_var))
            with tf.control_dependencies([update_mean, update_var]):
                return tf.nn.batch_normalization(x, batch_mean, batch_var, beta, gamma, epsilon)

        def func2():
            # Execute at test time
            return tf.nn.batch_normalization(x, pop_mean, pop_var, beta, gamma, epsilon)

        return tf.cond(train, func1, func2) 
開發者ID:maxorange,項目名稱:pix2vox,代碼行數:27,代碼來源:ops.py

示例2: testCreateVariables

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import moving_average_variables [as 別名]
def testCreateVariables(self):
    height, width = 3, 3
    with self.test_session():
      images = tf.random_uniform((5, height, width, 3), seed=1)
      ops.batch_norm(images)
      beta = variables.get_variables_by_name('beta')[0]
      self.assertEquals(beta.op.name, 'BatchNorm/beta')
      gamma = variables.get_variables_by_name('gamma')
      self.assertEquals(gamma, [])
      moving_mean = tf.moving_average_variables()[0]
      moving_variance = tf.moving_average_variables()[1]
      self.assertEquals(moving_mean.op.name, 'BatchNorm/moving_mean')
      self.assertEquals(moving_variance.op.name, 'BatchNorm/moving_variance') 
開發者ID:ringringyi,項目名稱:DOTA_models,代碼行數:15,代碼來源:ops_test.py

示例3: testCreateVariablesWithScale

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import moving_average_variables [as 別名]
def testCreateVariablesWithScale(self):
    height, width = 3, 3
    with self.test_session():
      images = tf.random_uniform((5, height, width, 3), seed=1)
      ops.batch_norm(images, scale=True)
      beta = variables.get_variables_by_name('beta')[0]
      gamma = variables.get_variables_by_name('gamma')[0]
      self.assertEquals(beta.op.name, 'BatchNorm/beta')
      self.assertEquals(gamma.op.name, 'BatchNorm/gamma')
      moving_mean = tf.moving_average_variables()[0]
      moving_variance = tf.moving_average_variables()[1]
      self.assertEquals(moving_mean.op.name, 'BatchNorm/moving_mean')
      self.assertEquals(moving_variance.op.name, 'BatchNorm/moving_variance') 
開發者ID:ringringyi,項目名稱:DOTA_models,代碼行數:15,代碼來源:ops_test.py

示例4: testCreateVariablesWithoutCenterWithScale

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import moving_average_variables [as 別名]
def testCreateVariablesWithoutCenterWithScale(self):
    height, width = 3, 3
    with self.test_session():
      images = tf.random_uniform((5, height, width, 3), seed=1)
      ops.batch_norm(images, center=False, scale=True)
      beta = variables.get_variables_by_name('beta')
      self.assertEquals(beta, [])
      gamma = variables.get_variables_by_name('gamma')[0]
      self.assertEquals(gamma.op.name, 'BatchNorm/gamma')
      moving_mean = tf.moving_average_variables()[0]
      moving_variance = tf.moving_average_variables()[1]
      self.assertEquals(moving_mean.op.name, 'BatchNorm/moving_mean')
      self.assertEquals(moving_variance.op.name, 'BatchNorm/moving_variance') 
開發者ID:ringringyi,項目名稱:DOTA_models,代碼行數:15,代碼來源:ops_test.py

示例5: testCreateVariablesWithoutCenterWithoutScale

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import moving_average_variables [as 別名]
def testCreateVariablesWithoutCenterWithoutScale(self):
    height, width = 3, 3
    with self.test_session():
      images = tf.random_uniform((5, height, width, 3), seed=1)
      ops.batch_norm(images, center=False, scale=False)
      beta = variables.get_variables_by_name('beta')
      self.assertEquals(beta, [])
      gamma = variables.get_variables_by_name('gamma')
      self.assertEquals(gamma, [])
      moving_mean = tf.moving_average_variables()[0]
      moving_variance = tf.moving_average_variables()[1]
      self.assertEquals(moving_mean.op.name, 'BatchNorm/moving_mean')
      self.assertEquals(moving_variance.op.name, 'BatchNorm/moving_variance') 
開發者ID:ringringyi,項目名稱:DOTA_models,代碼行數:15,代碼來源:ops_test.py

示例6: testMovingAverageVariables

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import moving_average_variables [as 別名]
def testMovingAverageVariables(self):
    height, width = 3, 3
    with self.test_session():
      images = tf.random_uniform((5, height, width, 3), seed=1)
      ops.batch_norm(images, scale=True)
      moving_mean = tf.moving_average_variables()[0]
      moving_variance = tf.moving_average_variables()[1]
      self.assertEquals(moving_mean.op.name, 'BatchNorm/moving_mean')
      self.assertEquals(moving_variance.op.name, 'BatchNorm/moving_variance') 
開發者ID:ringringyi,項目名稱:DOTA_models,代碼行數:11,代碼來源:ops_test.py

示例7: begin

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import moving_average_variables [as 別名]
def begin(self):
		""" Create restoring operations before the graph been finalized. """
		ema_variables = tf.moving_average_variables()
		self._restore_ops = [tf.assign(x, self._ema.average(x)) for x in ema_variables]
		print("==get restore ops==") 
開發者ID:yyht,項目名稱:BERT,代碼行數:7,代碼來源:model_io_utils.py


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