Skip to content

Instantly share code, notes, and snippets.

@gavincangan
Forked from jovianlin/get_available_gpus.py
Created July 12, 2018 17:15
Show Gist options
  • Save gavincangan/a930e196e43a9d51edf88e01cf5e8fb9 to your computer and use it in GitHub Desktop.
Save gavincangan/a930e196e43a9d51edf88e01cf5e8fb9 to your computer and use it in GitHub Desktop.
Get List of Devices in TensorFlow
from tensorflow.python.client import device_lib
def get_available_gpus():
local_device_protos = device_lib.list_local_devices()
return [x.name for x in local_device_protos if x.device_type == 'GPU']
get_available_gpus()
@gavincangan
Copy link
Author

Print all devices

from tensorflow.python.client import device_lib
local_device_protos = device_lib.list_local_devices()
print( [ x.name for x in local_device_protos ] )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment