placeholder 是 TensorFlow 中的占位符,暂时储存变量.
Tensorflow 如果想要从外部传入data, 就需要用到 tf.placeholder(), 然后以这种形式传输数据:
sess.run(***, feed_dict={input: **}).
示例:
import tensorflow as tf
input1 = tf.placeholder(tf.float32) # 需要定义placeholder的数据类型,一般为float32
input2 = tf.placeholder(tf.float32)
# 定义output步骤
output = tf.multiply(input1, input2) # 乘法
# 执行
with tf.Session() as sess:
print(sess.run(output, feed_dict={input1: [5.3], input2: [2.0]}))
[2020-07-24 21:08:20,011] [INFO] [3499#MainThread] [../.local/lib/python3.6/site-packages/tensorflow/python/util/auto_strategy_utils.py:108] Disable Auto Strategy.
[10.6]