Skip to content

Instantly share code, notes, and snippets.

@imironhead
Created December 8, 2017 14:19
Show Gist options
  • Save imironhead/e742ec290d1ccc78b86ce8df932be02f to your computer and use it in GitHub Desktop.
Save imironhead/e742ec290d1ccc78b86ce8df932be02f to your computer and use it in GitHub Desktop.
def build_model():
"""
"""
eigens = tf.placeholder(shape=[None, 32, 28, 1], dtype=tf.float32)
labels = tf.placeholder(shape=[None, 28], dtype=tf.float32)
flow = eigens
weights_initializer = tf.truncated_normal_initializer(stddev=0.02)
# conv
for i in xrange(FLAGS.body_conv_layers):
flow = tf.contrib.layers.convolution2d(
inputs=flow,
num_outputs=FLAGS.body_conv_output,
kernel_size=FLAGS.body_conv_kernel,
stride=1,
padding='SAME',
activation_fn=leaky_relu,
normalizer_fn=instance_norm,
weights_initializer=weights_initializer,
biases_initializer=None,
scope='body_conv_{}'.format(i))
flow = tf.contrib.layers.flatten(flow)
for j in xrange(FLAGS.fc_layers):
flow = tf.contrib.layers.fully_connected(
inputs=flow,
num_outputs=FLAGS.fc_output,
activation_fn=leaky_relu,
weights_initializer=weights_initializer,
scope='fc_{}'.format(j))
flow = tf.contrib.layers.fully_connected(
inputs=flow,
num_outputs=28,
activation_fn=None,
weights_initializer=weights_initializer,
scope='fc_end')
guess = tf.nn.sigmoid(flow)
loss = my_loss(flow, labels)
learning_rate = tf.placeholder(shape=[], dtype=tf.float32)
trainer = tf.train \
.AdamOptimizer(learning_rate=learning_rate, beta1=0.5) \
.minimize(loss)
return {
'eigens': eigens,
'labels': labels,
'guess': guess,
'loss': loss,
'trainer': trainer,
'learning_rate': learning_rate,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment