首先看调用
rotated_data = provider.rotate_point_cloud(current_data[start_idx:end_idx, :, :])
jittered_data = provider.jitter_point_cloud(rotated_data)
pointnet工程中,current_data取出batchsize个pointnet模型数据。作为输入参数
def rotate_point_cloud(batch_data):
""" Randomly rotate the point clouds to augument the dataset
rotation is per shape based along up direction
Input:
BxNx3 array, original batch of point clouds
Return:
BxNx3 array, rotated batch of point clouds
"""
rotated_data = np.zeros(batch_data.shape, dtype=np.float32)
for k in range(batch_data.shape[0]):
rotation_angle = np.random.uniform() * 2 * np.pi
cosval = np.cos(rotation_angle)
sinval = np.sin(rotation_angle)
rotation_matrix = np.array([[cosval, 0, sinval],
[0, 1, 0],
[-sinval, 0, cosval]])
shape_pc = batch_data[k, ...]
rotated_data[k, ...] = np.dot(shape_pc.reshape((-1, 3)), rotation_matrix)
return rotated_data
首先声明一个32,1024,3的array,类型是float,设置为0
然后进入循环,从0~31
首先产生0~1之间的随机数,乘以2Π,得到一个角度。
然后求此角度的cos和sin
最后组成一个3x3的旋转矩阵
最后先将1,1024,3的np array reshape为1024,3的array与旋转矩阵相乘,得到旋转的point点云模型数据,最后返回作为训练的输入,这是又增加一次样本量
接着我们来看下一句的具体定义
def jitter_point_cloud(batch_data, sigma=0.01, clip=0.05):
""" Randomly jitter points. jittering is per point.
Input:
BxNx3 array, original batch of point clouds
Return:
BxNx3 array, jittered batch of point clouds
"""
B, N, C = batch_data.shape
assert(clip > 0)
jittered_data = np.clip(sigma * np.random.randn(B, N, C), -1*clip, clip)
jittered_data += batch_data
return jittered_data
这里不难看出,是随机一个shape为32,1024,3的array值为0~0.01之间,最大值为0.05最小值为-0.05,然后跟刚刚旋转过的模型进行相加得到新的data
由此可见这两个参数的作用就是对模型数据进行旋转平移,达到多增加训练数据的目的