示例#1
0
 def __init__(self, num_points=2500, global_feat=True, routing=None):
     super(PointNetfeat, self).__init__()
     self.stn1 = input_transform_net(num_points=num_points)
     self.stn2 = feature_transform_net(num_points=num_points, K=64)
     self.routing = routing
     self.conv1 = nn.Conv1D(64, 1)
     self.conv1_feat_trans = nn.Conv1D(64, 1)
     self.conv2 = nn.Conv1D(128, 1)
     self.conv3 = nn.Conv1D(1024, 1)
     self.bn1 = nn.BatchNorm(in_channels=64)
     self.bn1_feat_trans = 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(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
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
示例#5
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
示例#6
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