import tensorflow as tf

        return h

def minibatch_discrimination(x, n_kernels, dim_per_kernel, name):
    with tf.variable_scope(name):
        batch_size, nf = x.get_shape().as_list()
        h = linear(x, [nf, n_kernels*dim_per_kernel], 'h1')
        activation = tf.reshape(h, (batch_size, n_kernels, dim_per_kernel))

        big = tf.eye(batch_size)
        big = tf.expand_dims(big, 1)

        abs_dif = tf.reduce_sum(tf.abs(tf.expand_dims(activation, 3) - tf.expand_dims(tf.transpose(activation, [1, 2, 0]), 0)), 2)
        mask = 1. - big
        masked = tf.exp(-abs_dif) * mask

        def half(tens, second):
