Example #1
0
 def testGetVariableGivenNameScoped(self):
     with self.test_session():
         with tf.variable_scope('A'):
             a = variables.variable('a', [5])
             b = variables.variable('b', [5])
             self.assertEquals([a], variables.get_variables_by_name('a'))
             self.assertEquals([b], variables.get_variables_by_name('b'))
 def testReuseVariables(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, scope='bn')
         ops.batch_norm(images, scale=True, scope='bn', reuse=True)
         beta = variables.get_variables_by_name('beta')
         gamma = variables.get_variables_by_name('gamma')
         self.assertEquals(len(beta), 1)
         self.assertEquals(len(gamma), 1)
         moving_vars = tf.get_collection('moving_vars')
         self.assertEquals(len(moving_vars), 2)
Example #3
0
    def testGetVariablesByNameReturnsByValueWithoutScope(self):
        with self.test_session():
            a = variables.variable('a', [5])
            matched_variables = variables.get_variables_by_name('a')

            # If variables.get_variables_by_name returns the list by reference, the
            # following append should persist, and be returned, in subsequent calls
            # to variables.get_variables_by_name('a').
            matched_variables.append(4)

            matched_variables = variables.get_variables_by_name('a')
            self.assertEquals([a], matched_variables)
 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')