tf.slice(inputs, begin, size, name)
是tensorflow中对向量inputs
的切片,begin
表示每个维度要抽取的开始位置,size
表示从开始位置往后要抽取的元素个数,若某个维度size
为-1
则表示抽取对应维度的所有元素。
例子
import tensorflow as tf
import numpy as np
xyz = np.array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
[10, 11, 12]])
points = np.array([[11, 22, 33],
[44, 55, 66],
[77, 88, 99],
[1010, 1111, 1212]])
point_cloud = np.concatenate([xyz, points], axis=-1)
point_cloud = np.expand_dims(point_cloud, axis=0)
print(point_cloud.shape)
l0_xyz = tf.slice(point_cloud, [0, 0, 0], [-1, -1, 3])
l0_points = tf.slice(point_cloud, [0, 0, 3], [-1, -1, 3])
输出
print(l0_xyz)
>>> tf.Tensor(
[[[ 1 2 3]
[ 4 5 6]
[ 7 8 9]
[10 11 12]]], shape=(1, 4, 3), dtype=int32)
print(l0_points)
>>> tf.Tensor(
[[[ 11 22 33]
[ 44 55 66]
[ 77 88 99]
[1010 1111 1212]]], shape=(1, 4, 3), dtype=int32)