Skip to content

Instantly share code, notes, and snippets.

@roopalgarg
Created March 11, 2017 08:04
Show Gist options
  • Save roopalgarg/919462c03e6b6fa7c0a3f7a070f33491 to your computer and use it in GitHub Desktop.
Save roopalgarg/919462c03e6b6fa7c0a3f7a070f33491 to your computer and use it in GitHub Desktop.
tensorflow: add noise
import tensorflow as tf
import numpy as np
def gaussian_noise_layer(input_layer, std):
noise = tf.random_normal(shape=tf.shape(input_layer), mean=0.0, stddev=std, dtype=tf.float32)
return input_layer + noise
inp = tf.placeholder(tf.float32, shape=[None, 8], name='input')
noise = gaussian_noise_layer(inp, .2)
noise.eval(session=tf.Session(), feed_dict={inp: np.zeros((4, 8))})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment