Python – tensorflow.device()
TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning neural networks.
device() is used to explicitly specify the device in which operation should be performed.
Syntax: tensorflow.device( device_name )
- device_name: It specifies the device name to be used in this context.
Returns: It returns a context manager that specifies the default device to use for newly created ops.
Device Spec: /job:localhost/replica:0/device:CPU:* Executing op MatMul in device /job:localhost/replica:0/task:0/device:CPU:0
Example 2: In this example device specification specifies GPU to be used but system couldn’t find GPU so it will run the operation on CPU.
Device Spec: /job:localhost/replica:0/device:GPU:* Executing op MatMul in device /job:localhost/replica:0/task:0/device:CPU:0
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course