Exemplo n.º 1
0
def get_model(point_cloud, is_training, num_class, bn_decay=None, feature=None):
    """ Semantic segmentation PointNet, input is B x N x 3, output B x num_class """
    end_points = {}
    l0_xyz = point_cloud
    l0_points = feature
    end_points['l0_xyz'] = l0_xyz

    # c0
    c0_l0_xyz, c0_l0_points, c0_l0_indices = DFCN_res_module(l0_xyz, l0_points, radius=2, out_channel=64, is_training=is_training, bn_decay=bn_decay, scope='layer0_c0', merge='concat')
    l1_xyz, l1_points, l1_indices = pointnet_sa_module(c0_l0_xyz, c0_l0_points, npoint=1024, radius=2, nsample=32, mlp=[64,128], mlp2=None, group_all=False, is_training=is_training, bn_decay=bn_decay, scope='layer1')

    # c1
    c0_l1_xyz, c0_l1_points, c0_l1_indices = DFCN_res_module(l1_xyz, l1_points, radius=5, out_channel=128, is_training=is_training, bn_decay=bn_decay, scope='layer1_c0')
    l2_xyz, l2_points, l2_indices = pointnet_sa_module(c0_l1_xyz, c0_l1_points, npoint=256, radius=4, nsample=32, mlp=[128,256], mlp2=None, group_all=False, is_training=is_training, bn_decay=bn_decay, scope='layer2')

    # c2
    c0_l2_xyz, c0_l2_points, c0_l2_indices = DFCN_res_module(l2_xyz, l2_points, radius=10, out_channel=256, is_training=is_training, bn_decay=bn_decay, scope='layer2_c0')
    c1_l2_xyz, c1_l2_points, c1_l2_indices = DFCN_res_module(c0_l2_xyz, c0_l2_points, radius=10, out_channel=512, is_training=is_training, bn_decay=bn_decay, scope='layer2_c1', same_dim=True)
    l2_cat_points = tf.concat([c0_l2_points, c1_l2_points], axis=-1)
    fc_l2_points = tf_util.conv1d(l2_cat_points, 512, 1, padding='VALID', bn=True, is_training=is_training, scope='conv_2_fc', bn_decay=bn_decay)

    # c3
    l3_xyz, l3_points, l3_indices = pointnet_sa_module(c1_l2_xyz, fc_l2_points, npoint=64, radius=8, nsample=32, mlp=[512,512], mlp2=None, group_all=False, is_training=is_training, bn_decay=bn_decay, scope='layer3')

    l2_points = pointnet_fp_module(l2_xyz, l3_xyz, l2_points, l3_points, [512,512], is_training, bn_decay, scope='fa_layer2')
    _, l2_points_1, _ = DFCN_module(l2_xyz, l2_points, radius=10, out_channel=512, is_training=is_training, bn_decay=bn_decay, scope='fa_layer2_c0')
    _, l2_points_2, _ = DFCN_module(l2_xyz, l2_points, radius=10, out_channel=512, is_training=is_training, bn_decay=bn_decay, scope='fa_layer2_c1')
    _, l2_points_3, _ = DFCN_module(l2_xyz, l2_points, radius=10, out_channel=512, is_training=is_training, bn_decay=bn_decay, scope='fa_layer2_c2')

    l2_points = tf.concat([l2_points_1, l2_points_2, l2_points_3], axis=-1)
    l2_points = tf_util.conv1d(l2_points, 512, 1, padding='VALID', bn=True, is_training=is_training, scope='fa_2_fc', bn_decay=bn_decay)

    l1_points = pointnet_fp_module(l1_xyz, l2_xyz, l1_points, l2_points, [256,256], is_training, bn_decay, scope='fa_layer3')
    _, l1_points_1, _ = DFCN_module(l1_xyz, l1_points, radius=5, out_channel=256, is_training=is_training, bn_decay=bn_decay, scope='fa_layer3_c0')
    _, l1_points_2, _ = DFCN_module(l1_xyz, l1_points_1, radius=5, out_channel=256, is_training=is_training, bn_decay=bn_decay, scope='fa_layer3_c1')
    l1_points = tf.concat([l1_points_1, l1_points_2], axis=-1)
    l1_points = tf_util.conv1d(l1_points, 256, 1, padding='VALID', bn=True, is_training=is_training, scope='fa_1_fc', bn_decay=bn_decay)

    l0_points = pointnet_fp_module(l0_xyz, l1_xyz, l0_points, l1_points, [128,128,128], is_training, bn_decay, scope='fa_layer4')
    _, l0_points, _ = DFCN_module(l0_xyz, l0_points, radius=2, out_channel=128, is_training=is_training, bn_decay=bn_decay, scope='fa_layer4_c0')

    # FC layers
    net = tf_util.conv1d(l0_points, 128, 1, padding='VALID', bn=True, is_training=is_training, scope='fc1', bn_decay=bn_decay)
    net = tf_util.dropout(net, keep_prob=0.5, is_training=is_training, scope='dp1')
    net = tf_util.conv1d(net, num_class, 1, padding='VALID', activation_fn=None, scope='fc2')

    return net, end_points
Exemplo n.º 2
0
def pointSIFT_res_module(xyz, points, radius, out_channel, is_training, bn_decay, scope='point_sift', bn=True, use_xyz=True, same_dim=False, merge='add'):
    data_format = 'NHWC'
    with tf.compat.v1.variable_scope(scope) as sc:
        # conv1
        _, new_points, idx, _ = pointSIFT_group(radius, xyz, points, use_xyz=use_xyz)

        for i in range(3):
            new_points = tf_util.conv2d(new_points, out_channel, [1, 2],
                                        padding='VALID', stride=[1, 2],
                                        bn=bn, is_training=is_training,
                                        scope='c0_conv%d' % (i), bn_decay=bn_decay,
                                        data_format=data_format)
        new_points = tf.squeeze(new_points, [2])
        # conv2
        _, new_points, idx, _ = pointSIFT_group_with_idx(xyz, idx=idx, points=new_points, use_xyz=use_xyz)

        for i in range(3):
            if i == 2:
                act = None
            else:
                act = tf.nn.relu
            new_points = tf_util.conv2d(new_points, out_channel, [1, 2],
                                        padding='VALID', stride=[1, 2],
                                        bn=bn, is_training=is_training,
                                        scope='c1_conv%d' % (i), bn_decay=bn_decay,
                                        activation_fn=act,
                                        data_format=data_format)
        new_points = tf.squeeze(new_points, [2])
        # residual part..
        if points is not None:
            if same_dim is True:
                points = tf_util.conv1d(points, out_channel, 1, padding='VALID', bn=bn, is_training=is_training, scope='merge_channel_fc', bn_decay=bn_decay)
            if merge == 'add':
                new_points = new_points + points
            elif merge == 'concat':
                new_points = tf.concat([new_points, points], axis=-1)
            else:
                print("ways not found!!!")
        new_points = tf.nn.relu(new_points)
        return xyz, new_points, idx