<commit_before>import tensorflow as tf

class DCGAN:
    def __init__(self,
                 batch_size=128, f_size=4, z_dim=100,
                 gdepth1=1024, gdepth2=512, gdepth3=256, gdepth4=128,
                 ddepth1=64,   ddepth2=128, ddepth3=256, ddepth4=512):
        self.batch_size = batch_size
        self.f_size = f_size
        self.z_dim = z_dim
        self.g = self.__generator(gdepth1, gdepth2, gdepth3, gdepth4)
        self.d = self.__discriminator(ddepth1, ddepth2, ddepth3, ddepth4)
        self.z = tf.random_uniform([self.batch_size, self.z_dim], minval=-1.0, maxval=1.0)

    def __generator(self, depth1, depth2, depth3, depth4):
        reuse = False
        def model(inputs):
            nonlocal reuse
            depths = [depth1, depth2, depth3, depth4, 3]
            i_depth = depths[0:4]
            o_depth = depths[1:5]
            with tf.variable_scope('g', reuse=reuse):
                # reshape from inputs
                with tf.variable_scope('reshape'):
                    fc = tf.contrib.layers.fully_connected(inputs, i_depth[0] * self.f_size * self.f_size, normalizer_fn=tf.contrib.layers.batch_norm)
                    out = tf.reshape(fc, [-1, self.f_size, self.f_size, i_depth[0]])
                # deconvolution (transpose of convolution) layers
                for i in range(4):
                    with tf.variable_scope('conv%d' % (i + 1)):
                        activation_fn = tf.nn.relu if i < 3 else None
                        normalizer_fn = tf.contrib.layers.batch_norm if i < 3 else None
                        out = tf.contrib.layers.conv2d_transpose(out, o_depth[i], [5, 5], stride=2, activation_fn=activation_fn, normalizer_fn=normalizer_fn)
            reuse = True
            return tf.nn.tanh(out)
        return model

    def __discriminator(self, depth1, depth2, depth3, depth4):
        reuse = False
        def model(inputs):
            nonlocal reuse
            depths = [3, depth1, depth2, depth3, depth4]
            i_depth = depths[0:4]
            o_depth = depths[1:5]
            out = []
            with tf.variable_scope('d', reuse=reuse):
                outputs = inputs
                # convolution layer
                for i in range(4):
                    with tf.variable_scope('conv%d' % i):
                        c = tf.contrib.layers.conv2d(outputs, o_depth[i], [5, 5], stride=2, activation_fn=None, normalizer_fn=tf.contrib.layers.batch_norm)
                        outputs = tf.maximum(0.2 * c, c)
                        out.append(outputs)
                # reshepe and fully connect to 2 classes
                with tf.variable_scope('classify'):
                    dim = 1<commit_msg>update discriminator<commit_after>import tensorflow as tf

class DCGAN:
    def __init__(self,
                 batch_size=128, f_size=4, z_dim=100,
                 gdepth1=1024, gdepth2=512, gdepth3=256, gdepth4=128,
                 ddepth1=64,   ddepth2=128, ddepth3=256, ddepth4=512):
        self.batch_size = batch_size
        self.f_size = f_size
        self.z_dim = z_dim
        self.g = self.__generator(gdepth1, gdepth2, gdepth3, gdepth4)
        self.d = self.__discriminator(ddepth1, ddepth2, ddepth3, ddepth4)
        self.z = tf.random_uniform([self.batch_size, self.z_dim], minval=-1.0, maxval=1.0)

    def __generator(self, depth1, depth2, depth3, depth4):
        reuse = False
        def model(inputs):
            nonlocal reuse
            depths = [depth1, depth2, depth3, depth4, 3]
            i_depth = depths[0:4]
            o_depth = depths[1:5]
            with tf.variable_scope('g', reuse=reuse):
                # reshape from inputs
                with tf.variable_scope('reshape'):
                    fc = tf.contrib.layers.fully_connected(inputs, i_depth[0] * self.f_size * self.f_size, normalizer_fn=tf.contrib.layers.batch_norm)
                    out = tf.reshape(fc, [-1, self.f_size, self.f_size, i_depth[0]])
                # deconvolution (transpose of convolution) layers
                for i in range(4):
                    with tf.variable_scope('conv%d' % (i + 1)):
                        activation_fn = tf.nn.relu if i < 3 else None
                        normalizer_fn = tf.contrib.layers.batch_norm if i < 3 else None
                        out = tf.contrib.layers.conv2d_transpose(out, o_depth[i], [5, 5], stride=2, activation_fn=activation_fn, normalizer_fn=normalizer_fn)
            reuse = True
            return tf.nn.tanh(out)
        return model

    def __discriminator(self, depth1, depth2, depth3, depth4):
        reuse = False
        def leaky_relu(x, leak=0.2):
            return tf.maximum(x, x * leak)
        def model(inputs):
            nonlocal reuse
            depths = [3, depth1, depth2, depth3, depth4]
            i_depth = depths[0:4]
            o_depth = depths[1:5]
            out = []
            with tf.variable_scope('d', reuse=reuse):
                outputs = inputs
                # convolution layer
                for i in range(4):
                    with tf.variable_scope('conv%d' % i):
                        outputs = tf.contrib.layers.conv2d(outputs, o_depth[i], [5, 5], stride=2, activation_fn=leaky_relu, normalizer_fn=tf.contrib.layers.batch_norm)
                        out.append(outputs)
                # reshepe and fully connect to 2 classes
                with tf.variable_scope('classify'):
                    dim = 1
{'fraction_non_alphanumeric': 0.10406742396482228, 'fraction_numerical': 0.035544155368266765, 'mean_word_length': 1.808127572016461, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3531702', 'n_tokens_mistral': 1798, 'n_tokens_neox': 1676, 'n_words': 371}