Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tensorflow as tf
- # Model Perimeters
- W = tf.Variable([0.3],tf.float32)
- b = tf.Variable([0.3],tf.float32)
- # Input and Output
- x = tf.placeholder(tf.float32)
- y = tf.placeholder(tf.float32)
- # Model Output
- linear_model = tf.add(tf.multiply(W , x) , b)
- # Loss
- squared_delta = tf.square(linear_model - y)
- loss = tf.reduce_sum(squared_delta)
- # Optimize
- optimizer = tf.train.GradientDescentOptimizer(learning_rate=0.01)
- train = optimizer.minimize(loss)
- # initialize variables
- init = tf.global_variables_initializer()
- # start session
- sess = tf.Session()
- sess.run(init)
- print( sess.run(loss,{x:[1,2,3,4],y:[0,-1,-2,-3]}))
- # Traning
- for i in range(1000):
- sess.run(train,{x:[1,2,3,4],y:[0,-1,-2,-3]})
- print(sess.run([W , b]))
- File_Writer = tf.summary.FileWriter('./graph',sess.graph)
- sess.run(File_Writer)
- # run following command in Terminal to run the Tensorboard
- # tensorboard --logdir graph
- # graph is the path of folder in which graph summary is saved
Add Comment
Please, Sign In to add comment