-
Notifications
You must be signed in to change notification settings - Fork 46
/
model.py
58 lines (51 loc) · 2.57 KB
/
model.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
47
48
49
50
51
52
53
54
55
56
import tensorflow as tf
from tensorflow.keras import layers
from utils import apply_phaseshuffle
def Generator(kernel_len=(5,5),dim=64,channels=1):
model = tf.keras.Sequential(name='generator')
#Input Layer
model.add(layers.Dense(4 * 4 * dim * 16, use_bias=False, input_shape=(100,)))
model.add(layers.Reshape((4,4,dim*16)))
model.add(layers.ReLU())
#Layer 0
model.add(layers.Conv2DTranspose(dim * 8, kernel_len, strides=(2,2), padding='same', use_bias=False, activation='relu'))
model.add(layers.ReLU())
#Layer 1
model.add(layers.Conv2DTranspose(dim * 4, kernel_len, strides=(2,2), padding='same', use_bias=False, activation='relu'))
model.add(layers.ReLU())
#Layer 2
model.add(layers.Conv2DTranspose(dim * 2, kernel_len, strides=(2,2), padding='same', use_bias=False, activation='relu'))
model.add(layers.ReLU())
#Layer 3
model.add(layers.Conv2DTranspose(dim, kernel_len, strides=(2,2), padding='same', use_bias=False, activation='relu'))
model.add(layers.ReLU())
#Layer 4
model.add(layers.Conv2DTranspose(channels, kernel_len, strides=(2,2), padding='same', use_bias=False, activation='tanh'))
model.add(layers.Lambda(lambda x: tf.nn.tanh(x), name='Tanh'))
return model
def Discrimiator(kernel_len=(5,5),dim=64,channels=1,phaseshuffle_rad=2):
model = tf.keras.Sequential(name='discriminator')
phaseshuffle = lambda x: apply_phaseshuffle(x, phaseshuffle_rad)
#Layer 0
model.add(layers.Conv2D(dim, kernel_len, strides=(2,2), padding='same', use_bias=False, input_shape=(128,128,channels)))
model.add(layers.LeakyReLU(alpha=0.2))
model.add(layers.Lambda(phaseshuffle, name='phase_shuffler0'))
#Layer 1
model.add(layers.Conv2D(dim * 2, kernel_len, strides=(2,2), padding='same', use_bias=False))
model.add(layers.LeakyReLU(alpha=0.2))
model.add(layers.Lambda(phaseshuffle, name='phase_shuffler1'))
#Layer 2
model.add(layers.Conv2D(dim * 4, kernel_len, strides=(2,2), padding='same', use_bias=False))
model.add(layers.LeakyReLU(alpha=0.2))
model.add(layers.Lambda(phaseshuffle, name='phase_shuffler2'))
#Layer 3
model.add(layers.Conv2D(dim * 8, kernel_len, strides=(2,2), padding='same', use_bias=False))
model.add(layers.LeakyReLU(alpha=0.2))
model.add(layers.Lambda(phaseshuffle, name='phase_shuffler3'))
#Layer 4
model.add(layers.Conv2D(dim * 16, kernel_len, strides=(2,2), padding='same', use_bias=False))
model.add(layers.LeakyReLU(alpha=0.2))
#Layer 5
model.add(layers.Reshape((4*4*dim*16,)))
model.add(layers.Dense(1))
return model