Skip to content

Instantly share code, notes, and snippets.

@risenW
Last active July 17, 2018 13:34
Show Gist options
  • Save risenW/8b75fd0a47770132c5910e2e7c060710 to your computer and use it in GitHub Desktop.
Save risenW/8b75fd0a47770132c5910e2e7c060710 to your computer and use it in GitHub Desktop.
Code for batch training using tensorflow
#Load our libraries
import matplotlib.pyplot as plt
import numpy as np
import tensorflow as tf
sess = tf.Session()
# declare batch size
batch_size = 20
x_vals = np.random.normal(1, 0.1, 100)
y_vals = np.repeat(10., 100)
X_data = tf.placeholder(shape=[None, 1], dtype=tf.float32)
Y_target = tf.placeholder(shape=[None, 1], dtype=tf.float32)
W = tf.Variable(tf.constant(0., shape=[1,1])) #It is good practice to initialize the weight to zero
#Add our simple operation to the computational graph
Y_pred = tf.matmul(X_data, W)
# initialize our variables
init = tf.global_variables_initializer()
sess.run(init)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment