title: Processing time gets longer and longer after each iteration (TensorFlow)
body: <p>I am training a CNN with TensorFlow for medical images application.</p>
  
  <p>As I don't have a lot of data, I am trying to apply random modifications to my training batch during the training loop to artificially increase my training dataset. I made the following function in a different script and call it on my training batch:</p>
  
  <pre><code>def randomly_modify_training_batch(images_train_batch, batch_size):
  
      for i in range(batch_size):
          image = images_train_batch[i]
          image_tensor = tf.convert_to_tensor(image)
  
          distorted_image = tf.image.random_flip_left_right(image_tensor)
          distorted_image = tf.image.random_flip_up_down(distorted_image)
          distorted_image = tf.image.random_brightness(distorted_image, max_delta=60)
          distorted_image = tf.image.random_contrast(distorted_image, lower=0.2, upper=1.8)
  
          with tf.Session():
              images_train_batch[i] = distorted_image.eval()  # .eval() is used to reconvert the image from Tensor type to ndarray
  
  return images_train_batch
  </code></pre>
  
  <p>The code works well for applying modifications to my images. </p>
  
  <p><strong>The problem is :</strong></p>
  
  <p>After each iteration of my training loop (feedfoward + backpropagation), applying this same function to my next training batch steadily takes 5 seconds longer than the last time.</p>
  
  <p>It takes around 1 second to process and reaches over a minute of processing after a bit more than 10 iterations.</p>
  
  <p>What causes this slowing?
  How can I prevent it?</p>
  
  <p>(I suspect something with <code>distorted_image.eval()</code> but I'm not quite sure. Am opening a new session each time? TensorFlow isn't supposed to close automatically the session as I use in a "with tf.Session()" block?)</p>