我正在训练一个CNN与TensorFlow医学图像应用。在
由于我没有太多的数据,我试图在训练循环期间对训练批应用随机修改,以人为地增加训练数据集。我用不同的脚本编写了以下函数,并在我的培训批处理中调用它: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
代码很好地应用到我的图像修改。在
问题是:
在我的下一次训练中,每一次训练的循环时间都比我训练的每一次循环长5秒。在
它需要大约1秒的时间来处理,经过10次以上的迭代,处理时间超过一分钟。在
是什么导致了这种放缓?
我怎样才能防止呢?在
(我怀疑是distorted_image.eval()的东西,但我不太确定。我每次都开一个新的会议?TensorFlow不应该像我在“with”中使用的那样自动关闭会话tf.会议()“阻止?)在