placeholder 是 Tensorflow 中的占位符,暂时储存变量.

Tensorflow 中用于从外部传入data的占位符, 用input= tf.placeholder()设置占位符, 然后以这种形式传输数据 sess.run(***, feed_dict={input: **}).

注:占位符就是指暂时没用任何值的符号,待用户输入。只在运算中做一个变量的表示。类似于方程中的未知数。

示例:

import tensorflow as tf

#在 Tensorflow 中需要定义 placeholder 的 type ,一般为 float32 形式
input1 = tf.placeholder(tf.float32)
input2 = tf.placeholder(tf.float32)

# mul = multiply 是将input1和input2 做乘法运算,并输出为 output 
ouput = tf.multiply(input1, input2)
with tf.Session() as sess:
    print(sess.run(ouput, feed_dict={input1: [7.], input2: [2.]}))

相关文章:

  • 2022-12-23
  • 2021-06-16
  • 2021-06-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-16
  • 2021-09-09
  • 2022-12-23
  • 2021-12-06
  • 2022-12-23
相关资源
相似解决方案