Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 前向传播缓慢-训练时间正常_Python_Python 3.x_Performance_Tensorflow_Tensorboard - Fatal编程技术网

Python 前向传播缓慢-训练时间正常

Python 前向传播缓慢-训练时间正常,python,python-3.x,performance,tensorflow,tensorboard,Python,Python 3.x,Performance,Tensorflow,Tensorboard,我很难弄清楚为什么当我执行前向传播时,我的代码非常慢。有关代码可在此处找到: 我将我的代码的性能与此进行比较: 区别在于我跑步的时候 self.session.run(self.predict(x_batch), feed_dict={...}) self.returnPrediction(x_batch) 或者当我跑的时候 self.session.run(self.predict(x_batch), feed_dict={...}) self.returnPrediction(x_ba

我很难弄清楚为什么当我执行前向传播时,我的代码非常慢。有关代码可在此处找到:

我将我的代码的性能与此进行比较:

区别在于我跑步的时候

self.session.run(self.predict(x_batch), feed_dict={...})
self.returnPrediction(x_batch)
或者当我跑的时候

self.session.run(self.predict(x_batch), feed_dict={...})
self.returnPrediction(x_batch)
运行大约需要0.14秒。现在这听起来可能不像是一场灾难,但那是每句话0.14秒(我正在制作一个RNN来预测一个句子中的下一个单词)。因为有1436个句子,我们看的是每个时代大约3分20秒。如果我想训练10个时代,那需要半小时。比其他代码需要的更多

有人知道问题出在哪里吗?我能看到的唯一区别是我已经模块化了代码


提前谢谢你的帮助。

我已经弄明白了。每次调用predict方法时,我都在重建图形。相反,在fit方法中,我定义了一个变量:

preds = self.predict(self.tfX)
然后每次我需要预测,而不是使用:

predictions = self.session.run(self.predict(x_batch), feed_dict={...})
我使用:

predictions = self.session.run(self.preds, feed_dict={...})