Skip to content
Related Articles

Related Articles

Improve Article

Python – tensorflow.DeviceSpec

  • Last Updated : 28 Jul, 2020

TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning  neural networks. 

DeviceSpec represents the specification of TensorFlow device. This specification might be partial. If a DeviceSpec is partially specified, it will be merged with other DeviceSpec`s according to the scope in which it is defined.

Syntax: tensorflow.DeviceSpec( job, replica, task, device_type, device_index )

 Parameters:

  • job(optional): It is a string which specifies the job name.
  • replica(optional): It is an integer which specifies the replica index.
  • task(optional): It is an integer which specifies the task index.
  • device_type(optional): It can either be CPU or GPU.
  • device_index(optional): It is an integer which specifies the device index.

Returns: It returns a DeviceSpec object.



Example 1:

Python3




# Importing the library
import tensorflow as tf
  
# Initializing Device Specification
device_spec = tf.DeviceSpec(job ="gfg", device_type ="GPU", device_index = 0)
  
# Printing the result
print('DeviceSpec: ', device_spec)

Output:


DeviceSpec:  <tensorflow.python.framework.device_spec.DeviceSpecV2 object at 0x7fe5c1818ac8>

Example 2:

Python3




# Importing the library
import tensorflow as tf
  
# Initializing Device Specification
device_spec = tf.DeviceSpec(job ="gfg", device_type ="CPU", device_index = 0)
  
# Printing the result
print('DeviceSpec: ', device_spec)

Output:


DeviceSpec:  <tensorflow.python.framework.device_spec.DeviceSpecV2 object at 0x7fe5bb29d888>

 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




My Personal Notes arrow_drop_up
Recommended Articles
Page :