Python – tensorflow.DeviceSpec
TensorFlow 是由 Google 设计的开源Python库,用于开发机器学习模型和深度学习神经网络。
DeviceSpec表示 TensorFlow 设备的规格。该规范可能是部分的。如果一个 DeviceSpec 被部分指定,它将根据定义的范围与其他 DeviceSpec 合并。
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.
示例 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)
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)
输出:
DeviceSpec:
示例 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)
输出:
DeviceSpec: