两种方法都可以获得变量的shape

tf.shape(x)

其中x可以是tensor,也可不是tensor,返回是一个tensor.

shape=tf.placeholder(tf.float32, shape=[None, 227,227,3] )

我们经常会这样来feed数据,如果在运行的时候想知道None到底是多少,这时候,只能通过tf.shape(x)[0]这种方式来获得.

tensorflow
一个面向所有人的开源机器学习框架

tensor.get_shape()

只有tensor有这个方法, 返回是一个tuple, 里面的值是python类型。

tensor.shape

等价于 tensor.get_shape()

GitHub 加速计划 / te / tensorflow
21
4
下载
一个面向所有人的开源机器学习框架
最近提交(Master分支:1 个月前 )
4f64a3d5 Instead, check for this case in `ResolveUsers` and `ResolveOperand`, by querying whether the `fused_expression_root` is part of the `HloFusionAdaptor`. This prevents us from stepping into nested fusions. PiperOrigin-RevId: 724311958 1 个月前
aa7e952e Fix a bug in handling negative strides, and add a test case that exposes it. We can have negative strides that are not just -1, e.g. with a combining reshape. PiperOrigin-RevId: 724293790 1 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