我定义了一个像这样的张量:
x = tf.get_variable("x", [100])
但是当我尝试打印张量的形状时:
print( tf.shape(x) )
我得到Tensor("Shape:0",shape =(1,),dtype = int32),为什么输出的结果不应该是shape =(100)
我正在玩tensorflow并遇到以下代码的问题:
def _init_parameters(self, input_data, labels):
# the input shape is (batch_size, input_size)
input_size = tf.shape(input_data)[1]
# labels in one-hot format have shape (batch_size, num_classes)
num_classes = tf.shape(labels)[1]
stddev = 1.0 / tf.cast(input_size, tf.float32)
w_shape = tf.pack([input_size, num_classes], 'w-shape')
normal_dist = tf.truncated_normal(w_shape, stddev=stddev, name='normaldist')
self.w = tf.Variable(normal_dist, name='weights')
Run Code Online (Sandbox Code Playgroud)
(我正在tf.pack按照这个问题的建议使用,因为我得到了同样的错误)
当我运行它(从一个更大的脚本调用这个),我得到这个错误:
ValueError: initial_value must have a shape specified: Tensor("normaldist:0", shape=TensorShape([Dimension(None), Dimension(None)]), dtype=float32)
Run Code Online (Sandbox Code Playgroud)
我试图在交互式shell中复制该过程.实际上,normal_dist虽然提供的值确实存在,但未指定维度:
In [70]: input_size.eval()
Out[70]: 4
In [71]: num_classes.eval()
Out[71]: 3
In [72]: w_shape.eval() …Run Code Online (Sandbox Code Playgroud)