热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Python张量流中的devicespecmake_merged_spec()方法使用说明

本文介绍了在Python张量流中使用make_merged_spec()方法合并设备规格对象的方法和语法,以及参数和返回值的说明,并提供了一个示例代码。

Python–张量流。device spec . make _ merged _ spec()

原文:https://www . geesforgeks . org/python-tensorflow-device spec-make _ merged _ spec/

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

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

语法:张量流。device spec . make _ merged _ spec(dev)

参数:


  • dev: 是 DeviceSpec。

返回:返回合并规格的设备规格对象。

例 1:

Python 3


# 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:

Python 3


# 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>


推荐阅读
author-avatar
沈达浪认_972
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有