This repository was archived by the owner on Mar 14, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmodels_64x64.py
44 lines (35 loc) · 1.48 KB
/
models_64x64.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from functools import partial
import tensorflow as tf
import tensorflow.contrib.slim as slim
import tflib as tl
conv = partial(slim.conv2d, activation_fn=None)
dconv = partial(slim.conv2d_transpose, activation_fn=None)
fc = partial(tl.flatten_fully_connected, activation_fn=None)
relu = tf.nn.relu
lrelu = tf.nn.leaky_relu
batch_norm = partial(slim.batch_norm, scale=True, updates_collections=None)
def G(z, dim=64, is_training=True):
bn = partial(batch_norm, is_training=is_training)
dconv_bn_relu = partial(dconv, normalizer_fn=bn, activation_fn=relu)
fc_bn_relu = partial(fc, normalizer_fn=bn, activation_fn=relu)
with tf.variable_scope('G', reuse=tf.AUTO_REUSE):
y = fc_bn_relu(z, 4 * 4 * dim * 8)
y = tf.reshape(y, [-1, 4, 4, dim * 8])
y = dconv_bn_relu(y, dim * 4, 5, 2)
y = dconv_bn_relu(y, dim * 2, 5, 2)
y = dconv_bn_relu(y, dim * 1, 5, 2)
img = tf.tanh(dconv(y, 3, 5, 2))
return img
def D(img, dim=64, is_training=True):
bn = partial(batch_norm, is_training=is_training)
conv_bn_lrelu = partial(conv, normalizer_fn=bn, activation_fn=lrelu)
with tf.variable_scope('D', reuse=tf.AUTO_REUSE):
y = lrelu(conv(img, dim, 5, 2))
y = conv_bn_lrelu(y, dim * 2, 5, 2)
y = conv_bn_lrelu(y, dim * 4, 5, 2)
y = conv_bn_lrelu(y, dim * 8, 5, 2)
logit = fc(y, 1)
return logit