Python – tensorflow.DeviceSpec.task Attribute

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

task is used to get the task index of DeviceSpec.

Syntax: tensorflow.DeviceSpec.task

Returns: It returns the task index of DeviceSpec

Example 1:



Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# Importing the library
import tensorflow as tf
  
# Initializing Device Specification
device_spec = tf.DeviceSpec(job ="gfg2", replica = 5, device_type ="GPU", device_index = 1)
  
# Printing the DeviceSpec object
print('Device Spec: ', device_spec)
  
# Getting task index
task = device_spec.task
  
# Printing the result
print('Task Index: ', task)

chevron_right


Output:

Device Spec:  <tensorflow.python.framework.device_spec.DeviceSpecV2 object at 0x7fe5ba981d08>
Task Index:  None

Example 2:

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# Importing the library
import tensorflow as tf
  
# Initializing Device Specification
device_spec = tf.DeviceSpec(job ="gfg2", replica = 5, task = 2, device_type ="GPU", device_index = 1)
  
# Printing the DeviceSpec object
print('Device Spec: ', device_spec)
  
# Getting task index
task = device_spec.task
  
# Printing the result
print('Task Index: ', task)

chevron_right


Output:

Device Spec:  <tensorflow.python.framework.device_spec.DeviceSpecV2 object at 0x7fe5ba91a708>
Task Index:  2


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.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.