Skip to content

Instantly share code, notes, and snippets.

@JoshVarty
Last active February 11, 2018 18:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoshVarty/b80b67d35e71f6bfaf2475682c5ef4ca to your computer and use it in GitHub Desktop.
Save JoshVarty/b80b67d35e71f6bfaf2475682c5ef4ca to your computer and use it in GitHub Desktop.
layer1_weights = tf.Variable(tf.random_normal([3, 3, 1, 64])) #3x3x1x64
layer1_bias = tf.Variable(tf.zeros([64])) #64
layer1_conv = tf.nn.conv2d(input, filter=layer1_weights, strides=[1,1,1,1], padding='SAME') #28x28x64
layer1_out = tf.nn.relu(layer1_conv + layer1_bias) #28x28x64
layer2_weights = tf.Variable(tf.random_normal([3, 3, 64, 64])) #3x3x64x64
layer2_bias = tf.Variable(tf.zeros([64])) #64
layer2_conv = tf.nn.conv2d(layer1_out, filter=layer2_weights, strides=[1,1,1,1], padding='SAME')#28x28x64
layer2_out = tf.nn.relu(layer2_conv + layer2_bias) #28x28x64
pool1 = tf.nn.max_pool(layer2_out, ksize=[1,2,2,1], strides=[1,2,2,1], padding='VALID') #14x14x64
layer3_weights = tf.Variable(tf.random_normal([3, 3, 64, 128])) #3x3x64x128
layer3_bias = tf.Variable(tf.zeros([128])) #128
layer3_conv = tf.nn.conv2d(pool1, filter=layer3_weights, strides=[1,1,1,1], padding='SAME') #14x14x128
layer3_out = tf.nn.relu(layer3_conv + layer3_bias) #14x14x128
layer4_weights = tf.Variable(tf.random_normal([3, 3, 128, 128])) #3x3x128x128
layer4_bias = tf.Variable(tf.zeros([128])) #128
layer4_conv = tf.nn.conv2d(layer3_out, filter=layer4_weights, strides=[1,1,1,1], padding='SAME')#14x14x128
layer4_out = tf.nn.relu(layer4_conv + layer4_bias) #14x14x128
pool2 = tf.nn.max_pool(layer4_out, ksize=[1,2,2,1], strides=[1,2,2,1], padding='VALID') #7x7x128
shape = pool2.shape.as_list()
fc = shape[1] * shape[2] * shape[3] #7x7x256 = 6,272
reshape = tf.reshape(pool2, [-1, fc])
fully_connected_weights = tf.Variable(tf.random_normal([fc, 10])) #6,272x10
fully_connected_bias = tf.Variable(tf.zeros([10])) #10
logits = tf.matmul(reshape, fully_connected_weights) + fully_connected_bias #10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment