Last active
June 27, 2019 16:24
-
-
Save nvinayvarma189/e6bcca7d4d7c534d2186e471d359925e to your computer and use it in GitHub Desktop.
Custom Layer for deep learning model in python
This file contains 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
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