Ejemplo n.º 1
0
def pointnet_fp_module(xyz1, xyz2, points1, points2, mlp, is_training, bn_decay, scope, bn=True,ibn=False):
    ''' PointNet Feature Propogation (FP) Module
        Input:                                                                                                      
            xyz1: (batch_size, ndataset1, 3) TF tensor                                                              
            xyz2: (batch_size, ndataset2, 3) TF tensor, sparser than xyz1                                           
            points1: (batch_size, ndataset1, nchannel1) TF tensor                                                   
            points2: (batch_size, ndataset2, nchannel2) TF tensor
            mlp: list of int32 -- output size for MLP on each point                                                 
        Return:
            new_points: (batch_size, ndataset1, mlp[-1]) TF tensor
    '''
    with tf.variable_scope(scope) as sc:
        dist, idx = three_nn(xyz1, xyz2)
        dist = tf.maximum(dist, 1e-10)
        norm = tf.reduce_sum((1.0/dist),axis=2,keep_dims=True)
        norm = tf.tile(norm,[1,1,3])
        weight = (1.0/dist) / norm
        interpolated_points = three_interpolate(points2, idx, weight)

        if points1 is not None:
            new_points1 = tf.concat(axis=2, values=[interpolated_points, points1]) # B,ndataset1,nchannel1+nchannel2
        else:
            new_points1 = interpolated_points
        new_points1 = tf.expand_dims(new_points1, 2)
        for i, num_out_channel in enumerate(mlp):
            new_points1 = tf_util2.conv2d(new_points1, num_out_channel, [1,1],
                                         padding='VALID', stride=[1,1],
                                         bn=bn,is_training=is_training,
                                         scope='conv_%d'%(i), bn_decay=bn_decay)
        new_points1 = tf.squeeze(new_points1, [2]) # B,ndataset1,mlp[-1]
        return new_points1
Ejemplo n.º 2
0
 def test_grad(self):
     with self.test_session():
         points = tf.constant(
             np.random.random((1, 8, 16)).astype('float32'))
         print(points)
         xyz1 = tf.constant(np.random.random((1, 128, 3)).astype('float32'))
         xyz2 = tf.constant(np.random.random((1, 8, 3)).astype('float32'))
         dist, idx = three_nn(xyz1, xyz2)
         weight = tf.ones_like(dist) / 3.0
         interpolated_points = three_interpolate(points, idx, weight)
         print(interpolated_points)
         err = tf.test.compute_gradient_error(points, (1, 8, 16),
                                              interpolated_points,
                                              (1, 128, 16))
         print(err)
         self.assertLess(err, 1e-4)
Ejemplo n.º 3
0
def fun(xyz1, xyz2, pts2):
    with tf.device('/cpu:0'):
        points = tf.constant(np.expand_dims(pts2, 0))
        xyz1 = tf.constant(np.expand_dims(xyz1, 0))
        xyz2 = tf.constant(np.expand_dims(xyz2, 0))
        dist, idx = three_nn(xyz1, xyz2)
        # weight = tf.ones_like(dist)/3.0
        dist = tf.maximum(dist, 1e-10)
        norm = tf.reduce_sum((1.0 / dist), axis=2, keep_dims=True)
        norm = tf.tile(norm, [1, 1, 3])
        print(norm)
        weight = (1.0 / dist) / norm
        interpolated_points = three_interpolate(points, idx, weight)
    with tf.Session('') as sess:
        tmp, pts1, d, w = sess.run([xyz1, interpolated_points, dist, weight])
        # print w
        pts1 = pts1.squeeze()
    return pts1
Ejemplo n.º 4
0
def flex_conv_dilate(xyz,
                     feat,
                     dilate,
                     knn,
                     outdims,
                     scope,
                     knn_indices=None,
                     concat=True,
                     add_se='max_pool',
                     upsample=True,
                     **unused):
    num_point = xyz.get_shape()[1]
    npoint = num_point // dilate
    with tf.variable_scope(scope) as sc:
        if dilate > 1:
            points_sampled, feat_sampled, kp_indices = subsample(xyz,
                                                                 feat,
                                                                 npoint,
                                                                 kp_idx=None)
        else:
            points_sampled, feat_sampled = xyz, feat

        feats_T = tf.transpose(feat_sampled, perm=[0, 2, 1])
        points_T = tf.transpose(points_sampled, perm=[0, 2, 1])
        if knn_indices is None:  # B, knn, numpts
            knn_indices, distances = knn_bruteforce(points_T, k=knn)

        x = feats_T
        for i, d in enumerate(outdims):
            x = flexconv_withBatchnorm(x,
                                       points_T,
                                       knn_indices,
                                       d,
                                       name='flexconv_{}'.format(i))

        if add_se == 'max_pool':
            x_pool = flex_pooling(x, knn_indices, name='se_maxpool')
            newx = se_res_bottleneck(x, x_pool, outdims[-1],
                                     "se")  # l: B, 64, N
        elif add_se == 'avg_pool':
            x_pool = flex_avg(x,
                              points_T,
                              knn_indices,
                              outdims[-1],
                              name='se_avgpool')
            x_pool = x_pool * (1.0 / knn)
            newx = se_res_bottleneck(x, x_pool, outdims[-1],
                                     "se")  # l: B, 64, N
        else:
            newx = x

        new_feat = tf.transpose(newx, perm=[0, 2, 1])  # B, N, outdim

        # upsampling
        if upsample and dilate > 1:
            dist, idx = three_nn(xyz, points_sampled)
            dist = tf.maximum(dist, 1e-10)
            norm = tf.reduce_sum((1.0 / dist), axis=2, keep_dims=True)
            norm = tf.tile(norm, [1, 1, 3])
            weight = (1.0 / dist) / norm
            new_feat = three_interpolate(new_feat, idx, weight)

        if concat:
            new_feat = tf.concat(axis=2, values=[new_feat, feat])
            new_feat = feature_conv1d_1(new_feat,
                                        outdims[-1],
                                        name='concat_conv1d',
                                        c_last=True,
                                        ac_func=BNReLU)
        return xyz, new_feat