-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAutoEncoderBlocks.py
34 lines (24 loc) · 1.08 KB
/
AutoEncoderBlocks.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
from tensorflow.keras import layers
import tensorflow_addons as tfa
from tensorflow import keras
import tensorflow as tf
def downsample(filters, size, alpha, apply_instancenorm=True):
initializer = tf.random_normal_initializer(0., 0.02)
result = keras.Sequential()
result.add(layers.Conv2D(filters, size, strides=2, padding='same',
kernel_initializer=initializer, use_bias=False))
if apply_instancenorm:
result.add(tfa.layers.InstanceNormalization())
result.add(layers.LeakyReLU(alpha))
return result
def upsample(filters, size, apply_batch=False):
initializer = tf.random_normal_initializer(0., 0.02)
result = keras.Sequential()
result.add(layers.Conv2DTranspose(filters, size, strides=2,
padding='same',
kernel_initializer=initializer,
use_bias=False))
if apply_batch:
result.add(layers.BatchNormalization())#tfa.layers.InstanceNormalization())
result.add(layers.ReLU())
return result