Пример #1
0
 def __init__(self, num_points=2500, global_feat=True, routing=None):
     super(PointNetfeat_vanilla, self).__init__()
     self.stn = input_transform_net(num_points=num_points)
     self.routing = routing
     self.conv1 = nn.Conv1D(64, 1)
     self.conv2 = nn.Conv1D(128, 1)
     self.conv3 = nn.Conv1D(1024, 1)
     self.bn1 = nn.BatchNorm(in_channels=64)
     self.bn2 = nn.BatchNorm(in_channels=128)
     self.bn3 = nn.BatchNorm(in_channels=1024)
     self.mp1 = nn.MaxPool1D(num_points)
     self.num_points = num_points
     self.global_feat = global_feat
Пример #2
0
def get_model(point_cloud, is_training, bn_decay=None):
    """
        Classification PointNetwork
        :param point_cloud: input pointcloud BxNx3
        :param is_training: training flag
        :param bn_decay: decay flag
        :return: output model BxNx50
    """
    batch_size = point_cloud.get_shape()[0].value
    num_point = point_cloud.get_shape()[1].value
    end_points = {}
    with tf.variable_scope('transform_net1') as sc:
        transform = input_transform_net(point_cloud, is_training, bn_decay, K=3)
    point_cloud_transformed = tf.matmul(point_cloud, transform)
    input_image = tf.expand_dims(point_cloud_transformed, -1)
    net = tf_util.conv2d(input_image, 64, [1, 3], padding='VALID', stride=[1, 1], bn=True, is_training=is_training,
                         scope='conv1', bn_decay=bn_decay)
    net = tf_util.conv2d(net, 64, [1, 1], padding='VALID', stride=[1, 1], bn=True, is_training=is_training,
                         scope='conv2', bn_decay=bn_decay)
    with tf.variable_scope('transform_net2') as sc:
        transform = feature_transform_net(net, is_training, bn_decay, K=64)
    end_points['transform'] = transform
    net_transformed = tf.matmul(tf.squeeze(net, axis=[2]), transform)
    point_feat = tf.expand_dims(net_transformed, [2])
    print(point_feat)
    net = tf_util.conv2d(point_feat, 64, [1, 1], padding='VALID', stride=[1, 1], bn=True, is_training=is_training,
                         scope='conv3', bn_decay=bn_decay)
    net = tf_util.conv2d(net, 128, [1, 1], padding='VALID', stride=[1, 1], bn=True, is_training=is_training,
                         scope='conv4', bn_decay=bn_decay)
    net = tf_util.conv2d(net, 1024, [1, 1], padding='VALID', stride=[1, 1], bn=True, is_training=is_training,
                         scope='conv5', bn_decay=bn_decay)
    global_feat = tf_util.max_pool2d(net, [num_point, 1], padding='VALID', scope='maxpool')
    print(global_feat)
    global_feat_expand = tf.tile(global_feat, [1, num_point, 1, 1])
    concat_feat = tf.concat(3, [point_feat, global_feat_expand])
    print(concat_feat)
    net = tf_util.conv2d(concat_feat, 512, [1, 1], padding='VALID', stride=[1, 1], bn=True, is_training=is_training,
                         scope='conv6', bn_decay=bn_decay)
    net = tf_util.conv2d(net, 256, [1, 1], padding='VALID', stride=[1, 1], bn=True, is_training=is_training,
                         scope='conv7', bn_decay=bn_decay)
    net = tf_util.conv2d(net, 128, [1, 1], padding='VALID', stride=[1, 1], bn=True, is_training=is_training,
                         scope='conv8', bn_decay=bn_decay)
    net = tf_util.conv2d(net, 128, [1, 1], padding='VALID', stride=[1, 1], bn=True, is_training=is_training,
                         scope='conv9', bn_decay=bn_decay)
    net = tf_util.conv2d(net, 50, [1, 1], padding='VALID', stride=[1, 1], activation_fn=None, scope='conv10')
    net = tf.squeeze(net, [2])  # BxNxC
    return net, end_points
Пример #3
0
def get_model(inputs, is_training, bn_decay=None, num_class=40, FLAGS=None):
    """ Classification PointNet, input is BxNx3, output Bx40 """
    point_cloud = inputs[:, :, 0:3]
    if FLAGS.normal:
        D = 6
        points = inputs[:, :, 3:]
    else:
        D = 3
        points = None

    # --------------------------------------- STN -------------------------------------
    if FLAGS.STN:
        with tf.variable_scope('transform_net') as sc:
            transform = input_transform_net(point_cloud,
                                            is_training,
                                            bn_decay,
                                            K=3)
        point_cloud = tf.matmul(point_cloud, transform)

    # ---------------------------------- Node Sampling --------------------------------
    with tf.variable_scope('group_sampling') as sc:
        KNN = FLAGS.KNN
        point_cloud_sampled, nn_points, _, _ = sample_and_group(
            npoint=FLAGS.node_num,
            radius=0.2,
            nsample=KNN,
            xyz=point_cloud,
            points=points,
            knn=True,
            use_xyz=True)

    point_cloud_sampled = tf.expand_dims(point_cloud_sampled, axis=-1)
    net1 = tf_util.conv2d(point_cloud_sampled,
                          64, [1, 3],
                          padding='VALID',
                          stride=[1, 1],
                          bn=True,
                          is_training=is_training,
                          scope='conv1_1',
                          bn_decay=bn_decay)
    net1 = tf.tile(net1, multiples=[1, 1, KNN, 1])
    net1 = tf.expand_dims(net1, axis=-2)

    nn_points = tf.expand_dims(nn_points, axis=-1)
    net = tf_util.conv3d(nn_points,
                         64, [1, 1, D],
                         padding='VALID',
                         stride=[1, 1, 1],
                         bn=True,
                         is_training=is_training,
                         scope='conv1_2',
                         bn_decay=bn_decay)
    concat = tf.concat(values=[net, net1], axis=-1)

    net = tf_util.conv3d(concat,
                         128, [1, 1, 1],
                         padding='VALID',
                         stride=[1, 1, 1],
                         bn=True,
                         is_training=is_training,
                         scope='conv2',
                         bn_decay=bn_decay)
    net = tf_util.conv3d(net,
                         128, [1, 1, 1],
                         padding='VALID',
                         stride=[1, 1, 1],
                         bn=True,
                         is_training=is_training,
                         scope='conv3',
                         bn_decay=bn_decay)

    # ---------------------- local pooling: merge local feature -------------------------
    if FLAGS.local_pool == 'average':
        pool_k = tf_util.avg_pool3d(net,
                                    kernel_size=[1, KNN, 1],
                                    stride=[1, 2, 2],
                                    padding='VALID',
                                    scope='pool_k')
    else:
        pool_k = tf_util.max_pool3d(net,
                                    kernel_size=[1, KNN, 1],
                                    stride=[1, 2, 2],
                                    padding='VALID',
                                    scope='pool_k')
    net = tf.squeeze(pool_k, axis=2)

    # ---------------------------------- VLAD layer --------------------------------------
    net, index = VLAD(net, FLAGS, is_training, bn_decay, layer_name='VLAD')

    # -------------------------------- classification ------------------------------------
    with tf.name_scope('fc_layer'):
        net = tf_util.fully_connected(net,
                                      512,
                                      bn=True,
                                      is_training=is_training,
                                      scope='fc1',
                                      bn_decay=bn_decay)
        net = tf_util.dropout(net,
                              keep_prob=0.7,
                              is_training=is_training,
                              scope='dp1')
        net = tf_util.fully_connected(net,
                                      256,
                                      bn=True,
                                      is_training=is_training,
                                      scope='fc2',
                                      bn_decay=bn_decay)
        net = tf_util.dropout(net,
                              keep_prob=0.7,
                              is_training=is_training,
                              scope='dp2')
        net = tf_util.fully_connected(net,
                                      num_class,
                                      activation_fn=None,
                                      scope='fc3')

    return net, index
Пример #4
0
def get_model(point_cloud, is_training, bn_decay=None):
    """
        Classification PointNet,
        input is BxNx3,
        output Bx40
    """
    batch_size = point_cloud.get_shape()[0].value
    num_point = point_cloud.get_shape()[1].value
    end_points = {}
    with tf.variable_scope('transform_net1') as sc:
        transform = input_transform_net(point_cloud,
                                        is_training,
                                        bn_decay,
                                        K=3)
    point_cloud_transformed = tf.matmul(point_cloud, transform)
    input_image = tf.expand_dims(point_cloud_transformed, -1)
    net = utils.tf_util.conv2d(input_image,
                               64, [1, 3],
                               padding='VALID',
                               stride=[1, 1],
                               bn=True,
                               is_training=is_training,
                               scope='conv1',
                               bn_decay=bn_decay)
    net = utils.tf_util.conv2d(net,
                               64, [1, 1],
                               padding='VALID',
                               stride=[1, 1],
                               bn=True,
                               is_training=is_training,
                               scope='conv2',
                               bn_decay=bn_decay)
    with tf.variable_scope('transform_net2') as sc:
        transform = feature_transform_net(net, is_training, bn_decay, K=64)
    end_points['transform'] = transform
    net_transformed = tf.matmul(tf.squeeze(net, axis=[2]), transform)
    net_transformed = tf.expand_dims(net_transformed, [2])
    net = utils.tf_util.conv2d(net_transformed,
                               64, [1, 1],
                               padding='VALID',
                               stride=[1, 1],
                               bn=True,
                               is_training=is_training,
                               scope='conv3',
                               bn_decay=bn_decay)
    net = utils.tf_util.conv2d(net,
                               128, [1, 1],
                               padding='VALID',
                               stride=[1, 1],
                               bn=True,
                               is_training=is_training,
                               scope='conv4',
                               bn_decay=bn_decay)
    net = utils.tf_util.conv2d(net,
                               1024, [1, 1],
                               padding='VALID',
                               stride=[1, 1],
                               bn=True,
                               is_training=is_training,
                               scope='conv5',
                               bn_decay=bn_decay)
    # Symmetric function: max pooling
    net = utils.tf_util.max_pool2d(net, [num_point, 1],
                                   padding='VALID',
                                   scope='maxpool')
    net = tf.reshape(net, [batch_size, -1])
    net = utils.tf_util.fully_connected(net,
                                        512,
                                        bn=True,
                                        is_training=is_training,
                                        scope='fc1',
                                        bn_decay=bn_decay)
    net = utils.tf_util.dropout(net,
                                keep_prob=0.7,
                                is_training=is_training,
                                scope='dp1')
    net = utils.tf_util.fully_connected(net,
                                        256,
                                        bn=True,
                                        is_training=is_training,
                                        scope='fc2',
                                        bn_decay=bn_decay)
    net = utils.tf_util.dropout(net,
                                keep_prob=0.7,
                                is_training=is_training,
                                scope='dp2')
    net = utils.tf_util.fully_connected(net,
                                        40,
                                        activation_fn=None,
                                        scope='fc3')
    return net, end_points
