📜  Python – tensorflow.DeviceSpec.parse_from_string()

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

Python – tensorflow.DeviceSpec.parse_from_string()

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

parse_from_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())
  
# Getting new DeviceSpec object
new_device_spec = device_spec.parse_from_string("/GPU:0")
  
# Printing the result
print('New Device Spec: ', new_device_spec.to_string())


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())
  
# Getting new DeviceSpec object
new_device_spec = device_spec.parse_from_string("replica:2 / GPU:0")
  
# Printing the result
print('New Device Spec: ', new_device_spec.to_string())


输出:

Device Spec:  /job:gfg/replica:5
New Device Spec:  /device:GPU:0

示例 2:

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())
  
# Getting new DeviceSpec object
new_device_spec = device_spec.parse_from_string("replica:2 / GPU:0")
  
# Printing the result
print('New Device Spec: ', new_device_spec.to_string())

输出:

Device Spec:  /job:gfg/replica:5
New Device Spec:  /replica:2/device:GPU:0