Python Tensorflow gpu 1.15不使用gpu

Python Tensorflow gpu 1.15不使用gpu,python,tensorflow,ubuntu-20.04,Python,Tensorflow,Ubuntu 20.04,我有一个安装了Ubuntu20.04的系统,因此为Tensorflow获得CUDA和cudnn的正确组合似乎有点棘手。我尝试了CUDA11,但无法使cudnn正常工作,因此我通过sudo-apt-install-nvidia-cuda-toolkit安装了CUDA10.1以及相应的cudnn(7.6.5)()。现在,当我安装Tensorflow gpu 2时,我可以轻松地检查它是否将gpu用作: import tensorflow as tf print("Num GPUs Avail

我有一个安装了Ubuntu20.04的系统,因此为Tensorflow获得CUDA和cudnn的正确组合似乎有点棘手。我尝试了CUDA11,但无法使cudnn正常工作,因此我通过
sudo-apt-install-nvidia-cuda-toolkit
安装了CUDA10.1以及相应的cudnn(7.6.5)()。现在,当我安装Tensorflow gpu 2时,我可以轻松地检查它是否将gpu用作:

import tensorflow as tf
print("Num GPUs Available: ", len(tf.config.experimental.list_physical_devices('GPU'))) 
它给出了正确的输出
2
。但是我需要使用Tensorflow-gpu-1.15。有了这个,我根据答案尝试了以下方法:

它给出了以下输出:

2020-07-11 14:05:53.181428: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-07-11 14:05:53.183404: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 0 with properties: 
name: GeForce GTX 1080 Ti major: 6 minor: 1 memoryClockRate(GHz): 1.582
pciBusID: 0000:01:00.0
2020-07-11 14:05:53.183598: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-07-11 14:05:53.185222: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 1 with properties: 
name: GeForce GTX 1080 major: 6 minor: 1 memoryClockRate(GHz): 1.7335
pciBusID: 0000:02:00.0
2020-07-11 14:05:53.185548: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcudart.so.10.0'; dlerror: libcudart.so.10.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/lib/cuda/include:/usr/lib/cuda/lib64:
2020-07-11 14:05:53.185790: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcublas.so.10.0'; dlerror: libcublas.so.10.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/lib/cuda/include:/usr/lib/cuda/lib64:
2020-07-11 14:05:53.186015: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcufft.so.10.0'; dlerror: libcufft.so.10.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/lib/cuda/include:/usr/lib/cuda/lib64:
2020-07-11 14:05:53.186237: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcurand.so.10.0'; dlerror: libcurand.so.10.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/lib/cuda/include:/usr/lib/cuda/lib64:
2020-07-11 14:05:53.186459: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcusolver.so.10.0'; dlerror: libcusolver.so.10.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/lib/cuda/include:/usr/lib/cuda/lib64:
2020-07-11 14:05:53.186578: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcusparse.so.10.0'; dlerror: libcusparse.so.10.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/lib/cuda/include:/usr/lib/cuda/lib64:
2020-07-11 14:05:53.186594: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7
2020-07-11 14:05:53.186601: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1641] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices...
2020-07-11 14:05:53.187652: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1159] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-07-11 14:05:53.187669: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1165]      
Traceback (most recent call last):
  File "/home/mo/anaconda3/envs/lf/lib/python3.6/site-packages/tensorflow_core/python/client/session.py", line 1365, in _do_call
return fn(*args)
  File "/home/mo/anaconda3/envs/lf/lib/python3.6/site-packages/tensorflow_core/python/client/session.py", line 1348, in _run_fn
