Python – tensorflow.DeviceSpec.replace()
TensorFlow 是由 Google 设计的开源Python库,用于开发机器学习模型和深度学习神经网络。
replace()用于覆盖 DeviceSpec 对象的规范并获取新对象。
Syntax: tensorflow.DeviceSpec.replace(**kwargs)
Parameters:
- **kwargs: This method accepts all the parameters accepted by DeviceSpec constructor.
Returns: It returns a DeviceSpec object.
示例 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.replace(job = "gfg2")
# 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.replace(job = "gfg2", device_type = "CPU")
# Printing the result
print('New Device Spec: ', new_device_spec.to_string())
输出:
Device Spec: /job:gfg/replica:5
New Device Spec: /job:gfg2/replica:5
示例 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.replace(job = "gfg2", device_type = "CPU")
# Printing the result
print('New Device Spec: ', new_device_spec.to_string())
输出:
Device Spec: /job:gfg/replica:5
New Device Spec: /job:gfg2/replica:5/device:CPU:*