📜  Python – tensorflow.DeviceSpec.task 属性

📅  最后修改于: 2022-05-13 01:54:23.408000             🧑  作者: Mango

Python – tensorflow.DeviceSpec.task 属性

TensorFlow 是由 Google 设计的开源Python库,用于开发机器学习模型和深度学习神经网络。

task用于获取 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