Skip to content
Related Articles

Related Articles

Python – tensorflow.DeviceSpec

View Discussion
Improve Article
Save Article
  • Last Updated : 28 Jul, 2020
View Discussion
Improve Article
Save Article

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>

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!