用tf.Session()创建会话时只有在会话中run某个张量才能得到这个张量的运算结果,而交互式环境下如命令行、IPython,想要执行一行就得到结果,这就需要用到tf.InteractiveSession(),并且可以使用Tensor.eval() 得到张量的具体值。

import tensorflow as tf
sess = tf.InteractiveSession() a = tf.truncated_normal([1,5],stddev=0.1) # 创建一个1x5的随机张量 print(a) # >> Tensor("truncated_normal_1:0", shape=(1, 5), dtype=float32)
print(a.eval())
# >> array([[ 0.0331782 , -0.0733152 , 0.01366828, 0.01550526, 0.06196761]],dtype=float32)

  

TensorFlow--交互式使用--tf.InteractiveSession()的更多相关文章

  1. TensorFlow——交互式使用会话:InteractiveSession类

    目的是在交互式环境下(如jupyter),手动设定当前会话为默认会话,从而省去每次都要显示地说明sess的繁琐,如:Tensor.ecal(session=sess)或sess.Operation.r ...

  2. tensorflow函数解析: tf.Session() 和tf.InteractiveSession()

    链接如下: http://stackoverflow.com/questions/41791469/difference-between-tf-session-and-tf-interactivese ...

  3. tf.Session()和tf.InteractiveSession()的区别

    官方tutorial是这么说的: The only difference with a regular Session is that an InteractiveSession installs i ...

  4. tf.Session()、tf.InteractiveSession()

    tf.Session()和tf.InteractiveSession()的区别 官方tutorial是这么说的: The only difference with a regular Session ...

  5. tf.InteractiveSession()和tf.Session()

    tf.InteractiveSession()适合用于python交互环境 tf.Session()适合用于源代码中 1.tf.InteractiveSession() 直接用eval()就可以直接获 ...

  6. TensorFlow高级API(tf.contrib.learn)及可视化工具TensorBoard的使用

    一.TensorFlow高层次机器学习API (tf.contrib.learn) 1.tf.contrib.learn.datasets.base.load_csv_with_header 加载cs ...

  7. tf.InteractiveSession()与tf.Session()

    tf.InteractiveSession():它能让你在运行图的时候,插入一些计算图,这些计算图是由某些操作(operations)构成的.这对于工作在交互式环境中的人们来说非常便利,比如使用IPy ...

  8. tf.InteractiveSession() 和 tf.Session() 的区别

    tf.InteractiveSession():它能让你在运行图的时候,插入一些计算图,这些计算图是由某些操作(operations)构成的.这对于工作在交互式环境中的人们来说非常便利,比如使用IPy ...

  9. 【TensorFlow基础】tf.add 和 tf.nn.bias_add 的区别

    1. tf.add(x,  y, name) Args: x: A `Tensor`. Must be one of the following types: `bfloat16`, `half`, ...

随机推荐

  1. Python 基础之python运算符

    一.运算符 1.算数运算符 + - * / // % ** var1 = 5var2 = 8 #(1)  + 加res = var1 + var2print(res) # (2)  -  减res = ...

  2. Python简单程序爬取天气信息,定时发邮件给朋友【高薪必学】

    前段时间看到了这个博客.https://blog.csdn.net/weixin_45081575/article/details/102886718.他用了request模块,这不巧了么,正好我刚用 ...

  3. 137、Java内部类之把内部类放到外部

    01.代码如下: package TIANPAN; class Outer { // 外部类 private String msg = "Hello World !"; publi ...

  4. synchronized和volatile关键字

    synchronized 同步块大家都比较熟悉,通过 synchronized 关键字来实现,所有加上synchronized 和 块语句,在多线程访问的时候,同一时刻只能有一个线程能够用 synch ...

  5. ubuntu 文件操作

    linux的文件目录是一棵目录树,默认起始位置在主文件夹(/home/city),里面有若干子文件(视频.图片.下载.桌面等) 一.文件路径(目录操作) 1.绝对路径:从根目录/写起,完整的.详细的描 ...

  6. 【剑指Offer面试编程题】题目1512:用两个栈实现队列--九度OJ

    题目描述: 用两个栈来实现一个队列,完成队列的Push和Pop操作. 队列中的元素为int类型. 输入: 每个输入文件包含一个测试样例. 对于每个测试样例,第一行输入一个n(1<=n<=1 ...

  7. 9月Win10杀软大PK

    导读 严格来说,Windows 10 并不存在“裸奔”一说,因为自带的 Defender 安全中心已经是越来越强大. 来自独立机构 AV-Comparatives 的 9 月份评测报告显示,Windo ...

  8. IDEA配置数据库连接失败的问题

    今天采用IDEA连接数据库失败了,有几个问题需要注意 首先笔者采用的数据库版本为8.0.17而IDEA自带版本是5.2.26大概,于是首先出现的问题是驱动不匹配,那么就需要换成我自己的版本,配置如下 ...

  9. Maven:sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

    还是记录使用 maven 时遇到的问题. 一.maven报错 maven package 进行打包时出现了以下报错: Non-resolvable parent POM for com.wpbxin: ...

  10. 「USACO09FEB」改造路Revamping Trails

    传送门 Luogu 解题思路 有点像这题,但是现在这道不能跑k遍SPFA了,会TLE. 那么我们就跑分层图最短路,然后就变成模板题了. 细节注意事项 别跑SPFA就好了. 参考代码 #include ...