【问题标题】:Tensorflow Deep Learning Memory Leak?TensorFlow 深度学习内存泄漏?
【发布时间】:2017-09-27 10:49:01
【问题描述】:

我正在使用 Tensorflow 进行 GPU 加速的深度学习,并且遇到了内存泄漏(RAM 种类,而不是在 GPU 上)。

几乎毫无疑问,我已将范围缩小到训练线

self.sess.run(self.train_step, feed_dict={self.x: trainingdata, self.y_true: traininglabels, self.keepratio: self.training_keep_rate})

如果我注释掉那一行,并且只注释掉那一行(但我仍然对几千个训练批次进行所有预处理和验证/测试等),内存泄漏不会发生。

泄漏量约为每小时几 GB(我正在运行 Ubuntu,并且有 16GB RAM + 16GB 交换空间;运行 1-3 小时后,系统变得非常迟钝且无响应,大约 1/3-使用了 1/2 的 RAM,这对我来说有点奇怪,因为我仍然有很多 RAM,而且发生这种情况时 CPU 大部分是空闲的......)

这里是一些相关的初始化代码(只运行一次,在开始时):

    with tf.name_scope('after_final_layer') as scope:
        self.layer1 = weights["wc1"]
        self.y_conv = network(self.x, weights, biases, self.keepratio)['out']
        variable_summaries(self.y_conv)
        # Note: Don't add a softmax reducer in the network if you are going to use this
        # cross-entropy function
        self.cross_entropy = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(self.y_conv, self.y_true, name = "softmax/cross_ent"), name = "reduce_mean")
        self.train_step = tf.train.AdamOptimizer(learning_rate, name = "Adam_Optimizer").minimize(self.cross_entropy)

        self.prediction = tf.argmax(self.y_conv, 1)
        self.correct_prediction = tf.equal(self.prediction, tf.argmax(self.y_true, 1))

        self.accuracy = tf.reduce_mean(tf.cast(self.correct_prediction, tf.float32))

        if tensorboard:
            # Merge all the summaries and write them out to the directory below
            self.merged = tf.summary.merge_all()
            self.my_writer = tf.summary.FileWriter('/home/james/PycharmProjects/AI_Final/my_tensorboard', graph=self.sess.graph)

        # self.sess.run(tf.initialize_all_variables()) #old outdated way to do below
        tf.global_variables_initializer().run(session=self.sess)

我也很高兴发布所有网络/初始化代码,但我认为这可能与这次泄漏无关。

是我做错了什么还是我发现了 Tensorflow 错误?提前致谢!

更新:我可能很快会提交一份错误报告,但我首先要确认我没有因自己的错误而打扰他们。我加了

self.sess.graph.finalize()

到我的初始化代码的末尾。据我了解,如果我不小心添加到图表中,它应该会引发异常。不抛出异常。我正在使用 tf 版本 0.12.0-rc0、np 版本 1.12.0b1 和 Python 版本 2.7.6。这些版本可能已经过时/有问题吗?

【问题讨论】:

  • 我建议在 TF github 上提交一个错误

标签: memory-leaks tensorflow


【解决方案1】:

这个问题在 1.1 中得到解决。忽略this page(在撰写本文时)说最新的稳定版本是 r0.12; 1.1 是最新的稳定版本。见https://github.com/tensorflow/tensorflow/issues/9590https://github.com/tensorflow/tensorflow/issues/9872

【讨论】:

    猜你喜欢
    • 2017-12-09
    • 1970-01-01
    • 2012-07-28
    • 1970-01-01
    • 2017-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多