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 ...
随机推荐
- Android--根据子控件的大小自动换行的ViewGroup
1.自定义ViewGroup /** * Created by Administrator on 2016/2/26. * * --------自动换行的ViewGroup----------- */ ...
- Expo大作战(四)--快速用expo构建一个app,expo中的关键术语
简要:本系列文章讲会对expo进行全面的介绍,本人从2017年6月份接触expo以来,对expo的研究断断续续,一路走来将近10个月,废话不多说,接下来你看到内容,讲全部来与官网 我猜去全部机翻+个人 ...
- 从 Azure 下载 Windows VHD
本文介绍如何使用 Azure 门户从 Azure 下载 Windows 虚拟硬盘 (VHD) 文件. Azure 中的虚拟机 (VM) 将磁盘用作存储操作系统.应用程序和数据的位置. 所有 Azure ...
- web导出excel文件的几种方法
总的来说,两种方法:服务器端生成和浏览器端生成. 服务器端生成就是:根据用户请求,获取相应的数据,使用poi/jxl, jacob/jawin+excel,或是用数据拼html的table或是cvs纯 ...
- Android分区
1. Android 分区: 2. Android各个分区的作用: 2.1 modem分区 实现手机必需的通信功能,大家通常所的刷RADIO就是刷写modem分区,在所有适配的ROM中这部分是不动,否 ...
- 最短路径Dijkstra matlab
Dijkstra: function [dist,pre, full_path]=MinRoad_Dijkstra(G,v0) n=0; if isfield(G,'w') && ~i ...
- SQLite简单使用记录
SQLite,一种轻量级的数据库 想要使用的话首先下载安装包. https://www.sqlite.org/download.html 下载sqlite-netFx20-setup-bundle-x ...
- 数据结构习题Pop Sequence的理解----小白笔记^_^
Pop Sequence(25 分) Given a stack which can keep M numbers at most. Push N numbers in the order of 1, ...
- lavarel模板引擎blade学习
blade 模板学习 特点 主要的两个优点是:模板继承和区块 继承页面布局 布局文件(layout.php) + 详情文件 (page.php) 的组合,即一般到具体的组合.在blade文件之中的体现 ...
- 浏览器中上传Excel文件,服务器获取Excel字段。写入的数据库中。操作Excel的方式jxl和poi。
从Excel中获取字段,官方给我们提供了方法,地址https://poi.apache.org/components/spreadsheet/quick-guide.html#CellContents ...