Ejemplo n.º 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'))
Ejemplo n.º 2
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'))
Ejemplo n.º 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)
Ejemplo n.º 4
0
 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)
Ejemplo n.º 5
0
 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.assertEqual(len(beta), 1)
         self.assertEqual(len(gamma), 1)
         moving_vars = tf.get_collection('moving_vars')
         self.assertEqual(len(moving_vars), 2)
Ejemplo n.º 6
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)
Ejemplo n.º 7
0
 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')
Ejemplo n.º 8
0
 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')
Ejemplo n.º 9
0
 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, 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.get_collection('moving_vars')[0]
     moving_variance = tf.get_collection('moving_vars')[1]
     self.assertEquals(moving_mean.op.name, 'BatchNorm/moving_mean')
     self.assertEquals(moving_variance.op.name, 'BatchNorm/moving_variance')
Ejemplo n.º 10
0
 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.assertEqual(beta.op.name, 'BatchNorm/beta')
         self.assertEqual(gamma.op.name, 'BatchNorm/gamma')
         moving_mean = tf.moving_average_variables()[0]
         moving_variance = tf.moving_average_variables()[1]
         self.assertEqual(moving_mean.op.name, 'BatchNorm/moving_mean')
         self.assertEqual(moving_variance.op.name,
                          'BatchNorm/moving_variance')