Пример #5
0
def get_model(point_cloud,
              is_training,
              classes,
              dtype=tf.float32,
              bn=True,
              bn_decay=None):
    """ Classification PointNet, input is BxNxF, output BxNxC
        B = number of images per batch
        N = number of points
        F = number of features
        C = number of classes """
    # batch_size = point_cloud.get_shape()[0].value
    global num_classes
    num_classes = classes
    num_point = point_cloud.get_shape()[1].value
    features = point_cloud.get_shape()[2].value
    end_points = {}

    with tf.compat.v1.variable_scope('transform_net1'):
        transform = input_transform_net(point_cloud,
                                        is_training,
                                        bn_decay,
                                        K=features,
                                        dtype=dtype)
    point_cloud_transformed = tf.matmul(point_cloud, transform)
    input_image = tf.expand_dims(point_cloud_transformed, -1)

    net = tf_util.conv2d(input_image,
                         64, [1, features],
                         padding='VALID',
                         stride=[1, 1],
                         bn=bn,
                         is_training=is_training,
                         scope='conv1',
                         bn_decay=bn_decay,
                         dtype=dtype)
    net = tf_util.conv2d(net,
                         64, [1, 1],
                         padding='VALID',
                         stride=[1, 1],
                         bn=bn,
                         is_training=is_training,
                         scope='conv2',
                         bn_decay=bn_decay,
                         dtype=dtype)

    with tf.compat.v1.variable_scope('transform_net2'):
        transform = feature_transform_net(net,
                                          is_training,
                                          bn_decay,
                                          K=64,
                                          dtype=dtype)
    end_points['transform'] = transform
    net_transformed = tf.matmul(tf.squeeze(net, axis=[2]), transform)
    point_feat = tf.expand_dims(net_transformed, [2])
    logger.info('point_feat = %s', point_feat)

    net = tf_util.conv2d(point_feat,
                         64, [1, 1],
                         padding='VALID',
                         stride=[1, 1],
                         bn=bn,
                         is_training=is_training,
                         scope='conv3',
                         bn_decay=bn_decay,
                         dtype=dtype)
    net = tf_util.conv2d(net,
                         128, [1, 1],
                         padding='VALID',
                         stride=[1, 1],
                         bn=bn,
                         is_training=is_training,
                         scope='conv4',
                         bn_decay=bn_decay,
                         dtype=dtype)
    net = tf_util.conv2d(net,
                         1024, [1, 1],
                         padding='VALID',
                         stride=[1, 1],
                         bn=bn,
                         is_training=is_training,
                         scope='conv5',
                         bn_decay=bn_decay,
                         dtype=dtype)
    global_feat = tf_util.max_pool2d(net, [num_point, 1],
                                     padding='VALID',
                                     scope='maxpool')
    logger.info('global_feat = %s', global_feat)

    global_feat_expand = tf.tile(global_feat, [1, num_point, 1, 1])
    concat_feat = tf.concat([point_feat, global_feat_expand], 3)
    logger.info('concat_feat = %s', concat_feat)

    net = tf_util.conv2d(concat_feat,
                         512, [1, 1],
                         padding='VALID',
                         stride=[1, 1],
                         bn=bn,
                         is_training=is_training,
                         scope='conv6',
                         bn_decay=bn_decay,
                         dtype=dtype)
    net = tf_util.conv2d(net,
                         256, [1, 1],
                         padding='VALID',
                         stride=[1, 1],
                         bn=bn,
                         is_training=is_training,
                         scope='conv7',
                         bn_decay=bn_decay,
                         dtype=dtype)
    net = tf_util.conv2d(net,
                         128, [1, 1],
                         padding='VALID',
                         stride=[1, 1],
                         bn=bn,
                         is_training=is_training,
                         scope='conv8',
                         bn_decay=bn_decay,
                         dtype=dtype)
    net = tf_util.conv2d(net,
                         128, [1, 1],
                         padding='VALID',
                         stride=[1, 1],
                         bn=bn,
                         is_training=is_training,
                         scope='conv9',
                         bn_decay=bn_decay,
                         dtype=dtype)

    net = tf_util.conv2d(net,
                         classes, [1, 1],
                         padding='VALID',
                         stride=[1, 1],
                         activation_fn=None,
                         scope='conv10',
                         dtype=dtype)
    net = tf.squeeze(net, [2])  # BxNxC
    logger.info('net = %s', net)

    return net, end_points
