美文网首页
33-tensorflow中的eval、placeholder和

33-tensorflow中的eval、placeholder和

作者: jxvl假装 | 来源:发表于2019-10-05 11:18 被阅读0次

eval的使用

eval()其实就是tf.Tensor的session.run()的另一种写法,

  1. eval()也是启动计算的一种方式。基于tensorflow基本原理,首先需要定义图,然后计算图,
    其中计算图的函数有常见的run()函数,如sess.run(),eval()也是类似。
  2. eval()只能用于tf.tensor类对象,也就是有输出的operaton。没有输出的operation,使用
    session.run()

placeholder和feec_dict的使用

placeholder:TensorFlow中的placeholder就是一个占位符,它并没有实际的值,只会分配必要的内存,需要使用feed_dict传递数据

tf.placeholder(dtype, shape=None, name=None)

feed_dict:feed_dict是一个字典,键为占位符,值为要传递给该占位符的值

使用:

import tensorflow as tf

x = tf.placeholder(tf.string)
with tf.Session() as sess:
    output = sess.run(x, feed_dict={x:"Hello world"})
    print(output)

相关文章

网友评论

      本文标题:33-tensorflow中的eval、placeholder和

      本文链接:https://www.haomeiwen.com/subject/jtywuctx.html