gpt4 book ai didi

python - 导入错误 : No module named 'tensorflow.python' with tensorflow-gpu

转载 作者:太空狗 更新时间:2023-10-29 21:54:08 25 4
gpt4 key购买 nike

我想为 keras/tensorflow 提供 gpu 支持,这就是我安装 tensorflow-gpu 的原因。所以我通过pip安装了tensorflow-gpu:

pip install --upgrade tensorflow-gpu

这导致:

from keras import backend as K
K.tensorflow_backend._get_available_gpus()
> []

然后我找到this stackoverflow answer这说明我应该在安装 tensorflow-gpu 后卸载 tensorflow。这导致:

Using TensorFlow backend.
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-3d00d838479b> in <module>()
----> 1 from keras import backend as K
2 K.tensorflow_backend._get_available_gpus()

/raid/ntzioras/VirtualEnvironments/DeepLearning/lib/python3.4/site-packages/keras/__init__.py in <module>()
1 from __future__ import absolute_import
2
----> 3 from . import utils
4 from . import activations
5 from . import applications

/raid/ntzioras/VirtualEnvironments/DeepLearning/lib/python3.4/site-packages/keras/utils/__init__.py in <module>()
4 from . import data_utils
5 from . import io_utils
----> 6 from . import conv_utils
7
8 # Globally-importable utils.

/raid/ntzioras/VirtualEnvironments/DeepLearning/lib/python3.4/site-packages/keras/utils/conv_utils.py in <module>()
7 from six.moves import range
8 import numpy as np
----> 9 from .. import backend as K
10
11

/raid/ntzioras/VirtualEnvironments/DeepLearning/lib/python3.4/site-packages/keras/backend/__init__.py in <module>()
82 elif _BACKEND == 'tensorflow':
83 sys.stderr.write('Using TensorFlow backend.\n')
---> 84 from .tensorflow_backend import *
85 else:
86 raise ValueError('Unknown backend: ' + str(_BACKEND))

/raid/ntzioras/VirtualEnvironments/DeepLearning/lib/python3.4/site-packages/keras/backend/tensorflow_backend.py in <module>()
4
5 import tensorflow as tf
----> 6 from tensorflow.python.training import moving_averages
7 from tensorflow.python.ops import tensor_array_ops
8 from tensorflow.python.ops import control_flow_ops

ImportError: No module named 'tensorflow.python'

重新安装tensorflow

pip install --upgrade tensorflow --no-cache

使用上面的代码再次导致 gpus 的空数组。

有什么办法解决这个问题吗?

最佳答案

这个解决方案对我有用:

同时卸载 CPU 和 GPU 版本的 TensorFlow,然后仅安装 GPU 版本的 TensorFlow。

pip uninstall tensorflow
pip uninstall tensorflow-gpu

pip install tensorflow-gpu

关于python - 导入错误 : No module named 'tensorflow.python' with tensorflow-gpu,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49432451/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com