返回在索引 axis 处插入长度为 1 的轴的张量。 (不推荐使用的参数)
用法
tf.compat.v1.expand_dims(
input, axis=None, name=None, dim=None
)参数
-
input一个Tensor。 -
axis0-D(标量)。指定展开input形状的维度索引。必须在[-rank(input) - 1, rank(input)]范围内。 -
name输出的名称Tensor(可选)。 -
dim0-D(标量)。等效于axis,将被弃用。
返回
-
与
input具有相同数据的Tensor,但其形状添加了大小为 1 的附加维度。
抛出
-
ValueError如果指定了dim和axis中的任何一个或都没有指定。
警告:不推荐使用某些参数:(dim)。它们将在未来的版本中被删除。更新说明:改用 axis 参数
给定一个张量 input ,此操作在 input 的形状的维度索引 axis 处插入一个长度为 1 的维度。维度索引遵循 Python 索引规则:它是从零开始的,一个负数索引它从末尾向后计数。
此操作可用于:
- 将外部"batch" 维度添加到单个元素。
- 对齐轴以进行广播。
- 将内部向量长度轴添加到标量张量。
例如:
如果您有一个形状为 [height, width, channels] 的图像:
image = tf.zeros([10,10,3])
您可以通过传递 axis=0 添加外部 batch 轴:
tf.expand_dims(image, axis=0).shape.as_list()
[1, 10, 10, 3]
新轴位置与 Python list.insert(axis, 1) 匹配:
tf.expand_dims(image, axis=1).shape.as_list()
[10, 1, 10, 3]
遵循标准 Python 索引规则,负数 axis 从末尾开始计数,因此 axis=-1 添加了最内层维度:
tf.expand_dims(image, -1).shape.as_list()
[10, 10, 3, 1]
此操作要求 axis 是 input.shape 的有效索引,遵循 Python 索引规则:
-1-tf.rank(input) <= axis <= tf.rank(input)
此操作与以下内容有关:
tf.squeeze,删除大小为 1 的维度。tf.reshape,提供更灵活的整形能力。tf.sparse.expand_dims,为tf.SparseTensor提供此函数
相关用法
- Python tf.compat.v1.executing_eagerly_outside_functions用法及代码示例
- Python tf.compat.v1.executing_eagerly用法及代码示例
- Python tf.compat.v1.estimator.DNNEstimator用法及代码示例
- Python tf.compat.v1.estimator.experimental.KMeans用法及代码示例
- Python tf.compat.v1.estimator.tpu.RunConfig用法及代码示例
- Python tf.compat.v1.enable_eager_execution用法及代码示例
- Python tf.compat.v1.estimator.regressor_parse_example_spec用法及代码示例
- Python tf.compat.v1.estimator.BaselineRegressor用法及代码示例
- Python tf.compat.v1.estimator.inputs.numpy_input_fn用法及代码示例
- Python tf.compat.v1.estimator.LinearRegressor用法及代码示例
- Python tf.compat.v1.enable_v2_tensorshape用法及代码示例
- Python tf.compat.v1.estimator.BaselineEstimator用法及代码示例
- Python tf.compat.v1.estimator.BaselineClassifier用法及代码示例
- Python tf.compat.v1.estimator.LinearClassifier用法及代码示例
- Python tf.compat.v1.estimator.DNNLinearCombinedRegressor用法及代码示例
- Python tf.compat.v1.estimator.tpu.TPUEstimator用法及代码示例
- Python tf.compat.v1.estimator.DNNClassifier用法及代码示例
- Python tf.compat.v1.estimator.DNNRegressor用法及代码示例
- Python tf.compat.v1.estimator.tpu.experimental.EmbeddingConfigSpec用法及代码示例
- Python tf.compat.v1.estimator.DNNLinearCombinedEstimator用法及代码示例
注:本文由纯净天空筛选整理自tensorflow.org大神的英文原创作品 tf.compat.v1.expand_dims。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
