📜  Python – tensorflow.DeviceSpec.from_string()

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

Python – tensorflow.DeviceSpec.from_string()

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

from_string用于从字符串生成 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)


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: