[英]How to get 'static' shape using 'tf.shape()'?
I am just trying to get the static shape of a tensor using command 'tf.shape()'. 我只是想使用命令'tf.shape()'获得张量的静态形状。 I noticed that we could use 'x.get_shape' to obtain the static shape, however, in my code, for training, the shape is static, for evaluation, the shape of tensor is dynamic 'None'-so that I am not sure if I also could get static shape by using 'tf.shape()' as well. 我注意到我们可以使用'x.get_shape'获得静态形状,但是,在我的代码中,用于训练的形状是静态的,用于评估,张量的形状是动态的'None'-因此我不确定如果我也可以通过使用'tf.shape()'获得静态形状。
The shape of 'deconv4.outputs' is [16,256,256,3], however, when I use 'tf.shape(deconv4.outputs)[0]', the result is: 'Tensor("FRUC_DVF_g/strided_slice_2:0", shape=(), dtype=int32, device=/device:GPU:0)', not '16'. 'deconv4.outputs'的形状为[16,256,256,3],但是,当我使用'tf.shape(deconv4.outputs)[0]'时,结果为:'Tensor(“ FRUC_DVF_g / strided_slice_2:0”,shape =(),dtype = int32,device = / device:GPU:0)',而不是'16'。
Could you please help me with this? 你能帮我这个忙吗?
Thanks in advance! 提前致谢!
I have got the output of the model called 'deconv4.outputs' with the shape of [16,256,256,3]. 我得到了名为[deconv4.outputs]的模型,其输出形状为[16,256,256,3]。 I want to obtain the first dimension of 'deconv4.outputs' using 'tf.shape()' command. 我想使用“ tf.shape()”命令获取“ deconv4.outputs”的第一维。
flow = tf.slice(deconv4.outputs, [0,0,0,0], [tf.shape(deconv4.outputs)[0], 256, 256, 2])
The expected result is that the 'tf.shape(deconv4.outputs)[0]' returns '16'. 预期结果是“ tf.shape(deconv4.outputs)[0]”返回“ 16”。
tf.shape(), should return 16, when running under a session with appropriate inputs. 在具有适当输入的会话下运行时,tf.shape()应该返回16。
Anything which is dynamic, if you specify None at the input, without running it under a session you would get (). 任何动态的东西,如果您在输入中指定None而不在会话中运行它,则会得到()。
Try your code with eager_execution_enabled if possible. 如果可能,请尝试使用eager_execution_enabled启用代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.