TensorFlow是Google设计的开源Python库,用于开发机器学习模型和深度学习神经网络。
from_string用于从字符串生成DeviceSpec。
用法:tensorflow.DeviceSpec.from_string( spec )
参数:
- spec:它是/job:/副本:/task:/device:CPU:或/job:/replica:/task:/device:GPU形式的字符串,所有条目都是可选的。
返回值:它返回由字符串生成的DeviceSpec对象。
范例1:
Python3
# 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:
Python3
# 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>
相关用法
注:本文由纯净天空筛选整理自aman neekhara大神的英文原创作品 Python – tensorflow.DeviceSpec.from_string()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。