GAN minibatch discrimination code
2019. 5. 28. 03:32ㆍ분석 Python/Tensorflow
NUM_KERNELS = 5
def minibatch(input, num_kernels=NUM_KERNELS, kernel_dim=3, name = None ):
output_dim = num_kernels*kernel_dim
w = tf.get_variable("Weight_minibatch_" + name ,
[input.get_shape()[1], output_dim ],
initializer=tf.random_normal_initializer(stddev=0.2))
b = tf.get_variable("Bias_minibatch_" + name ,
[output_dim],initializer=tf.constant_initializer(0.0))
x = tf.matmul(input, w) + b
activation = tf.reshape(x, (-1, num_kernels, kernel_dim))
diffs = tf.expand_dims(activation, 3) - \
tf.expand_dims(tf.transpose(activation, [1, 2, 0]), 0)
#eps = tf.expand_dims(np.eye(int(input.get_shape()[0]), dtype=np.float32), 1)
abs_diffs = tf.reduce_sum(tf.abs(diffs), 2) #+ eps
minibatch_features = tf.reduce_sum(tf.exp(-abs_diffs), 2)
output = tf.concat([input, minibatch_features],1)
return output
https://www.inference.vc/understanding-minibatch-discrimination-in-gans/
https://arxiv.org/pdf/1606.03498.pdf Improved Techniques for Training GANs
728x90
'분석 Python > Tensorflow' 카테고리의 다른 글
tensorflow mask 씌우기 (0) | 2019.05.30 |
---|---|
tensorflow 폴더 생성 및 지우기 (0) | 2019.05.28 |
[Python] 실습 Categorical 변수를 Embedding 해보기 (0) | 2019.05.20 |
Colaboratory와 tensorboard와 tensorflow를 활용한 GAN 구현물 (4) | 2019.05.18 |
tensorflow eager gpu 할당 쓴만큼만 잡게하기. (0) | 2019.05.04 |