tensorflow 使用CPU而不使用GPU的問題解決

今天發現一個怪現象,在訓練keras時,發現不使用GPU進行計算,而是採用CPU進行計算,致使計算速度很慢。python

用以下代碼可檢測tensorflow的能使用設備狀況:url

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

可用設備爲:spa

[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}]  

原來只有一個CPU設備可用了。因而檢查下tensorflow的版本狀況:code

pip3 list

各應用版本爲:blog

tensorflow          1.10.1 
tensorflow-gpu      1.9.0 

原來我升級了tensorflow版本,忘記了升級tensorflow-gpu版本,如今兩個版本有代差,而tensorflow默認選擇版本高的CPU版原本計算了。ip

那就升級tensorflow-gpu吧:ci

pip3 install --index-url http://pypi.douban.com/simple --trusted-host pypi.douban.com --upgrade tensorflow-gpu

再次檢測可用設備狀況,結果以下:it

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.7085
pciBusID: 0000:01:00.0
totalMemory: 4.94GiB freeMemory: 4.23GiB
2018-09-04 10:51:22.996666: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1484] Adding visible gpu devices: 0
2018-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)
[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 15761951721866580392
, name: "/device:GPU:0"
device_type: "GPU"
memory_limit: 4161994752
locality {
  bus_id: 1
  links {
  }
}
incarnation: 16066826866269340415
physical_device_desc: "device: 0, name: GeForce GTX 1060 5GB, pci bus id: 0000:01:00.0, compute capability: 6.1"
]
相關文章
相關標籤/搜索