Python – tensorflow.DeviceSpec.task 属性
TensorFlow 是由 Google 设计的开源Python库,用于开发机器学习模型和深度学习神经网络。
task用于获取 DeviceSpec 的任务索引。
Syntax: tensorflow.DeviceSpec.task
Returns: It returns the task index of DeviceSpec
示例 1:
Python3
# 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)
Python3
# 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)
输出:
Device Spec:
Task Index: None
示例 2:
Python3
# 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)
输出:
Device Spec:
Task Index: 2