Python – tensorflow.DeviceSpec.from_string()
TensorFlow是谷歌设计的开源Python库,用于开发机器学习模型和深度学习神经网络。
from_string用于从字符串生成DeviceSpec。
语法: tensorflow.DeviceSpec.from_string( spec )
参数:
- spec :它是一个形式为/job:/replica:/task:/device:CPU: 或/job:/replica:/task:/device:GPU的字符串,所有条目都是可选的。
返回:它返回一个由字符串生成的DeviceSpec对象。
示例 1:
# Importing the library
import tensorflow as tf
# Formatting the string
spec = '/job:gfg / replica:1 / task:2'
# Initializing Device Specification
device_spec = tf.DeviceSpec.from_string(spec)
# Printing the DeviceSpec object
print('Device Spec: ', device_spec)
输出:
Device Spec: <tensorflow.python.framework.device_spec.DeviceSpecV2 object at 0x7fadb9428168>
示例 2:
# Importing the library
import tensorflow as tf
# Formatting the string
spec = '/job:gfg / replica:2 / task:3'
# Initializing Device Specification
device_spec = tf.DeviceSpec.from_string(spec)
# Printing the DeviceSpec object
print('Device Spec: ', device_spec)
输出:
Device Spec: <tensorflow.python.framework.device_spec.DeviceSpecV2 object at 0x7fadb9428228>