我希望为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()
> []
然后我发现了这个stackoverflow答案,它指出在安装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
使用以上代码重新安装后,GPU数组仍为空。
有什么好的办法可以解决这个问题吗?