Instantly share code, notes, and snippets.

@samphippen /dcgan.py Secret
Created Nov 23, 2018

Embed
What would you like to do?
import tensorflow as tf
from layers import inception_module, downsample, conv, initializer
SIZE=128
def encoder(x):
with tf.variable_scope("encoder"):
net = inception_module(x, 32)
net = downsample(net, 2)
net = inception_module(net, 32)
net = downsample(net, 2)
net = inception_module(net, 16)
net = downsample(net, 2)
net = conv(net, 32, 1)
net = tf.reshape(net, [-1, net.shape[1]*net.shape[2]*net.shape[3]])
net = tf.layers.dense(net, units=(SIZE//16*SIZE//16*32), activation=tf.nn.sigmoid, kernel_initializer=initializer)
return net
def decoder(x):
with tf.variable_scope("decoder"):
net = tf.reshape(x, shape=[-1, SIZE//16,SIZE//16,32])
net = tf.layers.conv2d_transpose(net, filters=512, kernel_size=5, strides=2, padding="same", kernel_initializer=initializer)
net = tf.layers.batch_normalization(net)
net = tf.nn.relu(net)
net = tf.layers.conv2d_transpose(net, filters=256, kernel_size=5, strides=2, padding="same", kernel_initializer=initializer)
net = tf.layers.batch_normalization(net)
net = tf.nn.relu(net)
net = tf.layers.conv2d_transpose(net, filters=64 , kernel_size=5, strides=2, padding="same", kernel_initializer=initializer)
net = tf.layers.batch_normalization(net)
net = tf.nn.relu(net)
net = tf.layers.conv2d_transpose(net, filters=32 , kernel_size=5, strides=2, padding="same", kernel_initializer=initializer)
net = tf.layers.batch_normalization(net)
net = tf.nn.relu(net)
net = tf.layers.conv2d_transpose(net, filters=3, kernel_size=5, activation=tf.nn.sigmoid, padding="same")
return net
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment