jupyter notebook tensorflow打印device信息实例
作者:li_sh1000 发布时间:2021-02-06 09:34:40
标签:jupyter,notebook,tensorflow,device
juypter notebook中直接使用log_device_placement=True打印不出来device信息
# Creates a graph.
with tf.device('/device:CPU:0'):
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
# Creates a session with log_device_placement set to True.
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True,allow_soft_placement=True))
# Runs the op.
print(sess.run(c))
需要使用output_partition_graphs来输出device信息
# Creates a graph.
with tf.device('/device:GPU:0'):
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
# Creates a session with log_device_placement set to True.
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True,allow_soft_placement=True))
# Runs the op.
options = tf.RunOptions(output_partition_graphs=True)
metadata = tf.RunMetadata()
c_val = sess.run(c, options=options, run_metadata=metadata)
print metadata.partition_graphs
补充知识:Jupyter无法在控制台打印
因为数据有中文,所以我特意在jupter前面设置了
reload(sys)
sys.setdefaultencoding("utf-8")
结果使用print语句的时候无法输入内容。究其原因,是因为reload的时候把sdout变为ipython的对象了,所以要临时储存一下stdout的对象。
不妨试一试以下代码
import sys
stdo = sys.stdout
reload(sys)
sys.setdefaultencoding('utf-8')
sys.stdout= stdo
来源:https://blog.csdn.net/li_sh1000/article/details/81586175
0
投稿
猜你喜欢
- 刚刚看了bootstrap的导航栏,发现有点弄混了,现在来整理一下;导航栏是一个很好的功能,是 Bootstrap 网站的一个突出特点。导航
- 注意:自定义函数要放在项目应用目录/common/common.php中。 这里是关键。 模板变量的函数调用格式:{$varname|fun
- 安装显示目录功能:pip install jupyter_contrib_nbextensions配置:安装完之后需要配置 nbextens
- 目录一、熟悉designer——设计界面的神器1.首先打开designer。2.创建窗口3.熟悉各部功能区域二、设计自己的第一个GUI。1.
- 之前使用beego的http库的时候,有的情况需要下载文件。beego是能实现,但就是有点问题:不支持回调,没法显示下载速度,这在日常开发中
- 一、Pylint 是什么Pylint 是一个 Python 代码分析工具,它分析 Python 代码中的错误,查找不符合代码风格标准和有潜在
- $(function(){ var handler = function(){ } var timer = setInterval( han
- 一、DatasetDataset 类提供一种方式去获取数据及其标签主要有两个目的:获取每一个数据及其标签获取数据的总量大小1. 在控制台进行
- background-clip 和 background-origin 是 CSS3 中新加的 background module 属性,用
- 前言在程序中使用字典进行数据信息统计时,由于字典是无序的所以打印字典时内容也是无序的。因此,为了使统计得到的结果更方便查看需要进行排序。Py
- 问题1:如何获取caller的(文件名,行号,函数名)?当新增一条log记录时,最终将调用Logger类的_log方法,这个方法首先会创建一
- 准备图片选择一张shape为(500,500,3)的梵高的《星月夜》以便示例。1. 缩放 cv2.resize()方法cv2.resize(
- 本文实例讲述了php基于curl主动推送最新内容给百度收录的方法。分享给大家供大家参考,具体如下:php curl的好处可以以最快的方式并且
- 本文实例讲述了python实现通过代理服务器访问远程url的方法。分享给大家供大家参考。具体如下:import urllibproxies
- 冷备份是数据库文件的物理备份,通常在数据库通过一个shutdown normal或shutdown immediate 命令正常关闭后进行。
- 在一些微服务或web服务中我们难免需要日志功能,用来记录一些用户的登录记录,操作记录,以及一些程序的崩溃定位,执行访问定位等等;Python
- 平常需要怎么做来维护数据库吗?1. 允许收缩数据库中的每个文件以删除未使用的页。数据和事务日志文件都可以收缩。数据库文件可以作为组或单独地进
- 作为酷爱编程的老程序员,实在按耐不下这个冲动,Python真的是太火了,不断撩拨我的心。我是对Python存有戒备之心的,想当年我基于Dru
- 在MySQL中,事务就是一个逻辑工作单元的一系列步骤。事务是用来保证数据操作的安全性。事务的特征:1.Atomicity(原子性)2.Con
- 前言前面已经讲了MySQL的其他查询性能优化方式,没看过可以去了解一下:MySQL查询性能优化七种方式索引潜水MySQL查询性能优化武器之链