Пример #6
0
def get_model(point_cloud, is_training, bn_decay=None):
    """ Classification PointNet, input is BxNx3, output BxNx50 """
    batch_size = point_cloud.get_shape()[0].value
    num_point = point_cloud.get_shape()[1].value
    end_points = {}

    with tf.variable_scope('transform_net1') as sc:
        transform = input_transform_net(point_cloud,
                                        is_training,
                                        bn_decay,
                                        K=3)
    point_cloud_transformed = tf.matmul(point_cloud, transform)
    input_image = tf.expand_dims(point_cloud_transformed, -1)

    net = tf_util.conv2d(input_image,
                         64, [1, 3],
                         padding='VALID',
                         stride=[1, 1],
                         bn=True,
                         is_training=is_training,
                         scope='conv1',
                         bn_decay=bn_decay)
    net = tf_util.conv2d(net,
                         64, [1, 1],
                         padding='VALID',
                         stride=[1, 1],
                         bn=True,
                         is_training=is_training,
                         scope='conv2',
                         bn_decay=bn_decay)

    with tf.variable_scope('transform_net2') as sc:
        transform = feature_transform_net(net, is_training, bn_decay, K=64)
    end_points['transform'] = transform
    net_transformed = tf.matmul(tf.squeeze(net, axis=[2]), transform)
    point_feat = tf.expand_dims(net_transformed, [2])
    net = tf_util.conv2d(point_feat,
                         64, [1, 1],
                         padding='VALID',
                         stride=[1, 1],
                         bn=True,
                         is_training=is_training,
                         scope='conv3',
                         bn_decay=bn_decay)
    net = tf_util.conv2d(net,
                         128, [1, 1],
                         padding='VALID',
                         stride=[1, 1],
                         bn=True,
                         is_training=is_training,
                         scope='conv4',
                         bn_decay=bn_decay)
    net = tf_util.conv2d(net,
                         1024, [1, 1],
                         padding='VALID',
                         stride=[1, 1],
                         bn=True,
                         is_training=is_training,
                         scope='conv5',
                         bn_decay=bn_decay)
    global_feat = tf_util.max_pool2d(net, [num_point, 1],
                                     padding='VALID',
                                     scope='maxpool')
    global_feat_expand = tf.tile(global_feat, [1, num_point, 1, 1])
    concat_feat = tf.concat(axis=3,
                            values=[point_feat,
                                    global_feat_expand])  # (32,1024,1,1088)
    Fsem = tf_util.conv2d(concat_feat,
                          128, [1, 1],
                          padding='VALID',
                          stride=[1, 1],
                          bn=False,
                          is_training=is_training,
                          scope='Fsem')
    ptssemseg_logits = tf_util.conv2d(Fsem,
                                      50, [1, 1],
                                      padding='VALID',
                                      stride=[1, 1],
                                      activation_fn=None,
                                      scope='ptssemseg_logits')
    ptssemseg_logits = tf.squeeze(ptssemseg_logits, [2])

    # ptssemseg = tf.nn.softmax(ptssemseg_logits, name="ptssemseg")

    # Similarity matrix
    fts = tf.reshape(ptssemseg_logits, [batch_size, -1])
    H = HGNN.construct_H_with_KNN(fts)
    G = HGNN.generate_G_from_H(H)
    # G = tf.convert_to_tensor(G)
    net = tf_util.fully_connected(fts,
                                  128,
                                  bn=True,
                                  is_training=is_training,
                                  scope='fc1',
                                  bn_decay=bn_decay)
    net = tf.matmul(G, net)
    net = tf_util.fully_connected(net,
                                  40,
                                  bn=True,
                                  is_training=is_training,
                                  scope='fc2',
                                  bn_decay=bn_decay)
    net = tf.matmul(G, net)

    return net, end_points
