TensorFlow是Google設計的開源Python庫,用於開發機器學習模型和深度學習神經網絡。
replace()用於覆蓋DeviceSpec對象的規範並獲取新對象。
用法:tensorflow.DeviceSpec.replace(**kwargs)
參數:
- **kwargs:此方法接受DeviceSpec構造函數接受的所有參數。
返回值:它返回一個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.replace(job = "gfg2")
# 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:*
相關用法
注:本文由純淨天空篩選整理自aman neekhara大神的英文原創作品 Python – tensorflow.DeviceSpec.replace()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。