今天发现一个怪现象,在训练keras时,发现不使用GPU进行计算,而是采用CPU进行计算,导致计算速度很慢。用如下代码可检测tensorflow的能使用设备情况:
fromtensorflow.python.client importdevice_lib
print(device_lib.list_local_devices())
可用设备为:
[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}]
原来只有一个CPU设备可用了。于是检查下tensorflow的版本情况:
pip3 list
各应用版本为:
tensorflow 1.6.0
tensorflow-gpu 1.6.0
原来两个tf版本一样,则默认使用cpu版本,另外,如果两个版本有代差,则tensorflow默认选择版本高版本来计算。我把cpu版本的卸载了,再次检测可用设备情况,结果如下,可见可以使用GPU版本了:
2018-09-04 10:51:22.996654: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1405] Found device 0 with properties:
name: GeForce GTX 1060 5GB major: 6 minor: 1 memoryClockRate(GHz): 1.7085pciBusID: 0000:01:00.0totalMemory: 4.94GiB freeMemory: 4.23GiB2018-09-04 10:51:22.996666: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1484] Adding visible gpu devices: 02018-09-04 10:51:23.189923: I tensorflow/core/common_runtime/gpu/gpu_device.cc:965] Device interconnect StreamExecutor with strength 1 edge matrix:2018-09-04 10:51:23.189953: I tensorflow/core/common_runtime/gpu/gpu_device.cc:971] 0 2018-09-04 10:51:23.189959: I tensorflow/core/common_runtime/gpu/gpu_device.cc:984] 0: N 2018-09-04 10:51:23.190105: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1097] Created TensorFlow device (/device:GPU:0 with 3969 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1060 5GB, pci bus id: 0000:01:00.0, compute capability: 6.1)
incarnation: 15761951721866580392, name: "/device:GPU:0"device_type: "GPU"memory_limit: 4161994752locality {
bus_id: 1 links {
}
}
incarnation: 16066826866269340415physical_device_desc: "device: 0, name: GeForce GTX 1060 5GB, pci bus id: 0000:01:00.0, compute capability: 6.1"]
网友评论