Skip to content

Instantly share code, notes, and snippets.

@nvinayvarma189
Last active June 27, 2019 16:24
Show Gist options
  • Save nvinayvarma189/e6bcca7d4d7c534d2186e471d359925e to your computer and use it in GitHub Desktop.
Save nvinayvarma189/e6bcca7d4d7c534d2186e471d359925e to your computer and use it in GitHub Desktop.
Custom Layer for deep learning model in python
def Custom_Conv(bottom):
import tensorflow as tf
#bottom is the previous layer. Her it is UpSampling2D layer
input_channels = int(bottom.get_shape()[-1])
# initialize weights and biases using xavier
weights = tf.Variable(tf.truncated_normal(shape=[1, 1, input_channels, 1], dtype=tf.float32, stddev=tf.sqrt(1.0 / (1 * 1 * input_channels))))
biases = tf.Variable(tf.constant(0, dtype=tf.float32, shape=[1]))
# conv = convolve(bottom, weights)
conv = tf.nn.conv2d(bottom, weights, strides=[1, 1, 1, 1], padding='SAME')
# Add biases
bias = tf.reshape(tf.nn.bias_add(conv, biases), tf.shape(conv))
# Apply sigmoid function
sigmoid = tf.nn.sigmoid(bias)
return sigmoid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment