1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
for e in range(epochs):
idx = np.arange(len(X_train))
np.random.shuffle(idx)
X_train, Y_train = X_train[idx,:,:], Y_train[idx]
for i in range(n_batches):
x = X_train[(i*batch_size):((i+1)*batch_size),:,:]
y = Y_train[(i*batch_size):((i+1)*batch_size),:,:]
_, curr_loss = sess.run([optimizer, total_loss],
feed_dict={tf_X:x, tf_Y:y})
#print("Epoch:",str(e), "Batch:",str(i), "loss:",str(curr_loss))
loss_val,output_val = sess.run([total_loss,outputs], feed_dict={tf_X:X_valid, tf_Y:Y_valid})
print("Epoch:",str(e), " Loss:", loss_val)
|