def __init__(self, gan, config, d_vars=None, g_vars=None, name="BaseTrainer"):
     self.current_step = 0
     self.g_vars = g_vars
     self.d_vars = d_vars
     self.train_hooks = []
     
     GANComponent.__init__(self, gan, config, name=name)
Beispiel #2
0
    def __init__(self,
                 config=None,
                 inputs=None,
                 device='/gpu:0',
                 ops_config=None,
                 ops_backend=TensorflowOps,
                 batch_size=None,
                 width=None,
                 height=None,
                 channels=None):
        """ Initialized a new GAN."""
        self.inputs = inputs
        self.device = device
        self.ops_backend = ops_backend
        self.ops_config = ops_config
        self.created = False
        self.components = []
        self._batch_size = batch_size
        self._width = width
        self._height = height
        self._channels = channels

        if config == None:
            config = hg.Configuration.default()

        # A GAN as a component has a parent of itself
        # gan.gan.gan.gan.gan.gan
        GANComponent.__init__(self, self, config)
Beispiel #3
0
 def __init__(self, gan, config, d_vars=None, g_vars=None, loss=None):
     GANComponent.__init__(self, gan, config)
     self.create_called = False
     self.current_step = 0
     self.g_vars = g_vars
     self.d_vars = d_vars
     self.loss = loss
Beispiel #4
0
    def __init__(self,
                 gan,
                 config,
                 d_vars=None,
                 g_vars=None,
                 loss=None,
                 name="BaseTrainer"):
        self.current_step = 0
        self.g_vars = g_vars
        self.d_vars = d_vars
        self.loss = loss
        self.d_shake = None
        self.g_shake = None
        self.train_hooks = []
        for hook_config in (config.hooks or []):
            hook_config = hc.lookup_functions(hook_config.copy())
            defn = {
                k: v
                for k, v in hook_config.items()
                if k in inspect.getargspec(hook_config['class']).args
            }
            defn['gan'] = gan
            defn['config'] = hook_config
            defn['trainer'] = self
            hook = hook_config["class"](**defn)
            losses = hook.losses()
            if losses[0] is not None:
                self.loss.sample[0] += losses[0]
            if losses[1] is not None:
                self.loss.sample[1] += losses[1]
            self.train_hooks.append(hook)

        GANComponent.__init__(self, gan, config, name=name)
Beispiel #5
0
 def __init__(self, gan, config, discriminator=None, generator=None):
     GANComponent.__init__(self, gan, config)
     self.metrics = {}
     self.sample = None
     self.ops = None
     self.discriminator = discriminator
     self.generator = generator
Beispiel #6
0
    def __init__(self,
                 config=None,
                 inputs=None,
                 device='/gpu:0',
                 ops_config=None,
                 ops_backend=TensorflowOps,
                 graph=None,
                 batch_size=None,
                 width=None,
                 height=None,
                 channels=None,
                 debug=None,
                 session=None,
                 name="hypergan"):
        """ Initialized a new GAN."""
        self.inputs = inputs
        self.device = device
        self.ops_backend = ops_backend
        self.ops_config = ops_config
        self.components = []
        self._batch_size = batch_size
        self._width = width
        self._height = height
        self._channels = channels
        self.debug = debug
        self.name = name
        self.session = session
        self.skip_connections = SkipConnections()
        self.destroy = False
        if graph is None:
            graph = tf.get_default_graph()
        self.graph = graph

        if config == None:
            config = hg.Configuration.default()

        if debug and not isinstance(self.session,
                                    tf_debug.LocalCLIDebugWrapperSession):
            self.session = tf_debug.LocalCLIDebugWrapperSession(self.session)
            self.session.add_tensor_filter("has_inf_or_nan",
                                           tf_debug.has_inf_or_nan)
        else:
            tfconfig = tf.ConfigProto(allow_soft_placement=True)
            #tfconfig = tf.ConfigProto(log_device_placement=True)
            tfconfig.gpu_options.allow_growth = True

            with tf.device(self.device):
                self.session = self.session or tf.Session(config=tfconfig,
                                                          graph=graph)

        self.global_step = tf.Variable(0, trainable=False, name='global_step')
        self.steps = tf.Variable(0, trainable=False, name='global_step')
        self.increment_step = tf.assign(self.steps, self.steps + 1)
        # A GAN as a component has a parent of itself
        # gan.gan.gan.gan.gan.gan
        GANComponent.__init__(self, self, config, name=self.name)
        self.ops.debug = debug
Beispiel #7
0
    def __init__(self,
                 gan,
                 config,
                 name="BaseGenerator",
                 input=None,
                 reuse=False):
        self.input = input
        self.name = name

        GANComponent.__init__(self, gan, config, name=name, reuse=reuse)
 def __init__(self,
              gan,
              config,
              name=None,
              input=None,
              reuse=None,
              features=None):
     self.input = input
     self.name = name
     self.features = features
     GANComponent.__init__(self, gan, config, name=name, reuse=reuse)