self._extend_graph()
  File "/home/mo/anaconda3/envs/lf/lib/python3.6/site-packages/tensorflow_core/python/client/session.py", line 1388, in _extend_graph
    tf_session.ExtendSession(self._session)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Cannot assign a device for operation MatMul: {{node MatMul}} was explicitly assigned to /device:GPU:0 but available devices are [ /job:localhost/replica:0/task:0/device:CPU:0, /job:localhost/replica:0/task:0/device:XLA_CPU:0, /job:localhost/replica:0/task:0/device:XLA_GPU:0, /job:localhost/replica:0/task:0/device:XLA_GPU:1 ]. Make sure the device specification refers to a valid device.
 [[MatMul]]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/home/mo/anaconda3/envs/lf/lib/python3.6/site-packages/tensorflow_core/python/client/session.py", line 956, in run
run_metadata_ptr)
  File "/home/mo/anaconda3/envs/lf/lib/python3.6/site-packages/tensorflow_core/python/client/session.py", line 1180, in _run
feed_dict_tensor, options, run_metadata)
  File "/home/mo/anaconda3/envs/lf/lib/python3.6/site-packages/tensorflow_core/python/client/session.py", line 1359, in _do_run
run_metadata)
  File "/home/mo/anaconda3/envs/lf/lib/python3.6/site-packages/tensorflow_core/python/client/session.py", line 1384, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Cannot assign a device for operation MatMul: node MatMul (defined at /home/mo/anaconda3/envs/lf/lib/python3.6/site-packages/tensorflow_core/python/framework/ops.py:1748)  was explicitly assigned to /device:GPU:0 but available devices are [ /job:localhost/replica:0/task:0/device:CPU:0, /job:localhost/replica:0/task:0/device:XLA_CPU:0, /job:localhost/replica:0/task:0/device:XLA_GPU:0, /job:localhost/replica:0/task:0/device:XLA_GPU:1 ]. Make sure the device specification refers to a valid device.
 [[MatMul]]
