点云深度学习系列2——PointNet/PointCNN代码比较(变换矩阵部分)

PointNet与PointCNN从文章到代码都有很多相似之处,两者对比看待,或许更有助于我们理解。

众所周知,PointNet中使用了maxpooling和T-net,作者文章中起到关键作用的是maxpooling,而T-net对性能的提升作用也还是有的(两个T-net加上regularization 贡献了2.1个百分点),但奇怪的是在PointNet++的代码中,已经看不到T-net了(这一点论文没有提及,github上也有人提问,但是作者没有回复)。

但是,与之相似的PointCNN中有个X变换矩阵,但X变换对于PointCNN的作用可就非常重要了,因为它连maxpooling都没有用。下面我们就对两者进行比较。

首先是PointNet中的T-net代码:

def feature_transform_net(inputs, is_training, bn_decay=None, K=64):
    """ Feature Transform Net, input is BxNx1xK
        Return:
            Transformation matrix of size KxK """
    batch_size = inputs.get_shape()[0].value
    num_point = inputs.get_shape()[1].value

    net = tf_util.conv2d(inputs, 64, [1,1],
                         padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training,
                         scope='tconv1', bn_decay=bn_decay)
    net = tf_util.conv2d(net, 128, [1,1],
                         padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training,
                         scope='tconv2', bn_decay=bn_decay)
    net = tf_util.conv2d(net, 1024, [1,1],
                         padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training,
                         scope='tconv3', bn_decay=bn_decay)
    net = tf_util.max_pool2d(net, [num_point,1],#池化窗口是[num_point,1]
                             padding='VALID', scope='tmaxpool')

    net = tf.reshape(net, [batch_size, -1])#变成两维
    net = tf_util.fully_connected(net, 512, bn=True, is_training=is_training,
                                  scope='tfc1', bn_decay=bn_decay)
    net = tf_util.fully_connected(net, 256, bn=True, is_training=is_training,
                                  scope='tfc2', bn_decay=bn_decay)

    with tf.variable_scope('transform_feat') as sc:
        weights = tf.get_variable('weights', [256, K*K],
                                  initializer=tf.constant_initializer(0.0),
                                  dtype=tf.float32)
        biases = tf.get_variable('biases', [K*K],
                                 initializer=tf.constant_initializer(0.0),
                                 dtype=tf.float32)
        biases += tf.constant(np.eye(K).flatten(), dtype=tf.float32)
        transform = tf.matmul(net, weights)
        transform = tf.nn.bias_add(transform, biases)

    transform = tf.reshape(transform, [batch_size, K, K])
    return transform
代码主题部分,前三个conv2d用来升维,接着一个max_pool2d把1024个点的特征做了maxpooling,融合成一点。然后跟两个fully_connected把维度降到256,再然后是跟[256, K*K]的权值相乘再加K*K维的偏移,达到[batch_size, K*K],最后变形成[batch_size, K, K],大功告成,不容易啊。
接下来看PointCNN的X变换:

       ######################## X-transformation #########################
        X_0 = pf.conv2d(nn_pts_local_bn, K * K, tag + 'X_0', is_training, (1, K), with_bn=False)
        #kernal size(1, K, 3), kernal num=K*K, so the output size is (N, P, 1, K*K). so this operator is in the neighbor point dimentional.
        X_1 = pf.dense(X_0, K * K, tag + 'X_1', is_training, with_bn=False)#in the center point dimensional ,P decrease to 1.
        X_2 = pf.dense(X_1, K * K, tag + 'X_2', is_training, with_bn=False, activation=None)#(N, P, 1, K*K)
        X = tf.reshape(X_2, (N, P, K, K), name=tag + 'X')
        fts_X = tf.matmul(X, nn_fts_input, name=tag + 'fts_X')
        ###################################################################
第一层是卷积层,让人很吃惊,卷积核是1*k的,也就是在邻域维度上,直接把k个邻域点汇聚到一个点上,且用了K×K个卷积层,把特征维度升高到k*k,维度从(P,K,C)变成了(P,1,K×K);然后 ,作者用了两个dense层,保持了这个结构; 最后reshape成(P,K,K),这就得到了X-transporm矩阵。

从体量和复杂程度上来看,后者胜出。

从作用效果来看,不太好评价。因为PointCNN是有局部特征的,这点和pointnet++思想一致。所以即便PointCNN性能超过了PointNet,也不能直接证明X-transporm就一定优于T-net了。

代码方面,其实T-net的前四层和X变换的第一层做的事情差不多,都是为了把多个点的特征融合到一组特征,为训练变换矩阵提供素材。但接下来就不同了,T-net只有一组K*K的weights权值,而PointCNN后面跟了两个dense层,维度都是K*K的,参数更多,因此猜测PointCNN训练变换矩阵应该会更加充分。后期可以通过实验验证以下。

最后歪个楼,我在测试PointNet++的代码时,ModelNet40的分类结果一直徘徊在90.1左右,达不到论文里提的90.7,跟作者邮件联系也没有得到很好的答案。所以我再想是不是作者本来的PointNet++代码里是有T-net的,但是放到github里的版本没加上。但这只是猜测,有待验证。

附上相关代码的链接:

PointNet2:https://github.com/charlesq34/pointnet2

PointCNN:https://github.com/yangyanli/PointCNN

也欢迎关注公众号——3D点云深度学习。


猜你喜欢

转载自blog.csdn.net/qq_33278989/article/details/80248483
今日推荐