如果安装了CUDAnn v10.1后,Tensorflow仍未在GPU上运行,可以尝试以下解决方法:
import tensorflow as tf
print(tf.__version__)
print(tf.test.is_built_with_cuda())
print(tf.test.is_gpu_available(cuda_only=True))
确保输出中的版本与安装的版本一致,并且GPU可用。
import os
print(os.environ['CUDA_HOME'])
print(os.environ['CUDNN_HOME'])
确保输出中的路径与CUDAnn安装路径一致。
pip uninstall tensorflow
pip install tensorflow-gpu
确保在重新安装之前卸载了之前的Tensorflow版本。
import tensorflow as tf
physical_devices = tf.config.experimental.list_physical_devices('GPU')
tf.config.experimental.set_memory_growth(physical_devices[0], True)
确保将physical_devices[0]
替换为正确的GPU设备索引。
通过以上步骤,应该能够解决Tensorflow未在GPU上运行的问题。如果问题仍然存在,可能需要检查系统和驱动程序的兼容性,并确保正确安装了所有依赖项。