tf tensor 输出
在学习TensorFlow的过程中,我们需要知道某个tensor的值是什么,这个很重要,尤其是在debug的时候。也许你会说,这个很容易啊,直接print就可以了。其实不然,print只能打印输出shape的信息,而要打印输出tensor的值,需要借助class tf.Session, class tf.InteractiveSession。因为我们在建立graph的时候,只建立tensor的结构形状信息,并没有执行数据的操作。
一 class tf.Session
运行tensorflow操作的类,其对象封装了执行操作对象和评估tensor数值的环境。这个我们之前介绍过,在定义好所有的数据结构和操作后,其最后运行。
- import tensorflow as tf
- # Build a graph.
- a = tf.constant(5.0)
- b = tf.constant(6.0)
- c = a * b
- # Launch the graph in a session.
- sess = tf.Session()
- # Evaluate the tensor `c`.
- print(sess.run(c))
二 class tf.InteractiveSession
顾名思义,用于交互上下文的session,便于输出tensor的数值。与上一个Session相比,其有默认的session执行相关操作,比如:Tensor.eval(), Operation.run()。Tensor.eval()是执行这个tensor之前的所有操作,Operation.run()也同理。
- import tensorflow as tf
- a = tf.constant(5.0)
- b = tf.constant(6.0)
- c = a * b
- with tf.Session():
- # We can also use 'c.eval()' here.
- print(c.eval())
tf tensor 输出的更多相关文章
- 10 tensorflow在循环体中用tf.print输出节点内容
代码 i=tf.constant(0,dtype=tf.int32) batch_len=tf.constant(10,dtype=tf.int32) loop_cond = lambda a,b: ...
- typeError:The value of a feed cannot be a tf.Tensor object.Acceptable feed values include Python scalars,strings,lists.numpy ndarrays,or TensorHandles.For reference.the tensor object was Tensor...
如上贴出了:错误信息和错误代码. 这个问题困扰了自己两天,报错大概是说输入的数据和接受的格式不一样,不能作为tensor. 后来问了大神,原因出在tf.reshape(),因为网络训练时用placeh ...
- 将Tensor输出到文件
) local file = io.open('/home/xbwang/Desktop/part2original','a') ,length do number = part2[j] file:w ...
- AI - TensorFlow - 张量(Tensor)
张量(Tensor) 在Tensorflow中,变量统一称作张量(Tensor). 张量(Tensor)是任意维度的数组. 0阶张量:纯量或标量 (scalar), 也就是一个数值,例如,\'Howd ...
- 什么是Tensor
https://blog.csdn.net/kansas_lh/article/details/79321234 tensor是tensorflow基础的一个概念——张量. Tensorflow用到了 ...
- TF常用知识
命名空间及变量共享 # coding=utf-8 import tensorflow as tf import numpy as np import matplotlib.pyplot as plt; ...
- tf中计算图 执行流程学习【转载】
转自:https://blog.csdn.net/dcrmg/article/details/79028003 https://blog.csdn.net/qian99/article/details ...
- tf中的run()与eval()【转载】
转自:https://blog.csdn.net/jiaoyangwm/article/details/79248535 1.eval() 其实就是tf.Tensor的Session.run() 的 ...
- tf.nn.rnn_cell.MultiRNNCell
Class tf.contrib.rnn.MultiRNNCell 新版 Class tf.nn.rnn_cell.MultiRNNCell 构建多隐层神经网络 __init__(cells, sta ...
随机推荐
- MySql UNIX_TIMESTAMP和FROM_UNIXTIME函数讲解
MySql UNIX_TIMESTAMP和FROM_UNIXTIME函数讲解 by:授客 QQ:1033553122 1. unix_timestamp(date)将时间转换为时间戳,如果参数为空,则 ...
- flutter 防止键盘弹出 导致超出屏幕
return Scaffold( appBar: AppBar( elevation: 0.0, title: new Text("登陆"), ), resizeToAvoidBo ...
- 护网杯 task_shoppingCart 记录
前言 相关题目位于 https://gitee.com/hac425/blog_data/tree/master/hwb task_shoppingCart 漏洞位于 00BD9 用户输入 idx 然 ...
- Android之编写测试用例
测试是软件工程中一个非常重要的环节,而测试用例又可以显著地提高测试的效率和准确性.测试用例其实就是一段普通的程序代码,通常是带有期望的运行结果的,测试者可以根据最终的运行结果来判断程序是否能正常工作. ...
- Python技巧——list与字符串互相转换
Python技巧——list与字符串互相转换 在Python的编程中,经常会涉及到字符串与list之间的转换问题,下面就将两者之间的转换做一个梳理. 1.字符串转换成list 命令:list() ...
- [iOS] 列表滑动展开隐藏头部HeaderView
平常遇到大多数的带有列表的应用都会遇到这个场景:在列表顶端有一个Header,当向上滑动列表时,压缩header,向下滑动列表到头时,展开header.这种样式在例如微博,twitter这些展示动态的 ...
- Spring Boot (#1 quick start)
Spring Boot (#1 quick start) 官方文档 Spring Boot是为了简化Spring应用的创建.运行.调试.部署等而出现的,使用它可以做到专注于Spring应用的开发,而无 ...
- Git执行过程中出现问题及解决方法
not-fast-forward https://help.github.com/articles/dealing-with-non-fast-forward-errors/
- AOP编程报错Xlint:invalidAbsoluteTypeName
@Component@Aspectpublic class DingdingAspect { private Logger logger = LoggerFactory.getLogger(this. ...
- 用JS实现判断iframe是否加载完成
本文出至:新太潮流网络博客 var iframe = document.createElement("iframe"); iframe.src = "blog.iinu. ...