Beispiel #1
0
 def testConvOutputKroneckerFactorInit(self):
     with tf.Graph().as_default():
         tf.set_random_seed(200)
         tensor = tf.ones((2, 3, 4, 5), name='a/b/c')
         factor = ff.ConvOutputKroneckerFactor(((tensor, ), ))
         factor.instantiate_cov_variables()
         self.assertEqual([5, 5], factor.cov.get_shape().as_list())
Beispiel #2
0
    def testMakeCovarianceUpdateOp(self):
        with tf.Graph().as_default(), self.test_session() as sess:
            tf.set_random_seed(200)
            tensor = np.arange(1, 17).reshape(2, 2, 2, 2).astype(np.float32)
            factor = ff.ConvOutputKroneckerFactor(((tf.constant(tensor), ), ))
            factor.instantiate_cov_variables()

            sess.run(tf.global_variables_initializer())
            new_cov = sess.run(factor.make_covariance_update_op(.5))
            self.assertAllClose([[43, 46.5], [46.5, 51.5]], new_cov)
Beispiel #3
0
 def testConvOutputKroneckerFactorInitFloat64(self):
     with tf.Graph().as_default():
         dtype = dtypes.float64_ref
         tf.set_random_seed(200)
         tensor = tf.ones((2, 3, 4, 5), dtype=dtype, name='a/b/c')
         factor = ff.ConvOutputKroneckerFactor(((tensor, ), ))
         factor.instantiate_cov_variables()
         cov = factor.cov
         self.assertEqual(cov.dtype, dtype)
         self.assertEqual([5, 5], cov.get_shape().as_list())
Beispiel #4
0
    def test3DConvolution(self):
        with tf.Graph().as_default():
            batch_size = 1
            width = 3
            out_channels = width**3

            factor = ff.ConvOutputKroneckerFactor(outputs_grads=([
                tf.random_uniform(
                    (batch_size, width, width, width, out_channels), seed=0)
            ], ))
            factor.instantiate_cov_variables()

            with self.test_session() as sess:
                sess.run(tf.global_variables_initializer())
                sess.run(factor.make_covariance_update_op(0.0))
                cov = sess.run(factor.cov)

            # Cov should be rank 3^3, as each spatial position donates a rank-1
            # update.
            self.assertMatrixRank(width**3, cov)