I was just trying some stuff for a quaternionic neural network when I realized that, even if I close my current Session in a for loop, my program slows down massively and I get a memory leak caused by ops being constructed. This is my code:
for step in xrange(0,200):#num_epochs * train_size // BATCH_SIZE):
338
339 with tf.Session() as sess:
340
341 offset = (BATCH_SIZE) % train_size
342 #print "Offset : %d" % offset
343
344 batch_data = []
345 batch_labels = []
346 batch_data.append(qtrain[0][offset:(offset + BATCH_SIZE)])
347 batch_labels.append(qtrain_labels[0][offset:(offset + BATCH_SIZE)]
352 retour = sess.run(test, feed_dict={x: batch_data})
357
358 test2 = feedForwardStep(retour, W_to_output,b_output)
367 #sess.close()
The problem seems to come from test2 = feedForward(..)
. I need to declare these ops after executing retour
once, because retour
can't be a placeholder (I need to iterate through it). Without this line, the program runs very well, fast and without a memory leak. I can't understand why it seems like TensorFlow is trying to "save" test2
even if I close the session ...