Beispiel #9
0
 def __init__(self, gan, config, discriminator=None, generator=None, x=None, split=2, d_fake=None, d_real=None, reuse=False, name="BaseLoss"):
     self.sample = None
     self.ops = None
     self.reuse=reuse
     self.x = x
     self.d_fake = d_fake
     self.d_real = d_real
     self.discriminator = discriminator or gan.discriminator
     self.generator = generator
     self.split = split
     GANComponent.__init__(self, gan, config, name=name)
Beispiel #10
0
    def __init__(self,
                 gan,
                 config,
                 d_vars=None,
                 g_vars=None,
                 name="BaseTrainer"):
        self.current_step = 0
        self.g_vars = g_vars
        self.d_vars = d_vars
        self.train_hooks = []

        GANComponent.__init__(self, gan, config, name=name)
 def __init__(self,
              gan,
              config,
              name=None,
              input=None,
              reuse=None,
              features=None,
              weights=None,
              biases=None):
     GANComponent.__init__(self, gan, config)
     self.input = input
     self.name = name
     self.features = features
Beispiel #12
0
 def __init__(self,
              gan,
              config,
              name=None,
              input=None,
              reuse=None,
              x=None,
              g=None):
     self.input = input
     self.name = name
     self.x = x
     self.g = g
     GANComponent.__init__(self, gan, config, name=name, reuse=reuse)
Beispiel #13
0
    def __init__(self, config=None, inputs=None, device='/gpu:0', ops_config=None, ops_backend=TensorflowOps, graph=None,
            batch_size=None, width=None, height=None, channels=None, debug=None, session=None, name="hypergan"):
        """ Initialized a new GAN."""
        self.inputs = inputs
        self.device = device
        self.ops_backend = ops_backend
        self.ops_config = ops_config
        self.components = []
        self._batch_size = batch_size
        self._width = width
        self._height = height
        self._channels = channels
        self.debug = debug
        self.name = name
        self.session = session
        self.skip_connections = SkipConnections()
        self.destroy = False
        if graph is None:
            graph = tf.get_default_graph()
        self.graph = graph

        if config == None:
            config = hg.Configuration.default()

        if debug and not isinstance(self.session, tf_debug.LocalCLIDebugWrapperSession):
            self.session = tf_debug.LocalCLIDebugWrapperSession(self.session)
            self.session.add_tensor_filter("has_inf_or_nan", tf_debug.has_inf_or_nan)
        else:
            tfconfig = tf.ConfigProto(allow_soft_placement=True)
            #tfconfig = tf.ConfigProto(log_device_placement=True)
            tfconfig.gpu_options.allow_growth=True

            with tf.device(self.device):
                self.session = self.session or tf.Session(config=tfconfig, graph=graph)

        self.global_step = tf.Variable(0, trainable=False, name='global_step')
        self.steps = tf.Variable(0, trainable=False, name='global_step')
        self.increment_step = tf.assign(self.steps, self.steps+1)
        # A GAN as a component has a parent of itself
        # gan.gan.gan.gan.gan.gan
        GANComponent.__init__(self, self, config, name=self.name)
        self.ops.debug = debug
Beispiel #14
0
 def __init__(self,
              gan,
              config,
              discriminator=None,
              generator=None,
              x=None,
              split=2,
              d_fake=None,
              d_real=None,
              reuse=False,
              name="BaseLoss"):
     self.sample = None
     self.ops = None
     self.reuse = reuse
     self.x = x
     self.d_fake = d_fake
     self.d_real = d_real
     self.discriminator = discriminator
     self.generator = generator
     self.split = split
     GANComponent.__init__(self, gan, config, name=name)
Beispiel #15
0
    def __init__(self, gan, config, g=None, x=None, name=None, input=None, reuse=None, features=[], skip_connections=[]):
        self.x = x
        self.g = g

        GANComponent.__init__(self, gan, config, name=name, reuse=reuse)
Beispiel #16
0
    def __init__(self, gan, config, trainable_gan):
        self.current_step = 0
        self.train_hooks = gan.hooks
        self.trainable_gan = trainable_gan

        GANComponent.__init__(self, gan, config)
Beispiel #17
0
 def __init__(self, gan, config, input=None):
     GANComponent.__init__(self, gan, config)
     self.input = input
 def __init__(self, gan, config, name=None, input=None, reuse=None, features=None):
     self.input = input
     self.name = name
     self.features = features
     GANComponent.__init__(self, gan, config, name=name, reuse=reuse)
    def __init__(self, gan, config, name="BaseGenerator", input=None, reuse=False):
        self.input = input
        self.name = name

        GANComponent.__init__(self, gan, config, name=name, reuse=reuse)