📜  Python – tensorflow.DeviceSpec.to_string()

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

Python – tensorflow.DeviceSpec.to_string()

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

to_string()用于获取 DeviceSpec 对象规范的字符串表示。

示例 1:

Python3
# Importing the library
import tensorflow as tf
  
# Initializing Device Specification
device_spec = tf.DeviceSpec(job ="gfg", replica = 5)
  
# Printing the DeviceSpec 
print('Device Spec: ', device_spec.to_string())


Python3
# Importing the library
import tensorflow as tf
  
# Initializing Device Specification
device_spec = tf.DeviceSpec(job ="gfg", replica = 5, device_type = "CPU")
  
# Printing the DeviceSpec 
print('Device Spec: ', device_spec.to_string())


输出:

Device Spec:  /job:gfg/replica:5

示例 2:

Python3

# Importing the library
import tensorflow as tf
  
# Initializing Device Specification
device_spec = tf.DeviceSpec(job ="gfg", replica = 5, device_type = "CPU")
  
# Printing the DeviceSpec 
print('Device Spec: ', device_spec.to_string())

输出:

Device Spec:  /job:gfg/replica:5/device:CPU:*