10 tensorflow在循环体中用tf.print输出节点内容
代码
i=tf.constant(0,dtype=tf.int32)
batch_len=tf.constant(10,dtype=tf.int32)
loop_cond = lambda a,b: tf.less(a,batch_len)
#yy=tf.Print(batch_len,[batch_len],"batch_len:")
yy=tf.constant(0)
loop_vars=[i,yy]
def _recurrence(i,yy):
c=tf.constant(2,dtype=tf.int32)
x=tf.multiply(i,c)
print_info=tf.Print(x,[x],"x:")
yy=yy+print_info
i=tf.add(i,1)
return i,yy
i,yy=tf.while_loop(loop_cond,_recurrence,loop_vars,parallel_iterations=1)#可以批处理
sess = tf.Session()
sess.run(yy)
输出信息

为什么会这样,因为执行sess.run(yy)的时候,会有数据流过循环体中的所有tf.Print节点,此时就会执行tf.Print中指定的输出。最关键的操作就是yy=yy+print_info
存在的问题(与Spyder有关)
在spyder中使用调试模式的时候,无法输出上面的信息。
上面的代码是使用‘python 测试程序__在循环中使用tf.print.py’的方式在命令行执行才会输出。
如何不断的输出tf.Print信息
除了上述使用yy=yy+print_info。
如果print_info是这样的,比如:
print_info=tf.Print(constructionErrorMatrix,[constructionErrorMatrix],"constructionErrorMatrix:")#专门为了调试用,输出相关信息。
tfPrint=tfPrint+tf.to_int32(print_info[0])#一种不断输出tf.Print的方式,注意tf.Print的返回值。
constructionErrorMatrix是一个(?,)类型的float64 Tensor。我们可以用上述代码,继续进行tf.Print的输出。
此外,tf.Print中的第二个参数[]中放入的内容,也必须是能够转为Tensor。否则会提示
TypeError: Tensors in list passed to 'data' of 'Print' Op have types [<NOT CONVERTIBLE TO TENSOR>] that are invalid.
比如,一个Tensor的shape中如果有“?”,就不能转换为Tensor。对于这种不能Tensor,我们不能用get_shape()[i].value去获取?的维度,但是我们可以用tf.shape获取有数据流入以后的动态维度。就是?最终确定的维度。
10 tensorflow在循环体中用tf.print输出节点内容的更多相关文章
- 使用tf.print()打印tensor内容
使用tf.Print()打印tensor内容,这是tensorflow中调试bug的一个手段,例子如下所示: import tensorflow as tf a = tf.Variable(tf.ra ...
- 【转载】 tf.Print() (------------ tensorflow中的print函数)
原文地址: https://blog.csdn.net/weixin_36670529/article/details/100191674 ------------------------------ ...
- tensorflow笔记6:tf.nn.dynamic_rnn 和 bidirectional_dynamic_rnn:的输出,output和state,以及如何作为decoder 的输入
一.tf.nn.dynamic_rnn :函数使用和输出 官网:https://www.tensorflow.org/api_docs/python/tf/nn/dynamic_rnn 使用说明: A ...
- Tensorflow滑动平均模型tf.train.ExponentialMovingAverage解析
觉得有用的话,欢迎一起讨论相互学习~Follow Me 移动平均法相关知识 移动平均法又称滑动平均法.滑动平均模型法(Moving average,MA) 什么是移动平均法 移动平均法是用一组最近的实 ...
- Tensorflow之调试(Debug) && tf.py_func()
Tensorflow之调试(Debug)及打印变量 tensorflow调试tfdbg 几种常用方法: 1.通过Session.run()获取变量的值 2.利用Tensorboard查看一些可视化统计 ...
- import tensorflow 报错: tf.estimator package not installed.
import tensorflow 报错: tf.estimator package not installed. 解决方案1: 安装 pip install tensorflow-estimator ...
- python的print()输出
1.普通的输出: print(str)#str是任意一个字符串,数字··· 2.格式化输出: print('1,2,%s,%d'%('asd',4)) 1,2,asd,4 与C语言有点类似 3.其它: ...
- 使用if判断字符串的长度是否等于10,根据结果进行不同的输出
string1=' print(len(string1)) # 使用len()计算字符串长度 if not len(string1) ==10: print('字符串的长度不为10') else: p ...
- Windows 10 Tensorflow 2 gpu正式版安装和更新日志
Windows 10 Tensorflow 2 gpu正式版安装和更新日志 Tensorflow 2.0.0 released on2019年10月1日星期二 Link: https://github ...
随机推荐
- centos 7 nginx 安装
1.下载nginx rpm包 下载地址:http://nginx.org/packages/mainline/centos/7/x86_64/RPMS/ ,可查看所有安装包 从中如下载: wget h ...
- Vue的watch监听事件
Vue的watch监听事件 相关Html: <!DOCTYPE html> <html lang="en"> <head> <meta c ...
- Failed to instantiate CLSID_VirtualBox w/ IVirtualBox, but CLSID_VirtualBox w/ IUnknown works.
我是 win7 64位 解决办法: 1, win+r 快捷键打开 “运行”,输入regedit 打开注册表 2,找到 HKEY_CLASSES_ROOT\CLSID\{00020420-0000-00 ...
- 开源视频会议bigbluebutton
这是另一个开源视频会议项目,简称bbb 官方网站:http://bigbluebutton.org/ 代码地址:https://code.google.com/p/bigbluebutton/ dem ...
- 页面滚动插件 better-scroll 的用法
better-scroll 是一个页面滚动插件,用它可以很方便的实现下拉刷新,锚点滚动等功能. 实现原理:父容器固定高度,并设置 overflow:hidden,子元素超出父元素高度后将被隐藏,超出部 ...
- CentOS命令行界面与图形界面切换(图文详解)
不多说,直接上干货! Ctrl + Alt +F1,到图形界面 Ctrl + Alt +F2,到命令行界面 欢迎大家,加入我的微信公众号:大数据躺过的坑 人工智能躺过的坑 同 ...
- windows10下找回照片查看器的方法(仅作记录)
Windows Registry Editor Version 5.00 ; Change Extension's File Type [HKEY_CURRENT_USER\Software\Clas ...
- python mysql uitl
from traceback import format_exc import pymysql as MySQLdb class MySQLUtils(object): def get_db_conn ...
- C++运行时动态类型
RTTI 运行时类型识别(RTTI)的引入有三个作用: 配合typeid操作符的实现: 实现异常处理中catch的匹配过程: 实现动态类型转换dynamic_cast typeid操作符的实现 静态类 ...
- java面试⑥框架部分
2.5.1 什么是框架: 2.5.2 MVC模式 2.5.3 MVC框架 2.5.4 简单讲一下struts2的执行流程 2.5.5 Struts2中的拦截器,你都用它干什么? 2.5.6 简单讲一下 ...