2020-07-11 14:05:53.181428:I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983]从SysFS读取的成功NUMA节点的值为负值(-1),但必须至少有一个NUMA节点,因此返回NUMA节点零
2020-07-11 14:05:53.183404:I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618]找到了具有以下属性的设备0:
名称:GeForce GTX 1080 Ti大调:6小调:1记忆锁定率(GHz):1.582
pciBusID:0000:01:00.0
2020-07-11 14:05:53.183598:I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983]从SysFS读取的成功NUMA节点的值为负值(-1),但必须至少有一个NUMA节点,因此返回NUMA节点零
2020-07-11 14:05:53.185222:I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618]找到了具有以下属性的设备1:
名称:GeForce GTX 1080大调:6小调:1记忆锁定速率(GHz):1.7335
pciBusID:0000:02:00.0
2020-07-11 14:05:53.185548:W tensorflow/stream_executor/platform/default/dso_loader.cc:55]无法加载动态库“libcudart.so.10.0”;dError:libcudart.so.10.0:无法打开共享对象文件:没有此类文件或目录;LD_LIBRARY_路径:/usr/lib/cuda/include:/usr/lib/cuda/lib64:
2020-07-11 14:05:53.185790:W tensorflow/stream_executor/platform/default/dso_loader.cc:55]无法加载动态库'libcublas.so.10.0';dError:libcublas.so.10.0:无法打开共享对象文件:没有此类文件或目录;LD_LIBRARY_路径:/usr/lib/cuda/include:/usr/lib/cuda/lib64:
2020-07-11 14:05:53.186015:W tensorflow/stream_executor/platform/default/dso_loader.cc:55]无法加载动态库“libcuft.so.10.0”;dlerror:libcuft.so.10.0:无法打开共享对象文件:没有此类文件或目录;LD_LIBRARY_路径:/usr/lib/cuda/include:/usr/lib/cuda/lib64:
2020-07-11 14:05:53.186237:W tensorflow/stream_executor/platform/default/dso_loader.cc:55]无法加载动态库'libcurand.so.10.0';dError:libcurand.so.10.0:无法打开共享对象文件:没有此类文件或目录;LD_LIBRARY_路径:/usr/lib/cuda/include:/usr/lib/cuda/lib64:
2020-07-11 14:05:53.186459:W tensorflow/stream_executor/platform/default/dso_loader.cc:55]无法加载动态库“libcusolver.so.10.0”;dlerror:libcusolver.so.10.0:无法打开共享对象文件:没有此类文件或目录;LD_LIBRARY_路径:/usr/lib/cuda/include:/usr/lib/cuda/lib64:
2020-07-11 14:05:53.186578:W tensorflow/stream_executor/platform/default/dso_loader.cc:55]无法加载动态库'libcusparse.so.10.0';dlerror:libcusparse.so.10.0:无法打开共享对象文件:没有此类文件或目录;LD_LIBRARY_路径:/usr/lib/cuda/include:/usr/lib/cuda/lib64:
2020-07-11 14:05:53.186594:I tensorflow/stream_executor/platform/default/dso_loader.cc:44]成功打开了动态库libcudnn.so.7
2020-07-11 14:05:53.186601:W tensorflow/core/common_runtime/gpu/gpu_device.cc:1641]无法打开某些gpu库。如果您想使用GPU,请确保正确安装了上述缺失的库。请按照以下指南操作:https://www.tensorflow.org/install/gpu 了解如何下载和设置平台所需的库。
正在跳过注册GPU设备。。。
2020-07-11 14:05:53.187652:I tensorflow/core/common_runtime/gpu/gpu_设备cc:1159]设备互连拖缆执行器与强度1边缘矩阵:
2020-07-11 14:05:53.187669:I tensorflow/core/common_runtime/gpu/gpu_device.cc:1165]
回溯(最近一次呼叫最后一次):
文件“/home/mo/anaconda3/envs/lf/lib/python3.6/site packages/tensorflow\u core/python/client/session.py”,第1365行,在调用中
返回fn(*args)
文件“/home/mo/anaconda3/envs/lf/lib/python3.6/site packages/tensorflow\u core/python/client/session.py”,第1348行,在
self.\u扩展图()
文件“/home/mo/anaconda3/envs/lf/lib/python3.6/site packages/tensorflow\u core/python/client/session.py”,第1388行,在扩展图中
TFU会话。扩展会话(自会话)
tensorflow.python.framework.errors\u impl.InvalidArgumentError:无法为操作分配设备MatMul:{{node MatMul}}已显式分配给/device:GPU:0,但可用设备为[/job:localhost/replica:0/task:0/device:CPU:0,/job:localhost/replica:0/task:0/device:XLA\u-CPU:0,/job:localhost/replica:0/device:XLA\u-GPU:0,/job:localhost/replica:0/task:0/device:XLA\u-GPU:1]。确保设备规范引用了有效的设备。
[[MatMul]]
在处理上述异常期间,发生了另一个异常:
回溯(最近一次呼叫最后一次):
文件“”,第2行,在
文件“/home/mo/anaconda3/envs/lf/lib/python3.6/site packages/tensorflow_core/python/client/session.py”,第956行,正在运行
运行_元数据_ptr)
文件“/home/mo/anaconda3/envs/lf/lib/python3.6/site packages/tensorflow\u core/python/client/session.py”,第1180行,正在运行
feed_dict_tensor、options、run_元数据)
文件“/home/mo/anaconda3/envs/lf/lib/python3.6/site packages/tensorflow\u core/python/client/session.py”,第1359行,在运行中
运行(元数据)
文件“/home/mo/anaconda3/envs/lf/lib/python3.6/site packages/tensorflow\u core/python/client/session.py”,第1384行,在调用中
提升类型(e)(节点定义、操作、消息)
tensorflow.python.framework.errors\u impl.InvalidArgumentError:无法为操作分配设备MatMul:节点MatMul(在/home/mo/anaconda3/envs/lf/lib/python3.6/site packages/tensorflow_core/python/framework/ops.py:1748中定义)已显式分配给/device:GP
2020-07-11 14:05:53.181428: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-07-11 14:05:53.183404: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 0 with properties: 
name: GeForce GTX 1080 Ti major: 6 minor: 1 memoryClockRate(GHz): 1.582
pciBusID: 0000:01:00.0
2020-07-11 14:05:53.183598: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-07-11 14:05:53.185222: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 1 with properties: 
name: GeForce GTX 1080 major: 6 minor: 1 memoryClockRate(GHz): 1.7335
pciBusID: 0000:02:00.0
2020-07-11 14:05:53.185548: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcudart.so.10.0'; dlerror: libcudart.so.10.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/lib/cuda/include:/usr/lib/cuda/lib64:
2020-07-11 14:05:53.185790: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcublas.so.10.0'; dlerror: libcublas.so.10.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/lib/cuda/include:/usr/lib/cuda/lib64:
2020-07-11 14:05:53.186015: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcufft.so.10.0'; dlerror: libcufft.so.10.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/lib/cuda/include:/usr/lib/cuda/lib64:
2020-07-11 14:05:53.186237: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcurand.so.10.0'; dlerror: libcurand.so.10.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/lib/cuda/include:/usr/lib/cuda/lib64:
2020-07-11 14:05:53.186459: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcusolver.so.10.0'; dlerror: libcusolver.so.10.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/lib/cuda/include:/usr/lib/cuda/lib64:
2020-07-11 14:05:53.186578: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcusparse.so.10.0'; dlerror: libcusparse.so.10.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/lib/cuda/include:/usr/lib/cuda/lib64:
2020-07-11 14:05:53.186594: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7
2020-07-11 14:05:53.186601: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1641] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices...
2020-07-11 14:05:53.187652: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1159] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-07-11 14:05:53.187669: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1165]      
Traceback (most recent call last):
  File "/home/mo/anaconda3/envs/lf/lib/python3.6/site-packages/tensorflow_core/python/client/session.py", line 1365, in _do_call
return fn(*args)
  File "/home/mo/anaconda3/envs/lf/lib/python3.6/site-packages/tensorflow_core/python/client/session.py", line 1348, in _run_fn
self._extend_graph()
  File "/home/mo/anaconda3/envs/lf/lib/python3.6/site-packages/tensorflow_core/python/client/session.py", line 1388, in _extend_graph
    tf_session.ExtendSession(self._session)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Cannot assign a device for operation MatMul: {{node MatMul}} was explicitly assigned to /device:GPU:0 but available devices are [ /job:localhost/replica:0/task:0/device:CPU:0, /job:localhost/replica:0/task:0/device:XLA_CPU:0, /job:localhost/replica:0/task:0/device:XLA_GPU:0, /job:localhost/replica:0/task:0/device:XLA_GPU:1 ]. Make sure the device specification refers to a valid device.
 [[MatMul]]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/home/mo/anaconda3/envs/lf/lib/python3.6/site-packages/tensorflow_core/python/client/session.py", line 956, in run
run_metadata_ptr)
  File "/home/mo/anaconda3/envs/lf/lib/python3.6/site-packages/tensorflow_core/python/client/session.py", line 1180, in _run
feed_dict_tensor, options, run_metadata)
  File "/home/mo/anaconda3/envs/lf/lib/python3.6/site-packages/tensorflow_core/python/client/session.py", line 1359, in _do_run
run_metadata)
  File "/home/mo/anaconda3/envs/lf/lib/python3.6/site-packages/tensorflow_core/python/client/session.py", line 1384, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Cannot assign a device for operation MatMul: node MatMul (defined at /home/mo/anaconda3/envs/lf/lib/python3.6/site-packages/tensorflow_core/python/framework/ops.py:1748)  was explicitly assigned to /device:GPU:0 but available devices are [ /job:localhost/replica:0/task:0/device:CPU:0, /job:localhost/replica:0/task:0/device:XLA_CPU:0, /job:localhost/replica:0/task:0/device:XLA_GPU:0, /job:localhost/replica:0/task:0/device:XLA_GPU:1 ]. Make sure the device specification refers to a valid device.
 [[MatMul]]