Python – tensorflow.DeviceSpec.make_merged_spec()

Python – tensorflow.DeviceSpec.make_merged_spec()

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

make_merged_spec用于合并两个DeviceSpec的规格。

语法: tensorflow.DeviceSpec.make_merged_spec( dev )

参数:

  • dev:它是DeviceSpec。

返回:它返回一个具有合并规范的DeviceSpec对象。

示例 1:

# Importing the library
import tensorflow as tf
  
# Initializing Device Specification
device_spec = tf.DeviceSpec(job ="gfg", replica = 5)
device_spec2 = tf.DeviceSpec(device_type ="CPU")
  
# Printing the DeviceSpec object
print('Device Spec: ', device_spec)
print('Device Spec2: ', device_spec2)
  
# Getting new DeviceSpec object
new_device_spec = device_spec.make_merged_spec(device_spec2)
  
# Printing the result
print('New Device Spec: ', new_device_spec)

输出:

Device Spec:  <tensorflow.python.framework.device_spec.DeviceSpecV2 object at 0x7fad779e4d08>
Device Spec2:  <tensorflow.python.framework.device_spec.DeviceSpecV2 object at 0x7fadb9428228>
New Device Spec:  <tensorflow.python.framework.device_spec.DeviceSpecV2 object at 0x7fad779e4ca8>

示例 2:

# Importing the library
import tensorflow as tf
  
# Initializing Device Specification
device_spec = tf.DeviceSpec(job ="gfg", replica = 5)
device_spec2 = tf.DeviceSpec(device_type ="CPU", device_index = 2)
  
# Printing the DeviceSpec object
print('Device Spec: ', device_spec)
print('Device Spec2: ', device_spec2)
  
# Getting new DeviceSpec object
new_device_spec = device_spec.make_merged_spec(device_spec2)
  
# Printing the result
print('New Device Spec: ', new_device_spec)

输出:

Device Spec:  <tensorflow.python.framework.device_spec.DeviceSpecV2 object at 0x7fad779e4e28>
Device Spec2:  <tensorflow.python.framework.device_spec.DeviceSpecV2 object at 0x7fad779e4d08>
New Device Spec:  <tensorflow.python.framework.device_spec.DeviceSpecV2 object at 0x7fadb9428228>

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

Tensorflow 数学函数