本文注重介绍tf.placeholder的shape中None的表达
注意下面的shape
import tensorflow as tf
input = tf.placeholder(tf.float32)
input1=tf.placeholder(tf.float32,(None,)) ##注意(None,)
input3=tf.placeholder(tf.float32,(None)) ##注意(None)
input2=tf.placeholder(tf.float32,(None,None)) ##注意(None,None)
output = tf.shape(input)
output1 = tf.shape(input1)
output2 = tf.shape(input2)
output3 = tf.shape(input3)
with tf.Session() as sess:
print(sess.run(output, feed_dict={input:[[[3.]]]})) ##注意input
print(sess.run(output, feed_dict={input:[[3.]]})) ##注意input
print(sess.run(output, feed_dict={input:[4.]})) ##注意input
print(sess.run(output1, feed_dict={input1:[4.]})) ##注意input
print(sess.run(output2, feed_dict={input2: [[4.]]})) ##注意input
print(sess.run(output3, feed_dict={input3: [4.]})) ##注意input
下面都会报错:
import tensorflow as tf
input = tf.placeholder(tf.float32,(None,)) #注意(None,)
output = tf.shape(input)
with tf.Session() as sess:
print(sess.run(output, feed_dict={input:[[1.]]})) ##注意input
import tensorflow as tf
input = tf.placeholder(tf.float32,(None,None)) #注意(None,None)
output = tf.shape(input)
with tf.Session() as sess:
print(sess.run(output, feed_dict={input:[[[1.]]]})) ##注意input
本文深入解析TensorFlow中tf.placeholder的shape参数使用None的含义及示例。通过具体代码展示如何在不同维度上应用None,并解释其对数据输入灵活性的影响。
840

被折叠的 条评论
为什么被折叠?



