Tensorflow图运行速度不断降低每次迭代

时间:2018-09-04 05:19:51

标签: python tensorflow

我有一个非常简单的Tensorflow设置,但是它的一方面(计算精度)一直在增加运行时间。我对这是为什么感到困惑。我尽可能地简化了代码,同时保持了错误。这是代码

import time
import tensorflow as tf
import numpy as np

# dummy data
data = np.zeros((12, 784))
labels = np.zeros((12, 10))

xs = tf.placeholder(tf.float32, [12, 784])
ys = tf.placeholder(tf.float32, [12, 10])

weights = tf.Variable(tf.truncated_normal([784, 10], stddev=0.1))

prediction = tf.nn.softmax(tf.matmul(xs, weights))

sess = tf.Session()

init = tf.global_variables_initializer()
sess.run(init)

while True:

    y_pre = sess.run(prediction, feed_dict={xs: data})
    correct_prediction = tf.equal(tf.argmax(y_pre, 1), tf.argmax(labels, 1))
    accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))

    start_time = time.time()

    r = sess.run(accuracy, feed_dict={xs: data, ys: labels})

    time_taken = time.time() - start_time

    #why does time_taken keep growing?
    print("time_taken", time_taken)

我怀疑在True循环中我做错了。以我的经验,time_taken从0.01左右的低位开始,但是如果您将其留足够长的时间,似乎无限期地增长到0.30甚至更高。有什么办法可以保持time_taken不变?任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

您能在执行过程中查看一下RAM吗?