Skip to content

Commit

Permalink
Removed stop_gradient operations from within the loop, as they create…
Browse files Browse the repository at this point in the history
… new operations into the model which are never cleaned up.
  • Loading branch information
Tero Keski-Valkama committed Jul 7, 2017
1 parent 05c4261 commit aa4c66c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
6 changes: 3 additions & 3 deletions model.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,12 @@ def create(parameters):
train_op = optimizer.apply_gradients(zip(grads, tvars))

model = {
'output': output,
'output': tf.stop_gradient(output),
'optimizer': train_op,
'input': input,
'target_output': target_output,
'cost': cost,
'reg_loss': reg_loss,
'cost': tf.stop_gradient(cost),
'reg_loss': tf.stop_gradient(reg_loss),
'schedule_step': schedule_step,
'input_noise': input_noise,
'noise': noise
Expand Down
15 changes: 12 additions & 3 deletions train.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@

import re

def memory():
import os
import psutil
pid = os.getpid()
py = psutil.Process(pid)
memoryUse = py.memory_info()[0]/2.**30 # memory use in GB...I think
print('memory use:', memoryUse)

def make_x_and_y(x, noise, amplitude_plusminus_factor):
# Length of shifted x and y
length = np.size(x, 0) - 1
Expand Down Expand Up @@ -92,7 +100,7 @@ def choose_value(sample):
parameters['amplitude_plusminus_factor'])

# Create first estimation and optimize for the first order.
[_, cost, reg_loss] = sess.run([model['optimizer'], tf.stop_gradient(model['cost']), tf.stop_gradient(model['reg_loss'])], feed_dict = {
[_, cost, reg_loss] = sess.run([model['optimizer'], model['cost'], model['reg_loss']], feed_dict = {
model['input']: x,
model['schedule_step']: iter,
model['noise']: parameters['noise'],
Expand All @@ -112,7 +120,7 @@ def choose_value(sample):
", iters_since_loss_improved: ", iters_since_loss_improved
saver.save(sess, 'sound-model')

[error, output] = sess.run([tf.stop_gradient(model['cost']), tf.stop_gradient(model['output'])], feed_dict = {
[error, output] = sess.run([model['cost'], model['output']], feed_dict = {
model['input']: x,
model['schedule_step']: iter,
model['noise']: parameters['noise'],
Expand All @@ -134,7 +142,7 @@ def choose_value(sample):
test_x = manage_data.getNextTrainingBatchSequence(testingData, training_length)
(original_test_x, test_x, test_y) = make_x_and_y(test_x, 0.0, 0.0)

[test_error, test_output] = sess.run([tf.stop_gradient(model['cost']), tf.stop_gradient(model['output'])],
[test_error, test_output] = sess.run([model['cost'], model['output']],
feed_dict={
model['input']: test_x,
model['schedule_step']: iter,
Expand Down Expand Up @@ -171,6 +179,7 @@ def choose_value(sample):
##else:
## export_to_octave.save('train_error.mat', 'train_error', train_error_trend)
## export_to_octave.save('test_error.mat', 'test_error', test_error_trend)
memory()
sys.stdout.flush()
iter += 1
now = time.time()
Expand Down

0 comments on commit aa4c66c

Please sign in to comment.