Created
December 6, 2016 02:19
-
-
Save mmmayo13/d04db5aa97e06bcf287b2b0367fb8c01 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
import numpy as np | |
import tensorflow.contrib.slim as slim | |
total_layers = 25 #Specify how deep we want our network | |
units_between_stride = total_layers / 5 | |
def highwayUnit(input_layer,i): | |
with tf.variable_scope("highway_unit"+str(i)): | |
H = slim.conv2d(input_layer,64,[3,3]) | |
T = slim.conv2d(input_layer,64,[3,3], #We initialize with a negative bias to push the network to use the skip connection | |
biases_initializer=tf.constant_initializer(-1.0),activation_fn=tf.nn.sigmoid) | |
output = H*T + input_layer*(1.0-T) | |
return output | |
tf.reset_default_graph() | |
input_layer = tf.placeholder(shape=[None,32,32,3],dtype=tf.float32,name='input') | |
label_layer = tf.placeholder(shape=[None],dtype=tf.int32) | |
label_oh = slim.layers.one_hot_encoding(label_layer,10) | |
layer1 = slim.conv2d(input_layer,64,[3,3],normalizer_fn=slim.batch_norm,scope='conv_'+str(0)) | |
for i in range(5): | |
for j in range(units_between_stride): | |
layer1 = highwayUnit(layer1,j + (i*units_between_stride)) | |
layer1 = slim.conv2d(layer1,64,[3,3],stride=[2,2],normalizer_fn=slim.batch_norm,scope='conv_s_'+str(i)) | |
top = slim.conv2d(layer1,10,[3,3],normalizer_fn=slim.batch_norm,activation_fn=None,scope='conv_top') | |
output = slim.layers.softmax(slim.layers.flatten(top)) | |
loss = tf.reduce_mean(-tf.reduce_sum(label_oh * tf.log(output) + 1e-10, reduction_indices=[1])) | |
trainer = tf.train.AdamOptimizer(learning_rate=0.001) | |
update = trainer.minimize(loss) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment