首页 > 解决方案 > Tensorflow 1.14 无法使用 python 3.6 检测 GPU,但可以在 Python 2.7 中看到它

问题描述

我正在尝试使用 Mask R-CNN 样本来练习检测和分割模型。我将 python 3.6.8 与 Tensorflow 和 Keras 一起使用,但程序模型仅使用 CPU 开始训练并且无法检测到任何 GPU。同时,Python 2.7 可以看到我的 GPU,如下面的代码所示。

我已经安装了 NVidia 驱动程序 410、CUDA 10.0、cudnn 7.4.2、tensorflow-gpu==1.14.0,并安装了 pip 和 pip3。

为了检查 GPU 是否可用,我使用了小的 python 脚本:

from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())

import tensorflow as tf
tf.test.is_gpu_available()

python的输出:

2019-09-16 12:17:21.621640: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2019-09-16 12:17:21.635692: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcuda.so.1
2019-09-16 12:17:21.720910: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2019-09-16 12:17:21.721429: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x558027aed070 executing computations on platform CUDA. Devices:
2019-09-16 12:17:21.721444: I tensorflow/compiler/xla/service/service.cc:175]   StreamExecutor device (0): GeForce GTX 1060 3GB, Compute Capability 6.1
2019-09-16 12:17:21.741624: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 3408000000 Hz
2019-09-16 12:17:21.742628: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x558027ba37a0 executing computations on platform Host. Devices:
2019-09-16 12:17:21.742663: I tensorflow/compiler/xla/service/service.cc:175]   StreamExecutor device (0): <undefined>, <undefined>
2019-09-16 12:17:21.742937: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2019-09-16 12:17:21.743542: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1640] Found device 0 with properties: 
name: GeForce GTX 1060 3GB major: 6 minor: 1 memoryClockRate(GHz): 1.7845
pciBusID: 0000:01:00.0
2019-09-16 12:17:21.743884: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcudart.so.10.0
2019-09-16 12:17:21.745776: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcublas.so.10.0
2019-09-16 12:17:21.747601: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcufft.so.10.0
2019-09-16 12:17:21.748031: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcurand.so.10.0
2019-09-16 12:17:21.750885: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcusolver.so.10.0
2019-09-16 12:17:21.752588: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcusparse.so.10.0
2019-09-16 12:17:21.757589: I tensorflow/stream_executor/platform/default/dso_loader.cc:42]     Successfully opened dynamic library libcudnn.so.7
2019-09-16 12:17:21.757765: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2019-09-16 12:17:21.758440: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2019-09-16 12:17:21.759102: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1763] Adding visible gpu devices: 0
2019-09-16 12:17:21.759173: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcudart.so.10.0
2019-09-16 12:17:21.760528: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1181] Device interconnect StreamExecutor with strength 1 edge matrix:
2019-09-16 12:17:21.760553: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1187]      0 
2019-09-16 12:17:21.760564: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1200] 0:   N 
2019-09-16 12:17:21.760807: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2019-09-16 12:17:21.761483: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2019-09-16 12:17:21.762083: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1326] Created TensorFlow device (/device:GPU:0 with 2287 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1060 3GB, pci bus id: 0000:01:00.0, compute capability: 6.1)
[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 13231116977719504797
, name: "/device:XLA_GPU:0"
device_type: "XLA_GPU"
memory_limit: 17179869184
locality {
}
incarnation: 2220022223072533235
physical_device_desc: "device: XLA_GPU device"
, name: "/device:XLA_CPU:0"
device_type: "XLA_CPU"
memory_limit: 17179869184
locality {
}
incarnation: 579036656168733531
physical_device_desc: "device: XLA_CPU device"
, name: "/device:GPU:0"
device_type: "GPU"
memory_limit: 2398158848
locality {
  bus_id: 1
  links {
  }
}
incarnation: 14902085726432239020
physical_device_desc: "device: 0, name: GeForce GTX 1060 3GB, pci bus id: 0000:01:00.0, compute capability: 6.1"
]

python3的输出:

WARNING: Logging before flag parsing goes to stderr.
W0916 12:10:46.067314 140410557671232 __init__.py:308] Limited tf.compat.v2.summary API due to missing TensorBoard installation.
2019-09-16 12:10:46.084425: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2019-09-16 12:10:46.113540: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 3408000000 Hz
2019-09-16 12:10:46.114038: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x495fd00 executing computations on platform Host. Devices:
2019-09-16 12:10:46.114054: I tensorflow/compiler/xla/service/service.cc:175]   StreamExecutor device (0): <undefined>, <undefined>
[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 5355211451834126024
, name: "/device:XLA_CPU:0"
device_type: "XLA_CPU"
memory_limit: 17179869184
locality {
}
incarnation: 8307771055363446310
physical_device_desc: "device: XLA_CPU device"
]

我在哪里犯了错误以及如何解决此问题并检测 Python3 的 GPU?

标签: pythonpython-3.xtensorflow

解决方案


推荐阅读