-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.py
More file actions
executable file
·105 lines (85 loc) · 5.06 KB
/
model.py
File metadata and controls
executable file
·105 lines (85 loc) · 5.06 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import tensorflow as tf
import tensorlayer as tl
from tensorlayer.layers import *
flags = tf.app.flags
FLAGS = flags.FLAGS
def sANN_simplified_api(inputs, is_train=True, reuse=False):
num_classes = 1
fc_neurons = 1024
with tf.variable_scope("sANN", reuse=reuse):
tl.layers.set_name_reuse(reuse)
net_in = InputLayer(inputs, name='s/in')
net_in = DropoutLayer(net_in, keep=0.8, name='s/in/drop', is_fix=True)
net_h0 = DenseLayer(net_in, n_units=fc_neurons,
act = tf.contrib.keras.layers.LeakyReLU, name='s/h0')
net_h0 = DropoutLayer(net_h0, keep=0.5, name='s/h0/drop', is_fix=True)
net_h1 = DenseLayer(net_h0, n_units=fc_neurons,
act = tf.contrib.keras.layers.LeakyReLU, name='s/h1')
net_h1 = DropoutLayer(net_h1, keep=0.5, name='s/h1/drop', is_fix=True)
net_h2 = DenseLayer(net_h1, n_units=num_classes,
act = tf.sigmoid,
name='s/h2')
logits = net_h2.outputs
return net_h2, logits
def generator_simplified_api(inputs, is_train=True, reuse=False):
image_size = 64
s2, s4, s8, s16 = int(image_size/2), int(image_size/4), int(image_size/8), int(image_size/16)
gf_dim = 64 # Dimension of gen filters in first conv layer. [64]
c_dim = FLAGS.c_dim # n_color 3
batch_size = FLAGS.batch_size # 64
w_init = tf.random_normal_initializer(stddev=0.02)
gamma_init = tf.random_normal_initializer(1., 0.02)
with tf.variable_scope("generator", reuse=reuse):
tl.layers.set_name_reuse(reuse)
net_in = InputLayer(inputs, name='g/in')
net_h0 = DenseLayer(net_in, n_units=gf_dim*8*s16*s16, W_init=w_init,
act = tf.identity, name='g/h0/lin')
net_h0 = ReshapeLayer(net_h0, shape=[-1, s16, s16, gf_dim*8], name='g/h0/reshape')
net_h0 = BatchNormLayer(net_h0, act=tf.nn.relu, is_train=is_train,
gamma_init=gamma_init, name='g/h0/batch_norm')
net_h1 = DeConv2d(net_h0, gf_dim*4, (5, 5), out_size=(s8, s8), strides=(2, 2),
padding='SAME', batch_size=batch_size, act=None, W_init=w_init, name='g/h1/decon2d')
net_h1 = BatchNormLayer(net_h1, act=tf.nn.relu, is_train=is_train,
gamma_init=gamma_init, name='g/h1/batch_norm')
net_h2 = DeConv2d(net_h1, gf_dim*2, (5, 5), out_size=(s4, s4), strides=(2, 2),
padding='SAME', batch_size=batch_size, act=None, W_init=w_init, name='g/h2/decon2d')
net_h2 = BatchNormLayer(net_h2, act=tf.nn.relu, is_train=is_train,
gamma_init=gamma_init, name='g/h2/batch_norm')
net_h3 = DeConv2d(net_h2, gf_dim, (5, 5), out_size=(s2, s2), strides=(2, 2),
padding='SAME', batch_size=batch_size, act=None, W_init=w_init, name='g/h3/decon2d')
net_h3 = BatchNormLayer(net_h3, act=tf.nn.relu, is_train=is_train,
gamma_init=gamma_init, name='g/h3/batch_norm')
net_h4 = DeConv2d(net_h3, c_dim, (5, 5), out_size=(image_size, image_size), strides=(2, 2),
padding='SAME', batch_size=batch_size, act=None, W_init=w_init, name='g/h4/decon2d')
logits = net_h4.outputs
net_h4.outputs = tf.nn.tanh(net_h4.outputs)
return net_h4, logits
def discriminator_simplified_api(inputs, is_train=True, reuse=False):
df_dim = 64 # Dimension of discrim filters in first conv layer. [64]
c_dim = FLAGS.c_dim # n_color 3
batch_size = FLAGS.batch_size # 64
w_init = tf.random_normal_initializer(stddev=0.02)
gamma_init = tf.random_normal_initializer(1., 0.02)
with tf.variable_scope("discriminator", reuse=reuse):
tl.layers.set_name_reuse(reuse)
net_in = InputLayer(inputs, name='d/in')
net_h0 = Conv2d(net_in, df_dim, (5, 5), (2, 2), act=lambda x: tl.act.lrelu(x, 0.2),
padding='SAME', W_init=w_init, name='d/h0/conv2d')
net_h1 = Conv2d(net_h0, df_dim*2, (5, 5), (2, 2), act=None,
padding='SAME', W_init=w_init, name='d/h1/conv2d')
net_h1 = BatchNormLayer(net_h1, act=lambda x: tl.act.lrelu(x, 0.2),
is_train=is_train, gamma_init=gamma_init, name='d/h1/batch_norm')
net_h2 = Conv2d(net_h1, df_dim*4, (5, 5), (2, 2), act=None,
padding='SAME', W_init=w_init, name='d/h2/conv2d')
net_h2 = BatchNormLayer(net_h2, act=lambda x: tl.act.lrelu(x, 0.2),
is_train=is_train, gamma_init=gamma_init, name='d/h2/batch_norm')
net_h3 = Conv2d(net_h2, df_dim*8, (5, 5), (2, 2), act=None,
padding='SAME', W_init=w_init, name='d/h3/conv2d')
net_h3 = BatchNormLayer(net_h3, act=lambda x: tl.act.lrelu(x, 0.2),
is_train=is_train, gamma_init=gamma_init, name='d/h3/batch_norm')
net_h4 = FlattenLayer(net_h3, name='d/h4/flatten')
net_h4 = DenseLayer(net_h4, n_units=1, act=tf.identity,
W_init = w_init, name='d/h4/lin_sigmoid')
logits = net_h4.outputs
net_h4.outputs = tf.nn.sigmoid(net_h4.outputs)
return net_h4, logits