Python – tensorflow.DeviceSpec.from_string()
TensorFlow 是由 Google 设计的开源Python库,用于开发机器学习模型和深度学习神经网络。
from_string用于从字符串生成 DeviceSpec。
Syntax: tensorflow.DeviceSpec.from_string( spec )
Parameters:
- spec: It is a string of the form /job:/replica:/task:/device:CPU: or /job:/replica:/task:/device:GPU with all entries being optional.
Returns: It returns a DeviceSpec object generated by the string.
示例 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)
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:
示例 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: