-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
57 lines (50 loc) · 2 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
57
import tensorflow as tf
from tensorflow.keras import layers
DIMENSN = 80
def generator():
skernel = (4,4,4)
sstride = (2,2,2)
model = tf.keras.Sequential()
CDIMNSION = DIMENSN//(2**4)
#Project and reshape
model.add(layers.Dense(CDIMNSION*CDIMNSION*CDIMNSION*512, use_bias=False, input_shape=(100,)))
model.add(layers.BatchNormalization())
model.add(layers.LeakyReLU())
model.add(layers.Reshape((CDIMNSION,CDIMNSION,CDIMNSION,512)))
#3D convs
model.add(layers.Conv3DTranspose(256, skernel, strides=(1,1,1), padding='same', use_bias=False))
model.add(layers.BatchNormalization())
model.add(layers.LeakyReLU())
model.add(layers.Conv3DTranspose(128, skernel, strides=sstride, padding='same', use_bias=False))
model.add(layers.BatchNormalization())
model.add(layers.LeakyReLU())
model.add(layers.Conv3DTranspose( 64, skernel, strides=sstride, padding='same', use_bias=False))
model.add(layers.BatchNormalization())
model.add(layers.LeakyReLU())
model.add(layers.Conv3DTranspose( 32, skernel, strides=sstride, padding='same', use_bias=False))
model.add(layers.BatchNormalization())
model.add(layers.LeakyReLU())
#Final layer
model.add(layers.Conv3DTranspose( 1, skernel, strides=sstride, padding='same', use_bias=False, activation='tanh'))
return model
def discriminator():
skernel = (4,4,4)
sstride = (2,2,2)
model = tf.keras.Sequential()
#3D convs
model.add(layers.Conv3D( 32, skernel, strides=sstride, padding='same', input_shape=[DIMENSN,DIMENSN,DIMENSN,1]))
model.add(layers.LeakyReLU())
model.add(layers.Dropout(0.3))
model.add(layers.Conv3D( 64, skernel, strides=sstride, padding='same'))
model.add(layers.LeakyReLU())
model.add(layers.Dropout(0.3))
model.add(layers.Conv3D(128, skernel, strides=sstride, padding='same'))
model.add(layers.LeakyReLU())
model.add(layers.Dropout(0.3))
model.add(layers.Conv3D(256, skernel, strides=sstride, padding='same'))
model.add(layers.LeakyReLU())
model.add(layers.Dropout(0.3))
#Final layer
model.add(layers.Flatten())
model.add(layers.Dense(1))
return model