【转载】 tf.Print() (------------ tensorflow中的print函数)
原文地址:
https://blog.csdn.net/weixin_36670529/article/details/100191674
----------------------------------------------------------------------------------------------
调试程序的时候,经常会需要检查中间的参数,这些参数一般是定义在model或是别的函数中的局部参数,由于tensorflow要求先构建计算图再运算的机制,也不能定义后直接print出来。tensorflow有一个函数tf.Print()。
tf.Print(input, data, message=None, first_n=None, summarize=None, name=None)
最低要求两个输入,input和data,input是需要打印的变量的名字,data要求是一个list,里面包含要打印的内容。
参数:
- message是需要输出的错误信息
- first_n指只记录(打log日志)前n次
- summarize是对每个tensor只打印的条目数量,如果是None,对于每个输入tensor只打印3个元素
- name是op的名字
需要注意的是tf.Print()只是构建一个op,需要run之后才会打印。
例子:
x=tf.constant([2,3,4,5])
y=tf.Print(x,[x,x.shape,'test', x],message='Debug message:',summarize=100) with tf.Session() as sess:
sess.run(y) #Debug message:[2 3 4 5][4][test][2 3 4 5] z=tf.Print(x,[x,x.shape,'test', x],message='Debug message:',summarize=2) with tf.Session() as sess:
sess.run(z) #Debug message:[2 3...][4][test][2 3...]
输出是在命令窗口中,和print有区别
x=tf.constant([2,3,4,5])
with tf.Session() as sess:
print(sess.run(x))
#[2,3,4,5]
————————————————
版权声明:本文为CSDN博主「于小勇」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_36670529/article/details/100191674
附:

Print(input_, data, message=None, first_n=None, summarize=None, name=None)
Prints a list of tensors.
This is an identity op with the side effect of printing `data` when
evaluating.
Args:
input_: A tensor passed through this op.
data: A list of tensors to print out when op is evaluated.
message: A string, prefix of the error message.
first_n: Only log `first_n` number of times. Negative numbers log always;
this is the default.
summarize: Only print this many entries of each tensor. If None, then a
maximum of 3 elements are printed per input tensor.
name: A name for the operation (optional).
Returns:
Same tensor as `input_`.
【转载】 tf.Print() (------------ tensorflow中的print函数)的更多相关文章
- TensorFlow中的卷积函数
前言 最近尝试看TensorFlow中Slim模块的代码,看的比较郁闷,所以试着写点小的代码,动手验证相关的操作,以增加直观性. 卷积函数 slim模块的conv2d函数,是二维卷积接口,顺着源代码可 ...
- Tensorflow中的run()函数
1 run()函数存在的意义 run()函数可以让代码变得更加简洁,在搭建神经网络(一)中,经历了数据集准备.前向传播过程设计.损失函数及反向传播过程设计等三个过程,形成计算网络,再通过会话tf.Se ...
- 【转载】jQuery动画中的queue()函数
原文链接:http://www.cnblogs.com/hh54188/archive/2011/04/09/1996469.html 原文摘要:当你使用一系列的动画效果(如hide,show),这些 ...
- [ 转载 ]hashCode及HashMap中的hash()函数
hashCode及HashMap中的hash()函数 一.hashcode是什么 要理解hashcode首先要理解hash表这个概念 1. 哈希表 hash表也称散列表(Hash table),是 ...
- 对于tensorflow中的gradient_override_map函数的理解
# #############添加############## def binarize(self, x): """ Clip and binarize tensor u ...
- Tensorflow中的transpose函数解析
transpose函数作用是对矩阵进行转换操作 相信说完上面这一句,大家和我一样都是懵逼状态,完全不知道是怎么回事,那么接下来和我一起探讨吧 1.二维数组 x = [[1,3,5], [2,4,6] ...
- (原)tensorflow中函数执行完毕,显存不自动释放
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/7608916.html 参考网址: https://stackoverflow.com/question ...
- tensorflow中张量_常量_变量_占位符
1.tensor 在tensorflow中,数据是被封装在tensor对象中的.tensor是张量的意思,即包含从0到任意维度的张量.常数是0维度的张量,向量是1维度的张量,矩阵是二维度的张量,以及还 ...
- Tensorflow中的padding操作
转载请注明出处:http://www.cnblogs.com/willnote/p/6746668.html 图示说明 用一个3x3的网格在一个28x28的图像上做切片并移动 移动到边缘上的时候,如果 ...
随机推荐
- phpstorm webstorm编辑器正则替换 类名,方法名替换
首先勾选Match Case 和 Regex 正则规则:无须添加//左右分解符,直接写正则表达式,注意应该转义的部分,需要原封不动替换的部分加上括号 替换规则:正常书写正则,要继承下来的字符使用$1. ...
- Kubernetes YAML 文件全字段详解
Kubernetes YAML 文件全字段详解 Deployment yaml 其中主要参数都在podTemplate 中,DaemonSet StatefulSet 中的pod部分一样. apiVe ...
- pip换源-换成国内的源
PyPI使用国内源 通过几次 pip 的使用,对于默认的 pip 源的速度实在无法忍受,于是便搜集了一些国内的pip源,如下: 阿里云 http://mirrors.aliyun.com/pypi ...
- wentaolovesmeng.club
wentaolovesmeng.club wentaostudy.club
- 随笔分类 - C++托管(clr)(转)
c#利用SWIG调用c++dll学习总结[转] 摘要: 开发环境: 操作系统:windows 7 IDE:Microsoft Visual Studio Professional 2015 SWIG: ...
- includes方法 使用 Object.defineProperty 扩展 ,解决不兼容问题
原文链接 https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/includes ...
- JS实现继承的几种方法
父类: // 定义一个动物的类 function Animal (name) { // 属性 this.name = name || 'Animal'; // 实例方法 this.sleep = fu ...
- elastalert 基于EFK环境的邮件报警
1.安装elastalert 安装的python必须是2.7以上的版本 安装的路径 /usr/local/src 安装依赖 yum -y install wget openssl openssl- ...
- Flutter之网络请求
Flutter之网络请求 一,介绍与需求 1.1,介绍 1,http一个可组合的,基于Future的库,用于发出HTTP请求.包含一组高级功能和类,可轻松使用HTTP资源.它与平台无关,可以在命令行和 ...
- 关于lct维护动态生成树问题
水管局长数据加强版 题意是要求维护一棵最小生成树,支持删边操作. 删边操作比较难处理,因为如果删掉树上的边, 很难从已经有备选集合中找出连接不同联通块的最小的边. 然而题目并没有要求在线. 所以离线. ...