Пример #1
0
from __future__ import print_function

# Dependency imports
import numpy as np
import numpy.random as npr

import tensorflow as tf

from tensorflow.python.framework import dtypes
from kfac.python.ops import fisher_blocks as fb
from kfac.python.ops import fisher_factors as ff

# We need to set these constants since the numerical values used in the tests
# were chosen when these used to be the defaults.
ff.set_global_constants(init_covariances_at_zero=False,
                        zero_debias=False,
                        init_inverses_at_zero=False,
                        max_num_patches_per_dimension=1.0)


def make_damping_func(damping):
    return fb._package_func(lambda: damping, damping)


class FisherFactorTestingDummy(ff.FisherFactor):
    """Dummy class to test the non-abstract methods on ff.FisherFactor."""
    @property
    def _var_scope(self):
        return 'dummy/a_b_c'

    @property
    def _cov_shape(self):
Пример #2
0
from __future__ import print_function

# Dependency imports
import numpy as np
import tensorflow as tf

from kfac.python.ops import fisher_blocks as fb
from kfac.python.ops import fisher_factors as ff
from kfac.python.ops import layer_collection as lc
from kfac.python.ops import linear_operator as lo
from kfac.python.ops import utils

# We need to set these constants since the numerical values used in the tests
# were chosen when these used to be the defaults.
ff.set_global_constants(init_covariances_at_zero=False,
                        zero_debias=False,
                        init_inverses_at_zero=False)


def _make_psd(dim):
  """Constructs a PSD matrix of the given dimension."""
  mat = np.ones((dim, dim), dtype=np.float32)
  mat[np.arange(dim), np.arange(dim)] = 2. + np.arange(dim)
  return tf.constant(mat)


class UtilsTest(tf.test.TestCase):

  def testComputePiTracenorm(self):
    with tf.Graph().as_default(), self.test_session() as sess:
      tf.set_random_seed(200)
Пример #3
0
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

# Dependency imports
import numpy as np
import tensorflow as tf

from kfac.python.ops import estimator
from kfac.python.ops import fisher_factors as ff
from kfac.python.ops import layer_collection as lc
from kfac.python.ops import utils

# We need to set these constants since the numerical values used in the tests
# were chosen when these used to be the defaults.
ff.set_global_constants(zero_debias=False)

_ALL_ESTIMATION_MODES = ["gradients", "empirical", "curvature_prop", "exact"]


class EstimatorTest(tf.test.TestCase):
    def setUp(self):
        self._graph = tf.Graph()
        with self._graph.as_default():
            self.layer_collection = lc.LayerCollection()

            self.inputs = tf.random_normal((2, 2), dtype=tf.float32)
            self.weights = tf.get_variable("w", shape=(2, 2), dtype=tf.float32)
            self.bias = tf.get_variable("b",
                                        initializer=tf.zeros_initializer(),
                                        shape=(2, 1))