-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModels.py
46 lines (30 loc) · 2.64 KB
/
Models.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
45
46
def generator(z,isTrain,keep_prob):
with tf.variable_scope("generator"):
img = tf.layers.dense(z, 6*6*1024, activation = tf.nn.leaky_relu, kernel_initializer=tf.variance_scaling_initializer(dtype = tf.float32))
img = tf.layers.batch_normalization(img, training = isTrain)
img = tf.reshape(img,[-1,6,6,1024])
img = tf.layers.conv2d_transpose(img, 512, 3, strides = 2, activation = tf.nn.leaky_relu, padding ='same', kernel_initializer=tf.variance_scaling_initializer(dtype = tf.float32))
img = tf.layers.batch_normalization(img, training = isTrain)
img = tf.layers.conv2d_transpose(img, 256, 3, strides = 2, activation = tf.nn.leaky_relu, padding ='same', kernel_initializer=tf.variance_scaling_initializer(dtype = tf.float32)) img = tf.layers.batch_normalization(img, training = isTrain)
img = tf.layers.conv2d_transpose(img, 128, 3, strides = 2, activation = tf.nn.leaky_relu, padding ='same', kernel_initializer=tf.variance_scaling_initializer(dtype = tf.float32)) img = tf.layers.batch_normalization(img, training = isTrain)
img = tf.layers.conv2d_transpose(img, 3, 3, strides = 2, padding ='same', name = 'generator_out', kernel_initializer=tf.variance_scaling_initializer(dtype = tf.float32))
img = tf.nn.tanh(img)
return img
def discriminator(x,isTrain,keep_prob):
with tf.variable_scope("discriminator"):
x = tf.reshape(x,[-1,96,96,3])
logits = tf.layers.conv2d(x,128,5, kernel_initializer=tf.variance_scaling_initializer(dtype = tf.float32))
logits = tf.nn.leaky_relu(logits, alpha = 0.01)
logits = tf.layers.max_pooling2d(logits,2,2)
logits = tf.layers.conv2d(logits,256,5, kernel_initializer=tf.variance_scaling_initializer(dtype = tf.float32))
logits = tf.nn.leaky_relu(logits, alpha = 0.01)
logits = tf.layers.max_pooling2d(logits,2,2)
logits = tf.layers.conv2d(logits,512,5, kernel_initializer=tf.variance_scaling_initializer(dtype = tf.float32))
logits = tf.nn.leaky_relu(logits, alpha = 0.01)
logits = tf.layers.max_pooling2d(logits,2,2)
logits = tf.layers.conv2d(logits,1024,5, kernel_initializer=tf.variance_scaling_initializer(dtype = tf.float32))
logits = tf.nn.leaky_relu(logits, alpha = 0.01)
logits = tf.layers.max_pooling2d(logits,2,2)
logits = tf.layers.flatten(logits)
logits = tf.layers.dense(logits, 1, name = 'discriminator_out', kernel_initializer=tf.variance_scaling_initializer(dtype = tf.float32))
return logits