试图理解为什么我的tensorflowgpu导入语句都不起作用

2024-04-20 00:11:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用anaconda在Windowsx64机器上使用tensorflow运行google代码实验室。按照指示做,把模特训练得很好,一切都很好。然后我决定用tensorflow gpu再试一次

所以我卸载了tensorflow,并使用anaconda安装了tensorflow gpu。(康达卸载tensorflow->;康达安装tensorflow gpu)。据推测,Python应该负责cuDNN版本等等。在我的终端中,我可以运行python,在解释器中运行:

>>> import tensorflow as tf
>>> print(tf.__version__)
1.8.0

到目前为止看起来很棒。 我试着

>>> sess = tf.Session()

我的GeForce GTX 1050驱动程序按其应有的方式列出,计算能力为6.1,远高于3.5阈值,因此可以获得很好的长输出

太棒了

但是,当我试图返回并运行代码时,我在tf中使用的其他语句都失败了。 例如,在Tensorflow's GPU documentation中,他们建议运行以下代码来检查GPU是否正常工作:

import tensorflow as tf
print("Num GPUs Available: ", len(tf.config.experimental.list_physical_devices('GPU')))

我的结果是:

>>> print("Num GPUs Available: ", len(tf.config.experimental.list_physical_devices('GPU')))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'tensorflow' has no attribute 'config'

进一步,他们建议启用以下调试:

tf.debugging.set_log_device_placement(True)

我的结果是:

>>> tf.debugging.set_log_device_placement(True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'tensorflow' has no attribute 'debugging'

不用说,当我从codelab返回到原始代码时,除了原始导入语句本身之外,它在使用tf的第一行失败。我是不是错过了一些基本的东西?为什么我的tf命令都不被识别

你知道怎么了吗


Tags: 代码importconfiggputftensorflowasanaconda