【转载】 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的图像上做切片并移动 移动到边缘上的时候,如果 ...
随机推荐
- IIS配置伪静态 集成模式 样式丢失
最近将一个老网站迁移到新服务器,因为需要做伪静态配置,在网上找了一些教程跟着配置.结果却出现:按照网上教程配置完后将应用程序池模式改为经典模式,然后验证规则就匹配不了.改成集成模式验证规则能匹配但是网 ...
- PL/SQL Developer 快捷键
前面我有分享了一个PLSQL美化规则,其实通过统一的美化SQL,把这里SQL写在Java代码里可以比较容易阅读代码,且保持良好得编码风格. 在工作中我们也经常使用PLSQL来写一SQL,有些常用的SQ ...
- 转换复杂的JSON对象为 Map对象
最近项目需要跟客户对接一个webservice接口,客户那传json串过来,属于比较复杂的json串,这里跟大家分享下我项目中所用的解析方法: 该方法需要以下jar package com.test; ...
- 地址栏参数获取函数 GetQueryStr(name)
//name:参数名称,return:有则返回该参数对应值,没有则返回null function GetQueryStr(name) { var reg = new RegExp(& ...
- Caching POST-post是否能缓存
https://www.mnot.net/blog/2012/09/24/caching_POST One of the changes in Apple’s release of iOS6 last ...
- 学习:STL概念学习
STL初识: 为了建立数据结构和算法的一套标准,诞生了STL STL基本概念: STL(Standard Template Library,标准模板库) STL 从广义上分为: 容器(containe ...
- LeetCode 1091. Shortest Path in Binary Matrix
原题链接在这里:https://leetcode.com/problems/shortest-path-in-binary-matrix/ 题目: In an N by N square grid, ...
- C++ auto 完成类型自动推导与使用
c++11 允许声明一个变量或对象(object)而不需要指明其类型,只需说明它是auto. 1.如: auto i = 42: //i是整型 double f(); auto d=f(); // ...
- Supercharging your ETL with Airflow and Singer
转自:https://www.stitchdata.com/blog/supercharging-etl-with-airflow-and-singer/ singer 团队关于singer 与air ...
- mknod