Пример #7
0
def get_model_other(point_cloud, is_training, bn_decay=None):
    """ Classification PointNet, input is BxNx3 and BxNx1, output Bx4 """
    batch_size = point_cloud.get_shape()[0]  # .value
    num_point = point_cloud.get_shape()[1]  # .value
    end_points = {}

    # transform net for input x,y,z
    with tf.compat.v1.variable_scope('transform_net1') as sc:
        transform = input_transform_net(point_cloud[:, :, 1:4],
                                        is_training,
                                        bn_decay,
                                        K=3)
    point_cloud_transformed = tf.matmul(point_cloud[:, :, 1:4], transform)
    input_image = tf.expand_dims(point_cloud_transformed, -1)

    # First MLP layers
    net = tf_util.conv2d(input_image,
                         64, [1, 3],
                         padding='VALID',
                         stride=[1, 1],
                         bn=True,
                         is_training=is_training,
                         scope='conv1',
                         bn_decay=bn_decay)
    net = tf_util.conv2d(net,
                         64, [1, 1],
                         padding='VALID',
                         stride=[1, 1],
                         bn=True,
                         is_training=is_training,
                         scope='conv2',
                         bn_decay=bn_decay)

    # transform net for the features
    with tf.compat.v1.variable_scope('transform_net2') as sc:
        transform = feature_transform_net(net, is_training, bn_decay, K=64)
    end_points['transform'] = transform
    net_transformed = tf.matmul(tf.squeeze(net, axis=[2]), transform)
    # point_feat = tf.expand_dims(net_transformed, [2])

    # add the additional features to the second MLP layers
    # point_cloud_SF = tf.expand_dims(point_cloud[:, :, 0:1], [2])
    concat_other = tf.concat(axis=2,
                             values=[
                                 point_cloud[:, :, 0:1], net_transformed,
                                 point_cloud[:, :, 4:para.dim]
                             ])
    concat_other = tf.expand_dims(concat_other, [2])

    # second MLP layers
    net = tf_util.conv2d(
        concat_other,
        64,
        [1, 1],  # 64 is the output #neuron
        padding='VALID',
        stride=[1, 1],
        bn=True,
        is_training=is_training,
        scope='conv3',
        bn_decay=bn_decay)
    net = tf_util.conv2d(net,
                         128, [1, 1],
                         padding='VALID',
                         stride=[1, 1],
                         bn=True,
                         is_training=is_training,
                         scope='conv4',
                         bn_decay=bn_decay)
    net = tf_util.conv2d(net,
                         1024, [1, 1],
                         padding='VALID',
                         stride=[1, 1],
                         bn=True,
                         is_training=is_training,
                         scope='conv5',
                         bn_decay=bn_decay)

    # Symmetric function: max pooling
    net = tf_util.max_pool2d(net, [num_point, 1],
                             padding='VALID',
                             scope='maxpool')

    net = tf.reshape(net, [batch_size, -1])
    net = tf_util.fully_connected(net,
                                  512,
                                  bn=True,
                                  is_training=is_training,
                                  scope='fc1',
                                  bn_decay=bn_decay)
    net = tf_util.dropout(net,
                          keep_prob=0.7,
                          is_training=is_training,
                          scope='dp1')
    net = tf_util.fully_connected(net,
                                  256,
                                  bn=True,
                                  is_training=is_training,
                                  scope='fc2',
                                  bn_decay=bn_decay)
    net = tf_util.dropout(net,
                          keep_prob=0.7,
                          is_training=is_training,
                          scope='dp2')
    net = tf_util.fully_connected(net, 4, activation_fn=None, scope='fc3')

    return net, end_points
