当前位置: 首页>>代码示例>>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;未经允许,请勿转载。