Skip to content

Commit

Permalink
implemented tensorboard
Browse files Browse the repository at this point in the history
  • Loading branch information
LordSomen committed Aug 27, 2018
1 parent 415917d commit 699ebbe
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
Binary file not shown.
Binary file not shown.
58 changes: 57 additions & 1 deletion Tensorflow/tf.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,60 @@ def fetch_batch(epoch, batch_index, batch_size):
best_theta_restored = theta.eval()
print(best_theta_restored)
#%%
np.allclose(best_theta, best_theta_restored)
np.allclose(best_theta, best_theta_restored)

#%%
''' implementing tensorboard'''
reset_graph()

from datetime import datetime
now = datetime.utcnow().strftime("%Y%m%d%H%M%S")
root_logdir = "tf.logs"
logdir = "{}/run-{}/".format(root_logdir, now)

#%%
n_epochs = 1000
learning_rate = 0.01
X = tf.placeholder(tf.float32,shape=(None,n+1),name="X")
Y = tf.placeholder(tf.float32,shape=(None,1),name="Y")
theta = tf.Variable(tf.random_uniform([n+1,1],
-1.0,1.0,seed=42),name="theta")
Y_pred = tf.matmul(X,theta,name="predictions")
error = Y_pred - Y
mse = tf.reduce_mean(tf.square(error), name="mse")
optimizer = tf.train.GradientDescentOptimizer(learning_rate=
learning_rate)
training_op = optimizer.minimize(mse)

init = tf.global_variables_initializer()

#%%
mse_summary = tf.summary.scalar("MSE",mse)
file_writer = tf.summary.FileWriter(logdir,
tf.get_default_graph())

#%%
n_epochs = 10
batch_size = 100
n_batches = int(np.ceil(m / batch_size))

#%%
with tf.Session() as sess:
sess.run(init)
for epoch in range(n_epochs):
for batch_index in range(n_batches):
X_batch,Y_batch = fetch_batch(epoch,batch_index
,batch_size)
if batch_index % 10 == 0:
summary_str = mse_summary.eval(feed_dict=
{X: X_batch, Y: Y_batch})
step = epoch * n_batches + batch_index
file_writer.add_summary(summary_str, step)
sess.run(training_op, feed_dict={X: X_batch,
Y: Y_batch})

best_theta = theta.eval()

#%%
file_writer.close()
print(best_theta)

0 comments on commit 699ebbe

Please sign in to comment.