在tensorflow中,eval和run都是获取当前结点的值的一种方式。

在使用eval时,若有一个 t 是Tensor对象,调用t.eval()相当于调用sess.run(t) 一下两段代码等效:

float_tensor = tf.cast(tf.constant([1, 2, 3]),dtype=tf.float32)
t = float_tensor * float_tensor sess = tf.Session()
with sess.as_default():
print(t.eval())
print(sess.run(t))

result:

[1. 4. 9.]
[1. 4. 9.]

区别 
两者的区别主要在于,eval一次只能得到一个结点的值,而run可以得到多个。

float_tensor = tf.cast(tf.constant([1, 2, 3]),dtype=tf.float32)
t = float_tensor * float_tensor sess = tf.Session()
with sess.as_default():
print(t.eval(), float_tensor.eval())
print(sess.run((t, float_tensor)))

result:

[1. 4. 9.] [1. 2. 3.]
(array([1., 4., 9.], dtype=float32), array([1., 2., 3.], dtype=float32))

tensorflow中run和eval的区别(转)的更多相关文章

  1. Dockerfile 中 RUN, CMD, ENTRYPOINT 的区别

    RUN 指令:用于指定 docker build 过程中要运行的命令. 语法格式: RUN <command> 或 RUN ["<executeable>" ...

  2. MATLAB中feval与eval的区别

    feval函数有两种调用形式1.[y1, y2, ...] = feval(fhandle, x1, ..., xn)2.[y1, y2, ...] = feval(fname, x1, ..., x ...

  3. Python中json和eval的区别

    >>> import json >>> s = '{"one":1,"two":2}' >>> json. ...

  4. TensorFlow中random_normal和truncated_normal的区别

    原文链接:https://blog.csdn.net/zhangdongren/article/details/83344048 区别如下: tf.random_normal(shape,mean=0 ...

  5. docker中run和start的区别?

    docker run 后面指定的是一个镜像 而docker start指定的是一个容器 docker run是利用镜像生成容器,并启动容器,而docker start是启动一个之前生成过的容器

  6. tensorflow 中 softmax_cross_entropy_with_logits 与 sparse_softmax_cross_entropy_with_logits 的区别

    http://stackoverflow.com/questions/37312421/tensorflow-whats-the-difference-between-sparse-softmax-c ...

  7. Tensorflow中的run()函数

    1 run()函数存在的意义 run()函数可以让代码变得更加简洁,在搭建神经网络(一)中,经历了数据集准备.前向传播过程设计.损失函数及反向传播过程设计等三个过程,形成计算网络,再通过会话tf.Se ...

  8. Java线程中run和start方法的区别

    http://bbs.csdn.net/topics/350206340 Thread类中run()和start()方法的区别如下:run()方法:在本线程内调用该Runnable对象的run()方法 ...

  9. [开发技巧]·TensorFlow中numpy与tensor数据相互转化

    [开发技巧]·TensorFlow中numpy与tensor数据相互转化 个人主页–> https://xiaosongshine.github.io/ - 问题描述 在我们使用TensorFl ...

随机推荐

  1. 一、Html5基础讲解以及五个标签

    什么是html?html是用来描述网页的一种语言html指超文本标记语言html不是编程语言,是一种标记语言 HTML基础标签 Head.body html标题 <h1>…<h6&g ...

  2. phalcon断点调试(phpStorm+xdebug)

    1.下载并添加chrome插件xdebug helper,下载地址:http://www.downcc.com/soft/261091.html 2.php添加xdebug扩展 mkdir -p /u ...

  3. lunix salt 用法

    红蜘蛛软件 c/s client  : 学生端是客户端 ,装了红蜘蛛客户端-学生端 server端: 教师机  ,装了红蜘蛛软件-教师端  教师机,只能管理,  教师机和学生机,相互通信,相互知道的情 ...

  4. properties文件读取

    package properties; import java.io.FileInputStream; import java.io.FileNotFoundException; import jav ...

  5. MySQL 中的三中循环 while loop repeat 的基本用法

    -- MySQL中的三中循环 while . loop .repeat 求 1-n 的和 -- 第一种 while 循环 -- 求 1-n 的和 /* while循环语法: while 条件 DO 循 ...

  6. 性能测试day01_性能基本概念

    其实第一次接触性能是15年的时候,懵懵懂懂的被领导拉去做第一次做性能压测,如今有机会重新听一下云层大大讲解性能,于是打算以此博客记录下整个学习的过程,如若有不同意见者可以在下面留言指出,也欢迎大家一起 ...

  7. tornado 和 djanjo 转义处理对比

    tornado tornado默认是转义所有字符,比较安全,但有时候我们的确需要把字符当做html来解析处理,因此我们需要做些处理. 所有的模板输出都已经通过 tornado.escape.xhtml ...

  8. official shiro(Reference Manual)

    Apache Shiro Reference Documentation Overview Core Spring-based Applications 1.Overview pom.xml < ...

  9. odps 使用参考 & tips

    1.  自定义udf 编写udf 1)pom.xml <dependency> <groupId>com.aliyun.odps</groupId> <art ...

  10. FLEX中一组基于button的组件

    <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="ht ...