예제 #1
0
 def test_generate_name(self):
     with self.test_session():
         ops = TensorflowOps()
         ops.describe("generator")
         self.assertEqual(ops.generate_name(), "generator_1")
         self.assertEqual(ops.generate_name(), "generator_2")
         self.assertEqual(ops.generate_name("custom"), "custom")
         self.assertEqual(ops.generate_name(), "generator_3")
예제 #2
0
def gan_factory(*args, **kw_args):
    if 'config' in kw_args:
        config = kw_args['config']
    elif len(args) > 0:
        config = args[0]
    else:
        config = None
    if config and 'class' in config:
        return TensorflowOps.lookup_function(None, config['class'])(*args,
                                                                    **kw_args)
    else:
        return StandardGAN(*args, **kw_args)
예제 #3
0
 def test_generate_name(self):
     with self.test_session():
         ops = TensorflowOps()
         ops.describe("generator")
         self.assertEqual(ops.generate_name(), "generator_1")
         self.assertEqual(ops.generate_name(), "generator_2")
         self.assertEqual(ops.generate_name("custom"), "custom")
         self.assertEqual(ops.generate_name(), "generator_3")
예제 #4
0
 def test_variable_constructor(self):
     with self.test_session():
         ops = TensorflowOps()
         self.assertEqual(len(ops.weights), 0)
         self.assertEqual(len(ops.biases), 0)
         self.assertEqual(len(ops.variables()), 0)
예제 #5
0
 def test_generate_scope(self):
     with self.test_session():
         ops = TensorflowOps()
         self.assertEqual(ops.generate_scope(), "1")
         self.assertEqual(ops.generate_scope(), "2")
예제 #6
0
 def test_get_bias(self):
     with self.test_session():
         ops = TensorflowOps({'dtype': 'float32'})
         ops.get_bias([1, 1])
         self.assertTrue('float32' in str(ops.biases[0].dtype))
         self.assertEqual(ops.shape(ops.biases[0]), [1, 1])
예제 #7
0
import tensorflow as tf
import hypergan as hg
from hypergan.ops.tensorflow.ops import TensorflowOps

from unittest.mock import MagicMock

ops = TensorflowOps()
tanh_str = "function:tensorflow.python.ops.math_ops.tanh"


class OpsTest(tf.test.TestCase):
    def test_lookup_activations(self):
        x = tf.constant(-1.0, shape=[2, 2])
        with self.test_session():
            activations = ['relu', 'prelu', 'selu', 'crelu']
            for activation in activations:
                activation = ops.lookup(activation)(x)

                tf.get_default_session().run(tf.global_variables_initializer())

                self.assertNotEqual(x.eval()[0][0], activation.eval()[0][0])

    def test_lookup_function(self):
        with self.test_session():
            self.assertEqual(ops.lookup_function(tanh_str), tf.nn.tanh)

    def test_lookup_class(self):
        with self.test_session():
            self.assertEqual(ops.lookup_class('class:hypergan.GAN'), hg.GAN)

    def test_lookup(self):
예제 #8
0
 def test_get_weight(self):
     with self.test_session():
         ops = TensorflowOps({'dtype':'float32'})
         ops.get_weight([1,1])
         self.assertTrue('float32' in str(ops.weights[0].dtype))
         self.assertEqual(ops.shape(ops.weights[0]), [1, 1])
예제 #9
0
 def test_variable_constructor(self):
     with self.test_session():
         ops = TensorflowOps()
         self.assertEqual(len(ops.weights), 0)
         self.assertEqual(len(ops.biases), 0)
         self.assertEqual(len(ops.variables()), 0)
예제 #10
0
 def test_generate_scope(self):
     with self.test_session():
         ops = TensorflowOps()
         self.assertEqual(ops.generate_scope(), "1")
         self.assertEqual(ops.generate_scope(), "2")