Python – tensorflow.DeviceSpec.replica 属性
TensorFlow 是由 Google 设计的开源Python库,用于开发机器学习模型和深度学习神经网络。
replica用于获取 DeviceSpec 的副本索引。
Syntax: tensorflow.DeviceSpec.replica
Returns: It returns the replica index of the DeviceSpec.
示例 1:
Python3
# Importing the library
import tensorflow as tf
# Initializing Device Specification
device_spec = tf.DeviceSpec(job ="gfg2", device_type ="GPU", device_index = 1)
# Printing the DeviceSpec object
print('Device Spec: ', device_spec)
# Getting replica index
replica = device_spec.replica
# Printing the result
print('Replica: ', replica)
Python3
# Importing the library
import tensorflow as tf
# Initializing Device Specification
device_spec = tf.DeviceSpec(job ="gfg2", replica = 5, device_type ="GPU", device_index = 1)
# Printing the DeviceSpec object
print('Device Spec: ', device_spec)
# Getting replica index
replica = device_spec.replica
# Printing the result
print('Replica: ', replica)
输出:
Device Spec:
Replica: None
示例 2:
Python3
# Importing the library
import tensorflow as tf
# Initializing Device Specification
device_spec = tf.DeviceSpec(job ="gfg2", replica = 5, device_type ="GPU", device_index = 1)
# Printing the DeviceSpec object
print('Device Spec: ', device_spec)
# Getting replica index
replica = device_spec.replica
# Printing the result
print('Replica: ', replica)
输出:
Device Spec:
Replica: 5