Пример #8
0
def get_model(inputs, cls_label, is_training=None, bn_decay=None, NUM_CATEGORIES=16):
    """ Classification PointNet, input is BxNx3, output Bx40 """
    batch_size = inputs.get_shape()[0].value
    num_point = inputs.get_shape()[1].value
    point_cloud = inputs[:, :, 0:3]
    points = inputs[:, :, 3:]

    with tf.variable_scope('transform_net') as sc:
        transform = input_transform_net(point_cloud, is_training, bn_decay, K=3)
    point_cloud_transformed = tf.matmul(point_cloud, transform)

    with tf.variable_scope('group_sampling') as sc:
        KNN = 16
        Node_NUM = 256
        point_cloud_sampled, nn_points, _, _ = sample_and_group(npoint=Node_NUM, radius=0.2, nsample=KNN,
                                                                    xyz=point_cloud_transformed, points=points, knn=True, use_xyz=True)

    net1 = tf_util.conv2d(tf.expand_dims(point_cloud_sampled, axis=-1), 64, [1, 3],
                          padding='VALID', stride=[1, 1],
                          bn=True, is_training=is_training,
                          scope='conv1_1', bn_decay=bn_decay)
    net1 = tf.tile(net1, multiples=[1, 1, KNN, 1])
    net1 = tf.expand_dims(net1, axis=-2)

    nn_points = tf.expand_dims(nn_points, axis=-1)
    net = tf_util.conv3d(nn_points, 64, [1, 1, 6],
                         padding='VALID', stride=[1, 1, 1],
                         bn=True, is_training=is_training,
                         scope='conv1_2', bn_decay=bn_decay)
    concat = tf.concat(values=[net, net1], axis=-1)

    net = tf_util.conv3d(concat, 128, [1, 1, 1],
                         padding='VALID', stride=[1, 1, 1],
                         bn=True, is_training=is_training,
                         scope='conv2', bn_decay=bn_decay)
    net = tf_util.conv3d(net, 128, [1, 1, 1],
                         padding='VALID', stride=[1, 1, 1],
                         bn=True, is_training=is_training,
                         scope='conv3', bn_decay=bn_decay)
    pool_k = tf_util.max_pool3d(net, kernel_size=[1, KNN, 1],
                                stride=[1, 2, 2], padding='VALID', scope='pool_k')
    net = tf.squeeze(pool_k, axis=2)

    # vlad layer
    vlad_out, index = VLAD_part(net, 50, is_training, bn_decay, layer_name='VLAD')

    vlad_out = tf_util.conv2d(vlad_out, 384, [1, 1],
                              padding='VALID', stride=[1, 1],
                              bn=True, is_training=is_training,
                              scope='vlad_conv3', bn_decay=bn_decay)
    vlad_out = tf_util.conv2d(vlad_out, 512, [1, 1],
                              padding='VALID', stride=[1, 1],
                              bn=True, is_training=is_training,
                              scope='vlad_conv4', bn_decay=bn_decay)
    out_max = tf.nn.max_pool(vlad_out, ksize=[1, Node_NUM, 1, 1], strides=[1, 2, 2, 1],
                             padding='VALID')

    expand = tf.tile(out_max, multiples=[1,Node_NUM,1,1])
    concat = tf.concat([expand, vlad_out, net], axis=-1)

    concat = tf_util.conv2d(concat, 512, [1, 1],
                            padding='VALID', stride=[1, 1],
                            bn=True, is_training=is_training,
                            scope='conv4', bn_decay=bn_decay)
    concat = tf_util.conv2d(concat, 256, [1, 1],
                            padding='VALID', stride=[1, 1],
                            bn=True, is_training=is_training,
                            scope='conv5', bn_decay=bn_decay)
    concat = tf.squeeze(concat, axis=2)

    # segmentation network
    cls_label_one_hot = tf.one_hot(cls_label, depth=NUM_CATEGORIES, on_value=1.0, off_value=0.0)
    cls_label_one_hot = tf.reshape(cls_label_one_hot, [batch_size, 1, NUM_CATEGORIES])
    cls_label_one_hot = tf.tile(cls_label_one_hot, [1, num_point, 1])
    l0_points = pointnet_fp_module(xyz1=point_cloud_transformed, xyz2=point_cloud_sampled, points1=tf.concat([cls_label_one_hot, point_cloud_transformed, points], axis=-1),
                                   points2=concat, mlp=[128, 128], is_training=is_training, bn_decay=bn_decay, scope='layer6')

    l0_points = tf.expand_dims(l0_points, axis=2)
    net = tf_util.conv2d(l0_points, 128, [1, 1], padding='VALID', stride=[1, 1], 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.conv2d(net, 50, [1, 1], padding='VALID', stride=[1, 1], activation_fn=None, scope='fc2')
    net = tf.squeeze(net, axis=2)

    return net, index
Пример #9
0
def get_model(point_cloud, is_training, bn_decay=None):
    """ Classification PointNet, input is BxNx3, output Bx40 """
    with tf.variable_scope('transform_net') as sc:
        transform = input_transform_net(point_cloud,
                                        is_training,
                                        bn_decay,
                                        K=3)
    point_cloud_transformed = tf.matmul(point_cloud, transform)

    # KNN local search
    #knn_point = KNN_search(point_cloud_transformed, KNN=KNN, name_scope='KNN_search')  # 32 x 1024 x KNN x 6
    #knn_point = tf.expand_dims(knn_point, axis=-1)  # 32 x 1024 x KNN x 3 x 1

    with tf.variable_scope('group_sampling') as sc:
        KNN = 16
        point_cloud_transformed, _, _, nn_points = sample_and_group(
            npoint=1024,
            radius=0.1,
            nsample=KNN,
            xyz=point_cloud_transformed,
            points=None,
            knn=True,
            use_xyz=False)

    point_cloud_transformed = tf.expand_dims(point_cloud_transformed, axis=-1)
    net1 = tf_util.conv2d(point_cloud_transformed,
                          64, [1, 3],
                          padding='VALID',
                          stride=[1, 1],
                          bn=True,
                          is_training=is_training,
                          scope='conv1_1',
                          bn_decay=bn_decay)  # 32 x 1024 x 1 x 64
    net1 = tf.tile(net1, multiples=[1, 1, KNN, 1])  # 32 x 1024 x 16 x 64
    net1 = tf.expand_dims(net1, axis=-2)

    nn_points = tf.expand_dims(nn_points, axis=-1)  # 32 x 1024 x 16 x 3 x 1
    net = tf_util.conv3d(nn_points,
                         64, [1, 1, 3],
                         padding='VALID',
                         stride=[1, 1, 1],
                         bn=True,
                         is_training=is_training,
                         scope='conv1_2',
                         bn_decay=bn_decay)  # 32 x 1024 x 16 x 1 x 64
    concat = tf.concat(values=[net, net1], axis=-1)

    net = tf_util.conv3d(concat,
                         128, [1, 1, 1],
                         padding='VALID',
                         stride=[1, 1, 1],
                         bn=True,
                         is_training=is_training,
                         scope='conv2',
                         bn_decay=bn_decay)
    net = tf_util.conv3d(net,
                         128, [1, 1, 1],
                         padding='VALID',
                         stride=[1, 1, 1],
                         bn=True,
                         is_training=is_training,
                         scope='conv3',
                         bn_decay=bn_decay)
    # local pooling: merge local feature
    pool_k = tf_util.max_pool3d(net,
                                kernel_size=[1, KNN, 1],
                                stride=[1, 2, 2],
                                padding='VALID',
                                scope='pool_k')  # 32 x 1024 x 1 x 1 x 128
    net1 = tf.squeeze(pool_k, axis=2)

    # VLAD layer
    net2, index = VLAD(net1,
                       16,
                       is_training,
                       bn_decay,
                       layer_name='VLAD_layer1')

    net = VLAD_layer(net2,
                     net1,
                     16,
                     is_training,
                     bn_decay,
                     layer_name='VLAD_layer2')

    # classification
    with tf.name_scope('fc_layer'):
        net = tf_util.fully_connected(net,
                                      512,
                                      bn=True,
                                      is_training=is_training,
                                      scope='fc1',
                                      bn_decay=bn_decay)
        net = tf_util.dropout(net,
                              keep_prob=0.7,
                              is_training=is_training,
                              scope='dp1')
        net = tf_util.fully_connected(net,
                                      256,
                                      bn=True,
                                      is_training=is_training,
                                      scope='fc2',
                                      bn_decay=bn_decay)
        net = tf_util.dropout(net,
                              keep_prob=0.7,
                              is_training=is_training,
                              scope='dp2')
        net = tf_util.fully_connected(net, 40, activation_fn=None, scope='fc3')

    return net, index