def get_transform(point_cloud, is_training, bn_decay=None, K = 3):
    """ Transform Net, input is BxNx3 gray image
        Return:
            Transformation matrix of size 3xK """
    batch_size = point_cloud.get_shape()[0].value
    num_point = point_cloud.get_shape()[1].value

    input_image = tf.expand_dims(point_cloud, -1)
    net = tf_util.conv2d(input_image, 64, [1,3], 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='tconv3', bn_decay=bn_decay)
    net = tf_util.conv2d(net, 1024, [1,1], padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training, scope='tconv4', bn_decay=bn_decay)
    net = tf_util.max_pool2d(net, [num_point,1], padding='VALID', scope='tmaxpool')

    net = tf.reshape(net, [batch_size, -1])
    net = tf_util.fully_connected(net, 128, bn=True, is_training=is_training, scope='tfc1', bn_decay=bn_decay)
    net = tf_util.fully_connected(net, 128, bn=True, is_training=is_training, scope='tfc2', bn_decay=bn_decay)

    with tf.variable_scope('transform_XYZ') as sc:
        assert(K==3)
        weights = tf.get_variable('weights', [128, 3*K], initializer=tf.constant_initializer(0.0), dtype=tf.float32)
        biases = tf.get_variable('biases', [3*K], initializer=tf.constant_initializer(0.0), dtype=tf.float32) + tf.constant([1,0,0,0,1,0,0,0,1], dtype=tf.float32)
        transform = tf.matmul(net, weights)
        transform = tf.nn.bias_add(transform, biases)

    #transform = tf_util.fully_connected(net, 3*K, activation_fn=None, scope='tfc3')
    transform = tf.reshape(transform, [batch_size, 3, K])
    return transform
def get_transform_K(inputs, is_training, bn_decay=None, K = 3):
    """ Transform Net, input is BxNx1xK gray image
        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, 256, [1,1], padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training, scope='tconv1', bn_decay=bn_decay)
    net = tf_util.conv2d(net, 1024, [1,1], padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training, scope='tconv2', bn_decay=bn_decay)
    net = tf_util.max_pool2d(net, [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) + tf.constant(np.eye(K).flatten(), dtype=tf.float32)
        transform = tf.matmul(net, weights)
        transform = tf.nn.bias_add(transform, biases)

    #transform = tf_util.fully_connected(net, 3*K, activation_fn=None, scope='tfc3')
    transform = tf.reshape(transform, [batch_size, K, K])
    return transform
Beispiel #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 = {}
    l0_xyz = point_cloud
    l0_points = None
    end_points['l0_xyz'] = l0_xyz

    # Set abstraction layers
    # Note: When using NCHW for layer 2, we see increased GPU memory usage (in TF1.4).
    # So we only use NCHW for layer 1 until this issue can be resolved.
    l1_xyz, l1_points, l1_indices = pointnet_sa_module(l0_xyz, l0_points, npoint=512, radius=0.2, nsample=32, mlp=[64,64,128], mlp2=None, group_all=False, is_training=is_training, bn_decay=bn_decay, scope='layer1', use_nchw=True)
    l2_xyz, l2_points, l2_indices = pointnet_sa_module(l1_xyz, l1_points, npoint=128, radius=0.4, nsample=64, mlp=[128,128,256], mlp2=None, group_all=False, is_training=is_training, bn_decay=bn_decay, scope='layer2')
    l3_xyz, l3_points, l3_indices = pointnet_sa_module(l2_xyz, l2_points, npoint=None, radius=None, nsample=None, mlp=[256,512,1024], mlp2=None, group_all=True, is_training=is_training, bn_decay=bn_decay, scope='layer3')

    # Fully connected layers
    net = tf.reshape(l3_points, [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.5, 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.5, is_training=is_training, scope='dp2')
    net = tf_util.fully_connected(net, 40, activation_fn=None, scope='fc3')

    return net, end_points
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 = 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)
    net_transformed = tf.expand_dims(net_transformed, [2])

    net = 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 = 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, 40, activation_fn=None, scope='fc3')

    return net, end_points
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 = {}
    input_image = tf.expand_dims(point_cloud, -1)
    
    # Point functions (MLP implemented as conv2d)
    net = tf_util.conv2d(input_image, 32, [1,9],
                         padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training,
                         scope='conv1', bn_decay=bn_decay)
    #net = tf_util.conv2d(net, 128, [1,1],
    #                     padding='VALID', stride=[1,1],
    #                     bn=True, is_training=is_training,
    #                     scope='conv2', bn_decay=bn_decay)
    
    #net = tf_util.conv2d(net, 128, [1,1],
    #                     padding='VALID', stride=[1,1],
    #                     bn=True, is_training=is_training,
    #                     scope='conv3', bn_decay=bn_decay)
    #net = tf.concat([net,net1, net2],axis=-1)
    #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
    maxpool_net = tf_util.max_pool2d(net, [num_point,1],
                             padding='VALID', scope='maxpool')
    avg_pool2d_net = tf_util.avg_pool2d(net, [num_point,1],
                             padding='VALID', scope='avgpool')
    
    net = tf.concat([avg_pool2d_net, maxpool_net], axis=3)
    #net = tf.concat([tf.reduce_sum(net,axis=1,keep_dims=True), net1], axis=3)
    # MLP on global point cloud vector
    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.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='dp1')
    net = tf_util.fully_connected(net, 40, activation_fn=None, scope='fc3')

    return net, end_points
def logmap(point_cloud, is_training,  batch_size=8,  activation=tf.nn.relu):
    """ ConvNet baseline, input is BxNx3 gray image """
    num_point = point_cloud.get_shape()[1].value
    euc_dists = safe_norm(point_cloud - tf.tile(point_cloud[:,0:1,:], [1,point_cloud.shape[1], 1]), axis = -1)[:,:,tf.newaxis]
    point_cloud = tf.concat([point_cloud, euc_dists], axis = 2)
    input_image = tf.expand_dims(point_cloud, -1)
    # CONV
    bn = False
    net = tf_util.conv2d(input_image, 64, [1,4], padding='VALID', stride=[1,1],
                         bn=bn, is_training=is_training, scope='conv1',activation_fn=activation)
    net = tf_util.conv2d(net, 64, [1,1], padding='VALID', stride=[1,1],
                         bn=bn, is_training=is_training, scope='conv2',activation_fn=activation)
    net = tf_util.conv2d(net, 128, [1,1], padding='VALID', stride=[1,1],
                         bn=bn, is_training=is_training, scope='conv3',activation_fn=activation)
    net = tf_util.conv2d(net, 256, [1,1], padding='VALID', stride=[1,1],
                         bn=bn, is_training=is_training, scope='conv4',activation_fn=activation)
    points_feat1 = tf_util.conv2d(net, 1024, [1,1], padding='VALID', stride=[1,1],
                         bn=bn, is_training=is_training, scope='conv5',activation_fn=activation)
    # MAX
    pc_feat1 = tf_util.max_pool2d(points_feat1, [num_point,1], padding='VALID', scope='maxpool1')
    # FC
    pc_feat1 = tf.reshape(pc_feat1, [batch_size, 1024])
    pc_feat1 = tf_util.fully_connected(pc_feat1, 1024, bn=bn, is_training=is_training, scope='fc1',activation_fn=activation)
    pc_feat1 = tf_util.fully_connected(pc_feat1, 1024, bn=bn, is_training=is_training, scope='fc2',activation_fn=activation)

    # CONCAT
    pc_feat1_expand = tf.tile(tf.reshape(pc_feat1, [batch_size, 1, 1, -1]), [1, num_point, 1, 1])

    points_feat1_concat = tf.concat(axis=3, values=[tf.expand_dims(point_cloud, -2), pc_feat1_expand])

    # CONV
    net = tf_util.conv2d(points_feat1_concat, 1024, [1,1], padding='VALID', stride=[1,1],
                         bn=bn, is_training=is_training, scope='conv6',activation_fn=activation)
    net = tf_util.conv2d(net, 528, [1,1], padding='VALID', stride=[1,1],
                         bn=bn, is_training=is_training, scope='conv7',activation_fn=activation)
    net = tf_util.conv2d(net, 3, [1,1], padding='VALID', stride=[1,1],
                         activation_fn=None, scope='conv8')
    euc_dists = safe_norm(net - tf.tile(net[:,0:1,:,:], [1,point_cloud.shape[1],1, 1]), axis = -1)[:,:,:,tf.newaxis]
    pc1 = net
    net = tf.concat([net, euc_dists], axis = 3)

    points_feat2_concat = tf.concat(axis=3, values=[net, pc_feat1_expand])
    net = tf_util.conv2d(points_feat2_concat, 1024, [1,1], padding='VALID', stride=[1,1],
                         bn=bn, is_training=is_training, scope='conv9',activation_fn=activation)
    net = tf_util.conv2d(net, 528, [1,1], padding='VALID', stride=[1,1],
                         bn=bn, is_training=is_training, scope='conv10',activation_fn=activation)
    net = tf_util.conv2d(net, 2, [1,1], padding='VALID', stride=[1,1],
                         activation_fn=None, scope='conv11')
    net = tf.squeeze(net,2)
    return net
def get_model(point_cloud, is_training, bn_decay=None):
    """ Autoencoder for point clouds.
    Input:
        point_cloud: TF tensor BxNx3
        is_training: boolean
        bn_decay: float between 0 and 1
    Output:
        net: TF tensor BxNx3, reconstructed point clouds
        end_points: dict
    """
    global num_point
    batch_size = point_cloud.get_shape()[0].value
    point_dim = point_cloud.get_shape()[2].value
    end_points = {}

    input_image = tf.expand_dims(point_cloud, -1)

    # Encoder
    net = tf_util.conv2d(input_image, 64, [1,point_dim],
                         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)
    point_feat = tf_util.conv2d(net, 64, [1,1],
                         padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training,
                         scope='conv3', bn_decay=bn_decay)
    net = tf_util.conv2d(point_feat, 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.reduce_max(net, axis=1, keepdims=False)

    net = tf.reshape(global_feat, [batch_size, -1])
    end_points['embedding'] = net

    # FC Decoder
    net = tf_util.fully_connected(net, 1024, bn=True, is_training=is_training, scope='fc1', bn_decay=bn_decay)
    net = tf_util.fully_connected(net, 1024, bn=True, is_training=is_training, scope='fc2', bn_decay=bn_decay)
    net = tf_util.fully_connected(net, num_point*3, activation_fn=None, scope='fc3')
    net = tf.reshape(net, (batch_size, num_point, 3))

    return net, end_points
Beispiel #8
0
def get_model(input_images, is_training, cat_num, batch_size, weight_decay,
              bn_decay):
    input_data = tf.expand_dims(input_images, -1)
    print input_data

    net = tf_util.conv2d(input_data, 128, [3, 3], stride=[1, 1], padding='VALID', scope='conv1', \
            weight_decay=weight_decay, bn_decay=bn_decay, bn=True, is_training=is_training)
    print net

    net = tf_util.conv2d(net, 256, [3, 3], stride=[1, 1], padding='VALID', scope='conv2', \
            weight_decay=weight_decay, bn_decay=bn_decay, bn=True, is_training=is_training)
    print net

    net = tf_util.conv2d(net, 512, [5, 5], stride=[1, 1], padding='VALID', scope='conv3', \
            weight_decay=weight_decay, bn_decay=bn_decay, bn=True, is_training=is_training)
    net = tf_util.max_pool2d(net, [2, 2],
                             stride=[2, 2],
                             scope='mp3',
                             padding='VALID')
    print net

    net = tf_util.conv2d(net, 512, [5, 5], stride=[1, 1], padding='VALID', scope='conv4', \
            weight_decay=weight_decay, bn_decay=bn_decay, bn=True, is_training=is_training)
    net = tf_util.max_pool2d(net, [2, 2],
                             stride=[2, 2],
                             scope='mp4',
                             padding='VALID')
    print net

    net = tf.reshape(net, [batch_size, -1])
    print net

    net = tf_util.fully_connected(net, 256, bn=True, is_training=is_training, \
            weight_decay=weight_decay, bn_decay=bn_decay, scope='fc1')
    net = tf_util.dropout(net,
                          is_training=is_training,
                          keep_prob=0.5,
                          scope='dp1')

    net = tf_util.fully_connected(net, 128, bn=True, is_training=is_training, \
            weight_decay=weight_decay, bn_decay=bn_decay, scope='fc2')
    net = tf_util.dropout(net,
                          is_training=is_training,
                          keep_prob=0.5,
                          scope='dp2')

    net = tf_util.fully_connected(net, cat_num, bn=False, is_training=is_training, \
            weight_decay=weight_decay, activation_fn=None, scope='fc3')

    return net
Beispiel #9
0
def get_model(point_cloud, is_training, bn_decay=None):
  """ Classification PointNet, input is BxNx3, output Bx40 """

  point_cloud_shape = point_cloud.get_shape()
  batch_size = point_cloud_shape[0].value
  num_points = point_cloud_shape[1].value
  num_dims = point_cloud_shape[2].value
  feature_list = []
  end_points = {}
  xyz = point_cloud
  

  point_cloud = tf.expand_dims(point_cloud, -2)
  net = tf_util.conv2d(point_cloud, 64, [1, 1],
                       padding='VALID', stride=[1, 1],
                       bn=True, is_training=is_training,
                       scope='mlp1',bn_decay=bn_decay)
 
  net = tf.squeeze(net)  
  net = transformer_block(net, xyz, num_points, 0, 32, is_training, bn_decay)
  new_xyz, net, grouped_xyz = trasit_down(net, xyz, 32, num_points/2, 1, is_training, bn_decay)


  net = transformer_block(net, new_xyz, num_points/2, 1, 64, is_training, bn_decay)
  new_xyz, net, grouped_xyz = trasit_down(net, new_xyz, 64, num_points/4, 2, is_training, bn_decay)

  net = transformer_block(net, new_xyz, num_points/4, 2, 128, is_training, bn_decay)
  new_xyz, net, grouped_xyz = trasit_down(net, new_xyz, 128, num_points/8, 3, is_training, bn_decay)

  net = transformer_block(net, new_xyz, num_points/8, 3, 256, is_training, bn_decay)
  new_xyz, net, grouped_xyz = trasit_down(net, new_xyz, 256, num_points/16, 3, is_training, bn_decay)

  net = transformer_block(net, new_xyz, num_points/16, 4, 512, is_training, bn_decay)

  print("net=", net.shape)
  net = tf.reduce_max(net, 1)

  # MLP on global point cloud vector
  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.5, 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.5, is_training=is_training,
                        scope='dp2')
  net = tf_util.fully_connected(net, 40, activation_fn=None, scope='fc3')

  return net, end_points, feature_list
Beispiel #10
0
def get_extractor2(net2,
                   is_training,
                   num_class,
                   params,
                   weight_decay=None,
                   bn_decay=None,
                   bn=True,
                   scname='',
                   reversal=False):

    if reversal:
        net = flip_gradient(net2, 40.0)
    else:
        net = net2
    net = tf_util.fully_connected(net,
                                  params[10],
                                  bn=bn,
                                  is_training=is_training,
                                  activation_fn=tf.nn.relu,
                                  scope=scname + 'fc1',
                                  bn_decay=bn_decay)
    net = tf_util.dropout(net,
                          keep_prob=0.5,
                          is_training=is_training,
                          scope=scname + 'dp1')

    net = tf_util.fully_connected(net,
                                  params[10],
                                  bn=bn,
                                  is_training=is_training,
                                  activation_fn=tf.nn.relu,
                                  scope=scname + 'fc2',
                                  bn_decay=bn_decay)
    net = tf_util.dropout(net,
                          keep_prob=0.7,
                          is_training=is_training,
                          scope=scname + 'dp2')
    net = tf_util.fully_connected(net,
                                  params[11],
                                  bn=bn,
                                  is_training=is_training,
                                  activation_fn=tf.nn.relu,
                                  scope=scname + 'fc3',
                                  bn_decay=bn_decay)
    net = tf_util.fully_connected(net,
                                  num_class,
                                  activation_fn=None,
                                  scope=scname + 'fc4')

    return net
def get_3d_box_estimation_v1_net(object_point_cloud, one_hot_vec, is_training, bn_decay, end_points):
    ''' 3D Box Estimation PointNet v1 network.
    Input:
        object_point_cloud: TF tensor in shape (B,M,C)
            point clouds in object coordinate
        one_hot_vec: TF tensor in shape (B,3)
            length-3 vectors indicating predicted object type
    Output:
        output: TF tensor in shape (B,3+NUM_HEADING_BIN*2+NUM_SIZE_CLUSTER*4)
            including box centers, heading bin class scores and residuals,
            and size cluster scores and residuals
    '''
    num_point = object_point_cloud.get_shape()[1].value
    net = tf.expand_dims(object_point_cloud, 2)                 # B×M×1×C
    # MLP(128,128,256,512)
    net = tf_util.conv2d(net, 128, [1, 1],
                         padding='VALID', stride=[1, 1],
                         bn=True, is_training=is_training,
                         scope='conv-reg1', bn_decay=bn_decay)  # B×M×1×128
    net = tf_util.conv2d(net, 128, [1, 1],
                         padding='VALID', stride=[1, 1],
                         bn=True, is_training=is_training,
                         scope='conv-reg2', bn_decay=bn_decay)  # B×M×1×128
    net = tf_util.conv2d(net, 256, [1, 1],
                         padding='VALID', stride=[1, 1],
                         bn=True, is_training=is_training,
                         scope='conv-reg3', bn_decay=bn_decay)  # B×M×1×256
    net = tf_util.conv2d(net, 512, [1, 1],
                         padding='VALID', stride=[1, 1],
                         bn=True, is_training=is_training,
                         scope='conv-reg4', bn_decay=bn_decay)  # B×M×1×512
    # max pool
    net = tf_util.max_pool2d(net, [num_point, 1],
                             padding='VALID', scope='maxpool2')  # B×1×1×512
    net = tf.squeeze(net, axis=[1, 2])                          # B×512
    net = tf.concat([net, one_hot_vec], axis=1)                 # B×515
    # FCs(512,256,3+4NS+2NH)
    net = tf_util.fully_connected(net, 512, scope='fc1', bn=True,
                                  is_training=is_training, bn_decay=bn_decay)  # B×512
    net = tf_util.fully_connected(net, 256, scope='fc2', bn=True,
                                  is_training=is_training, bn_decay=bn_decay)  # B×256

    # The first 3 numbers: box center coordinates (cx,cy,cz),
    # the next NUM_HEADING_BIN*2:  heading bin class scores and bin residuals
    # next NUM_SIZE_CLUSTER*4: box cluster scores and residuals
    output = tf_util.fully_connected(net,
                                     3 + NUM_HEADING_BIN * 2 + NUM_SIZE_CLUSTER * 4, activation_fn=None, scope='fc3')
    # B×(3+4NS+2NH)
    return output, end_points
Beispiel #12
0
def input_transform_net(point_cloud, is_training, num_point, bn_decay=None, K=3):
    """ Input (XYZ) Transform Net, input is BxNx3 gray image
        Return:
            Transformation matrix of size 3xK """
    batch_size = point_cloud.get_shape()[0].value
    # num_point = point_cloud.get_shape()[1].value

    input_image = tf.expand_dims(point_cloud, -1)
    net = tf_util.conv2d(input_image, 64, [1,3],
                         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) #(?, ?, 1, 1024)


    # net = tf_util.max_pool2d(net, [num_point,1],
    #                          padding='VALID', scope='tmaxpool')
    # net = tf.reshape(net, [batch_size, -1])
    #---------- 对源代码进行了修改,适应点数量变化 ----------
    net = tf.reduce_max(net, axis=1)
    net = tf.reshape(net, shape = [-1, 1024])


    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_XYZ') as sc:
        assert(K==3)
        weights = tf.get_variable('weights', [256, 3*K],
                                  initializer=tf.constant_initializer(0.0),
                                  dtype=tf.float32)
        biases = tf.get_variable('biases', [3*K],
                                 initializer=tf.constant_initializer(0.0),
                                 dtype=tf.float32)
        biases += tf.constant([1,0,0,0,1,0,0,0,1], dtype=tf.float32)
        transform = tf.matmul(net, weights)
        transform = tf.nn.bias_add(transform, biases)

    transform = tf.reshape(transform, [-1, 3, K])
    return transform
Beispiel #13
0
def PointNet(points, training_var, batch_size, bn_decay=None):

    input_image = tf.expand_dims(points, -1)

    points = tf.reshape(points, [-1,pointSize,3, 1])
    net = tf_util.conv2d(points, 64, [1, 3],  # input_image
                         padding='VALID', stride=[1, 1],
                         bn=True, is_training=training_var,
                         scope='conv1', bn_decay=bn_decay)
    # print('netshape')
    net = tf_util.conv2d(net, 64, [1, 1],
                         padding='VALID', stride=[1, 1],
                         bn=True, is_training=training_var,
                         scope='conv2', bn_decay=bn_decay)
    net = tf_util.conv2d(net, 256, [1, 1],
                         padding='VALID', stride=[1, 1],
                         bn=True, is_training=training_var,
                         scope='conv3', bn_decay=bn_decay)
    net = tf_util.conv2d(net, 512, [1, 1],
                         padding='VALID', stride=[1, 1],
                         bn=True, is_training=training_var,
                         scope='conv4', bn_decay=bn_decay)
    net = tf_util.conv2d(net, 1024, [1, 1],
                         padding='VALID', stride=[1, 1],
                         bn=True, is_training=training_var,
                         scope='conv5', bn_decay=bn_decay)
    print('before maxpool')
    print(net.get_shape())

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

    print(net.get_shape())


    print ('batch_size', batch_size)
    # MLP on global point cloud vector
    print('nethspe: ', net.get_shape())
    net = tf.reshape(net, [-1, 1024])
    net = tf_util.fully_connected(net, 512, bn=True, is_training=training_var,
                                  scope='fc1', bn_decay=bn_decay)
    net = tf_util.fully_connected(net, 256, bn=True, is_training=training_var,
                                  scope='fc2', bn_decay=bn_decay)
    pose = tf_util.fully_connected(net, 48, activation_fn=None, scope='fc3')
    print('posehape: ', pose.get_shape())
    return pose
    """PointNet model
Beispiel #14
0
def get_rot_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
    feature_dim = point_cloud.get_shape()[2].value
    end_points = {}
    input_image = tf.expand_dims(point_cloud, -1)

    # Point functions (MLP implemented as conv2d)
    net = tf_util.conv2d(input_image, 64, [1, feature_dim],
                         padding='VALID', stride=[1, 1],
                         bn=True, is_training=is_training,
                         scope='conv1_rot', 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_rot', bn_decay=bn_decay)

    net = tf_util.conv2d(net, 64, [1, 1],
                         padding='VALID', stride=[1, 1],
                         bn=True, is_training=is_training,
                         scope='conv3_rot', 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_rot', 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_rot', bn_decay=bn_decay) # check the maximum along point dimension

    max_indices = tf.argmax(net, axis=1)
    net = tf_util.max_pool2d(net, [num_point, 1],
                            padding='VALID', scope='maxpool_rot')

    # MLP on global point cloud vector
    net = tf.reshape(net, [batch_size, -1])
    net, _, _ = tf_util.fully_connected(net, 512, bn=True, is_training=is_training,
                                  scope='fc1_rot', bn_decay=bn_decay)
    net, _, _ = tf_util.fully_connected(net, 256, bn=True, is_training=is_training,
                                  scope='fc2_rot', bn_decay=bn_decay)
    # net = tf_util.dropout(net, keep_prob=0.7, is_training=is_training,
    #                       scope='dp1')
    net, out_weight, out_biases = tf_util.fully_connected(net, 3, activation_fn=None, scope='output_rot')

    return net, max_indices
Beispiel #15
0
    def get_model(self, point_cloud):
        """ Classification PointNet, input is BxNx3, output Bxnum_class """
        c = self.configuration
        print(colors.warning('Input'), colors.info(point_cloud.shape))

        if c.enable_rtn:
            point_cloud = RotTransLayer(point_cloud, c)

        all_features = []
        if c.with_shortcut:
            all_features.append(point_cloud)
        if c.with_pc_feature:
            pc_feat = GetPCFeature(point_cloud, c)
            print(colors.warning('PC_Feature'), colors.info(pc_feat.shape))
            pc_feat = LinearCombLayer(pc_feat, 128, 'LinearCombLayerPC', True, c)
            pc_feat = FeatureMapLayer(pc_feat, 128, 'FeatureMapLayerPC', c)
            all_features.append(pc_feat)
        if c.with_nn_feature:
            nn_feat = GetNNFeature(point_cloud, c.num_neighbor, 'GetNNFeature', c)
            print(colors.warning('NN_Feature'), colors.info(nn_feat.shape))
            nn_feat = LinearCombLayer(nn_feat, 128, 'LinearCombLayerNN', False, c)
            nn_feat = FeatureMapLayer(nn_feat, 128, 'FeatureMapLayerNN', c)
            all_features.append(nn_feat)
        #
        pt_feat = tf.concat(all_features, axis=2)
        #
        pt_feat = SetConvLayer(pt_feat, 256, 'SetConv_1', c)
        #
        pt_feat = SetConvLayer(pt_feat, 384, 'SetConv_2', c)
        #
        pt_feat = SetConvLayer(pt_feat, 512, 'SetConv_3', c)

        # (N, P, C) -> (N, C)
        net = tf.reduce_max(pt_feat, axis=1, keepdims=False)
        self.aux = {}
        self.aux['max_idx'] = tf.argmax(pt_feat, axis=1)
        self.aux['global_feature'] = net
        # MLP on global point cloud vector
        with tf.variable_scope('MLP_classify'):
            net = tf_util.fully_connected(net, 512, bn=True, is_training=c.is_training,
                                        scope='fc1', bn_decay=c.bn_decay, activation_fn=tf.nn.elu)
            net = tf_util.dropout(net, keep_prob=0.5, is_training=c.is_training,
                                scope='dp1')
            net = tf_util.fully_connected(net, 256, bn=True, is_training=c.is_training,
                                        scope='fc2', bn_decay=c.bn_decay, activation_fn=tf.nn.elu)
            net = tf_util.dropout(net, keep_prob=0.5, is_training=c.is_training,
                                scope='dp2')
            net = tf_util.fully_connected(net, c.num_class, activation_fn=None, scope='fc3')
        return net
Beispiel #16
0
def get_model_two_layer(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 = {}
    k = 20

    adj_matrix = tf_util.pairwise_distance(point_cloud)
    nn_idx = tf_util.knn(adj_matrix, k=k)
    edge_feature = tf_util.new_get_edge_feature(point_cloud,
                                                nn_idx=nn_idx,
                                                k=k)

    net = tf_util.conv2d(edge_feature,
                         256, [1, 1],
                         padding='VALID',
                         stride=[1, 1],
                         bn=True,
                         is_training=is_training,
                         scope='dgcnn1',
                         bn_decay=bn_decay)
    net = tf.reduce_max(net, axis=-2, keep_dims=True)

    net = tf_util.conv2d(net,
                         1024, [1, 1],
                         padding='VALID',
                         stride=[1, 1],
                         bn=True,
                         is_training=is_training,
                         scope='agg',
                         bn_decay=bn_decay)

    net = tf.reduce_max(net, axis=1, keep_dims=True)

    # MLP on global point cloud vector
    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.5,
                          is_training=is_training,
                          scope='dp1')
    net = tf_util.fully_connected(net, 40, activation_fn=None, scope='fc3')

    return net, end_points
Beispiel #17
0
def get_model(points, w, mu, sigma, is_training, bn_decay=None, weigth_decay=0.005, add_noise=False, num_classes=40):
    """ Classification PointNet, input is BxNx3, output Bx40 """
    batch_size = points.get_shape()[0].value
    n_points = points.get_shape()[1].value
    n_gaussians = w.shape[0].value
    res = int(np.round(np.power(n_gaussians,1.0/3.0)))


    # fv = tf_util.get_fv_minmax(points, w, mu, sigma, flatten=False)
    fv = tf_util.get_fv_tf(points, w, mu, sigma, flatten=False)

    grid_fisher = tf.reshape(fv,[batch_size,-1,res,res,res])
    grid_fisher = tf.transpose(grid_fisher, [0, 2, 3, 4, 1])

    #net = tf.reshape(grid_fisher,[batch_size, -1])

    #Decoder
    # Inception
    layer = 1
    net = inception_module(grid_fisher, n_filters=256, kernel_sizes=[3,5], is_training=is_training, bn_decay=bn_decay, scope='inception'+str(layer))
    # layer = layer + 1
    # net = inception_module(net, n_filters=128,kernel_sizes=[3, 5], is_training=is_training, bn_decay=bn_decay, scope='inception'+str(layer))
    # layer = layer + 1
    # net = inception_module(net, n_filters=256,kernel_sizes=[3, 5], is_training=is_training, bn_decay=bn_decay, scope='inception'+str(layer))
    # layer = layer + 1
    # net = tf_util.max_pool3d(net, [2, 2, 2], scope='maxpool'+str(layer), stride=[2, 2, 2], padding='SAME')
    # layer = layer + 1
    # net = inception_module(net, n_filters=256,kernel_sizes=[3,5], is_training=is_training, bn_decay=bn_decay, scope='inception'+str(layer))
    # layer = layer + 1
    # net = inception_module(net, n_filters=512,kernel_sizes=[3,5], is_training=is_training, bn_decay=bn_decay, scope='inception'+str(layer))
    # layer = layer + 1
    # net = tf_util.max_pool3d(net, [2, 2, 2], scope='maxpool'+str(layer), stride=[2, 2, 2], padding='SAME')

    net = tf.reshape(net,[batch_size, -1])

    # net = tf_util.fully_connected(net, 1024, bn=True, is_training=is_training,
    #                               scope='fc'+str(layer), bn_decay=bn_decay, weigth_decay=weigth_decay)
    layer = layer+1
    net = tf_util.fully_connected(net, 1024, bn=True, is_training=is_training,
                                  scope='fc'+str(layer), bn_decay=bn_decay, weigth_decay=weigth_decay)
    layer = layer + 1
    net = tf_util.fully_connected(net, n_points*3, bn=True, is_training=is_training,
                                  scope='fc'+str(layer), bn_decay=bn_decay, weigth_decay=weigth_decay, activation_fn=None)

    reconstructed_points = tf.reshape(net,[batch_size, n_points, 3])


    return reconstructed_points, fv
Beispiel #18
0
def get_encoder(input_image, point_dim, is_training, bn_decay, num_point,batch_size, end_points):
    net = tf_util.conv2d(input_image, 64, [1,point_dim],
                         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)
    point_feat = tf_util.conv2d(net, 64, [1,1],
                         padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training,
                         scope='conv3', bn_decay=bn_decay)
    net = tf_util.conv2d(point_feat, 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, 256, [1,1],# 512
                         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')

    net = tf.reshape(global_feat, [batch_size, -1])
    net = tf.identity(net, name = "old_input_latent")
    z = tf_util.fully_connected(net, 256, bn=True, is_training=is_training, scope='z', bn_decay=bn_decay)# 256
    return z
Beispiel #19
0
def get_model(point_cloud, is_training, scope='', num_point=None, bn_decay=None, ifglobal=False, bn=True, end_points={}):
    """ 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 = {}

    l0_xyz = point_cloud
    l0_points = None

    # Set abstraction layers
    l1_xyz, l1_points = pointnet_sa_module_msg(l0_xyz, l0_points, 512, [0.1,0.2,0.4], [16,32,128], [[32,32,64], [64,64,128], [64,96,128]], is_training, bn_decay, scope='layer1', use_nchw=True, bn = bn)
    l2_xyz, l2_points = pointnet_sa_module_msg(l1_xyz, l1_points, 128, [0.2,0.4,0.8], [32,64,128], [[64,64,128], [128,128,256], [128,128,256]], is_training, bn_decay, scope='layer2', bn = bn)
    l3_xyz, l3_points, _ = pointnet_sa_module(l2_xyz, l2_points, npoint=None, radius=None, nsample=None, mlp=[256,512,1024], mlp2=None, group_all=True, is_training=is_training, bn_decay=bn_decay, scope='layer3', bn = bn)

    # Fully connected layers
    net = tf.reshape(l3_points, [batch_size, -1])
    net = tf_util.fully_connected(net, 512, bn=bn, is_training=is_training, scope='fc1', bn_decay=bn_decay)
    end_points['embedding'] = net
    # net = tf_util.dropout(net, keep_prob=0.4, 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.4, is_training=is_training, scope='dp2')
    # net = tf_util.fully_connected(net, 40, activation_fn=None, scope='fc3')
    end_points['l2_xyz'] = l2_xyz
    end_points['l3_xyz'] = l3_xyz
    end_points['l1_xyz'] = l1_xyz
    end_points['l0_xyz'] = l0_xyz
    end_points['l2_points'] = l2_points
    end_points['l3_points'] = l3_points
    end_points['l1_points'] = l1_points
    end_points['l0_points'] = l0_points

    return net, end_points
Beispiel #20
0
    def __init__(self, sess, ob_space, ac_space, n_env, n_steps, n_batch, reuse=False, **kwargs):
        super(Policy, self).__init__(sess, ob_space, ac_space, n_env, n_steps, n_batch, reuse=reuse, scale=True)
        
        with tf.variable_scope("model", reuse=reuse):
            is_training = tf.constant(True)
            bn = False
            net = tf.cast(self.obs_ph, tf.float32)
            net = make_pointnet(net, is_training, bn = bn)
            with tf.name_scope("pi_h_fc1"):
                #pi_h = tu.fully_connected(net, 8, bn=bn, is_training=is_training, scope="pi_h_fc1", bn_decay=None)
                pi_h = tf.layers.dense(net, 8, name="pi_h_fc1")
                pi_h = tf.clip_by_value(
                    t=pi_h,
                    clip_value_min=-1,
                    clip_value_max=1,
                    name="action_clipping"
                )
            pi_latent = pi_h
            
            
            with tf.name_scope("vf_h_fc1"):
                vf_h = tu.fully_connected(net, 16, bn=bn, is_training=is_training,
                                  scope="vf_h_fc1", bn_decay=None)
            value_fn = tf.layers.dense(vf_h, 1, name="vf")
            vf_latent = vf_h

            self._proba_distribution, self._policy, self.q_value = \
                self.pdtype.proba_distribution_from_latent(pi_latent, vf_latent, init_scale=0.01)
        self._value_fn = value_fn
        self._setup_init()
def get_3d_box_estimation_v2_net(object_point_cloud, one_hot_vec,
                                 is_training, bn_decay, end_points):
    ''' 3D Box Estimation PointNet v2 network.
    Input:
        object_point_cloud: TF tensor in shape (B,M,C)
            masked point clouds in object coordinate
        one_hot_vec: TF tensor in shape (B,3)
            length-3 vectors indicating predicted object type
    Output:
        output: TF tensor in shape (B,3+NUM_HEADING_BIN*2+NUM_SIZE_CLUSTER*4)
            including box centers, heading bin class scores and residuals,
            and size cluster scores and residuals
    '''
    # Gather object points
    print("one_hot_vec: ", one_hot_vec)
    batch_size = object_point_cloud.get_shape()[0].value

    l0_xyz = object_point_cloud
    l0_points = None
    # Set abstraction layers
    l1_xyz, l1_points, l1_indices = pointnet_sa_module(l0_xyz, l0_points,
        npoint=128, radius=0.2, nsample=64, mlp=[64,64,128],
        mlp2=None, group_all=False,
        is_training=is_training, bn_decay=bn_decay, scope='ssg-layer1')
    l2_xyz, l2_points, l2_indices = pointnet_sa_module(l1_xyz, l1_points,
        npoint=32, radius=0.4, nsample=64, mlp=[128,128,256],
        mlp2=None, group_all=False,
        is_training=is_training, bn_decay=bn_decay, scope='ssg-layer2')
    l3_xyz, l3_points, l3_indices = pointnet_sa_module(l2_xyz, l2_points,
        npoint=None, radius=None, nsample=None, mlp=[256,256,512],
        mlp2=None, group_all=True,
        is_training=is_training, bn_decay=bn_decay, scope='ssg-layer3')

    # Fully connected layers
    net = tf.reshape(l3_points, [batch_size, -1])
    net = tf.concat([net, one_hot_vec], axis=1)
    net = tf_util.fully_connected(net, 512, bn=True,
        is_training=is_training, scope='fc1', bn_decay=bn_decay)
    net = tf_util.fully_connected(net, 256, bn=True,
        is_training=is_training, scope='fc2', bn_decay=bn_decay)

    # The first 3 numbers: box center coordinates (cx,cy,cz),
    # the next NUM_HEADING_BIN*2:  heading bin class scores and bin residuals
    # next NUM_SIZE_CLUSTER*4: box cluster scores and residuals
    output = tf_util.fully_connected(net,
        3+NUM_HEADING_BIN*2+NUM_SIZE_CLUSTER*4, activation_fn=None, scope='fc3')
    return output, end_points
Beispiel #22
0
def feature_transform_net(inputs, is_training, num_point, 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],
    #                          padding='VALID', scope='tmaxpool')
    # net = tf.reshape(net, [batch_size, -1])
    #---------- 对源代码进行了修改,适应点数量变化 ----------
    net = tf.reduce_max(net, axis=1)
    net = tf.reshape(net, shape= [-1, 1024])


    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, [-1, K, K])
    return transform
Beispiel #23
0
def input_transform_net_dgcnn(edge_feature, is_training, bn_decay=None, K=3):
    """ Input (XYZ) Transform Net, input is BxNx3 gray image
    Return:
        Transformation matrix of size 3xK """

    batch_size = edge_feature.get_shape()[0].value
    num_point = edge_feature.get_shape()[1].value

    net = tf_util.conv2d(edge_feature, 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.reduce_max(net, axis=-2, keep_dims=True)

    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],
                             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_XYZ') as sc:
        # assert(K==3)
        with tf.device('/cpu:0'):
            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
Beispiel #24
0
def reasoning_keypoints(point_cloud, npoint, is_training , bn_decay=None):
    '''
    Input:
        xyz:(batch_size,num_point,3)
        npoint:int , the numbers of keypoints
        key:int
    output:
        keypoints_xyz(batch_size,npoint,3)
    '''
    with tf.variable_scope('keypointNet') as sc:
    	batch_size = point_cloud.get_shape()[0].value
    	num_point = point_cloud.get_shape()[1].value
    	C = point_cloud.get_shape()[2].value
    	image = tf.expand_dims(point_cloud, -1)  # b,n,C,1
    	net = tf_util.conv2d(image, 64, [1, C], 
    	                     padding='VALID', stride=[1, 1],
    	                     bn=True, is_training=is_training,
    	                     scope='conv0',bn_decay=bn_decay,activation_fn=tf_util.PReLU) #-> b,n,1,64
    	point_feat = net

    	net = tf_util.conv2d(net, 128, [1, 1],
    	                     padding='VALID', stride=[1, 1],
    	                     bn=True, is_training=is_training,
    	                     scope='conv1', bn_decay=bn_decay,activation_fn=tf_util.PReLU)
    	net = tf_util.conv2d(net, 256, [1, 1],
    	                     padding='VALID', stride=[1, 1],
    	                     bn=True, is_training=is_training,
    	                     scope='conv2', bn_decay=bn_decay,activation_fn=tf_util.PReLU)
    	######
    	net = tf_util.conv2d(net, 1024, [1, 1],
    	                     padding='VALID', stride=[1, 1],
    	                     bn=True, is_training=is_training,
    	                     scope='conv3', bn_decay=bn_decay,activation_fn=tf_util.PReLU)#b,n,1,1024
    	net = tf_util.max_pool2d(net, [num_point, 1], 
    	                         padding='VALID', scope='maxpool')# -> b,1,1,1024
    	
    	net = tf.reshape(net, [batch_size, -1])
    	res_feature = net
    	net = tf_util.fully_connected(net, 512, bn=True, is_training=is_training,
    	                              scope='fc1' , bn_decay=bn_decay,activation_fn=tf_util.PReLU)
    	net = tf_util.fully_connected(net, 256, bn=True, is_training=is_training,
    	                              scope='fc2' , bn_decay=bn_decay,activation_fn=tf_util.PReLU)
    	net = tf_util.fully_connected(net, npoint * 3, bn=True, is_training=is_training,
    	                              scope='fc3' , bn_decay=bn_decay,activation_fn=tf_util.PReLU)
    	keypoints_xyz = tf.reshape(net, [batch_size, npoint, 3])
    	print("keypointNet:{}".format(keypoints_xyz.shape))
    	return keypoints_xyz,res_feature,point_feat
Beispiel #25
0
def get_model(input_images, is_training, cat_num, batch_size, weight_decay,
              bn_decay):
    input_data = tf.reshape(input_images, [batch_size, -1])

    net = tf_util.fully_connected(input_data, cat_num, bn=False, is_training=is_training, \
            weight_decay=weight_decay, activation_fn=None, scope='fc1')

    return net
Beispiel #26
0
def generate(features, FLAGS, is_training, bn_decay=None):

    gen_points = FLAGS.generate_num
    ### 将1×1024的特征转变为点云的坐标 全连接层,生成256个点, 每个点256维特征
    net = tf.reshape(features, [FLAGS.batch_size, 64])
    net = tf_util.fully_connected(net,
                                  1024,
                                  scope='G_full_conn1',
                                  bn_decay=bn_decay)
    net = tf_util.fully_connected(net,
                                  gen_points * 3,
                                  scope='G_full_conn2',
                                  bn_decay=bn_decay,
                                  activation_fn=None)
    net = tf.reshape(net, [FLAGS.batch_size, gen_points, 3])

    return net
def get_3d_box_estimation_v2_net(object_point_cloud, one_hot_vec,
                                 is_training, bn_decay, end_points):
    ''' 3D Box Estimation PointNet v2 network.
    Input:
        object_point_cloud: TF tensor in shape (B,M,C)
            masked point clouds in object coordinate
        one_hot_vec: TF tensor in shape (B,3)
            length-3 vectors indicating predicted object type
    Output:
        output: TF tensor in shape (B,3+NUM_HEADING_BIN*2+NUM_SIZE_CLUSTER*4)
            including box centers, heading bin class scores and residuals,
            and size cluster scores and residuals
    ''' 
    # Gather object points
    batch_size = object_point_cloud.get_shape()[0].value

    l0_xyz = object_point_cloud
    l0_points = None
    # Set abstraction layers
    l1_xyz, l1_points, l1_indices = pointnet_sa_module(l0_xyz, l0_points,
        npoint=128, radius=0.2, nsample=64, mlp=[64,64,128],
        mlp2=None, group_all=False,
        is_training=is_training, bn_decay=bn_decay, scope='ssg-layer1')
    l2_xyz, l2_points, l2_indices = pointnet_sa_module(l1_xyz, l1_points,
        npoint=32, radius=0.4, nsample=64, mlp=[128,128,256],
        mlp2=None, group_all=False,
        is_training=is_training, bn_decay=bn_decay, scope='ssg-layer2')
    l3_xyz, l3_points, l3_indices = pointnet_sa_module(l2_xyz, l2_points,
        npoint=None, radius=None, nsample=None, mlp=[256,256,512],
        mlp2=None, group_all=True,
        is_training=is_training, bn_decay=bn_decay, scope='ssg-layer3')

    # Fully connected layers
    net = tf.reshape(l3_points, [batch_size, -1])
    net = tf.concat([net, one_hot_vec], axis=1)
    net = tf_util.fully_connected(net, 512, bn=True,
        is_training=is_training, scope='fc1', bn_decay=bn_decay)
    net = tf_util.fully_connected(net, 256, bn=True,
        is_training=is_training, scope='fc2', bn_decay=bn_decay)

    # The first 3 numbers: box center coordinates (cx,cy,cz),
    # the next NUM_HEADING_BIN*2:  heading bin class scores and bin residuals
    # next NUM_SIZE_CLUSTER*4: box cluster scores and residuals
    output = tf_util.fully_connected(net,
        3+NUM_HEADING_BIN*2+NUM_SIZE_CLUSTER*4, activation_fn=None, scope='fc3')
    return output, end_points
def get_3d_box_estimation_v1_net(object_point_cloud, one_hot_vec,
                                 is_training, bn_decay, end_points):
    ''' 3D Box Estimation PointNet v1 network.
    Input:
        object_point_cloud: TF tensor in shape (B,M,C)
            point clouds in object coordinate
        one_hot_vec: TF tensor in shape (B,3)
            length-3 vectors indicating predicted object type
    Output:
        output: TF tensor in shape (B,3+NUM_HEADING_BIN*2+NUM_SIZE_CLUSTER*4)
            including box centers, heading bin class scores and residuals,
            and size cluster scores and residuals
    ''' 
    num_point = object_point_cloud.get_shape()[1].value
    net = tf.expand_dims(object_point_cloud, 2)
    net = tf_util.conv2d(net, 128, [1,1],
                         padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training,
                         scope='conv-reg1', bn_decay=bn_decay)
    net = tf_util.conv2d(net, 128, [1,1],
                         padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training,
                         scope='conv-reg2', bn_decay=bn_decay)
    net = tf_util.conv2d(net, 256, [1,1],
                         padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training,
                         scope='conv-reg3', bn_decay=bn_decay)
    net = tf_util.conv2d(net, 512, [1,1],
                         padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training,
                         scope='conv-reg4', bn_decay=bn_decay)
    net = tf_util.max_pool2d(net, [num_point,1],
        padding='VALID', scope='maxpool2')
    net = tf.squeeze(net, axis=[1,2])
    net = tf.concat([net, one_hot_vec], axis=1)
    net = tf_util.fully_connected(net, 512, scope='fc1', bn=True,
        is_training=is_training, bn_decay=bn_decay)
    net = tf_util.fully_connected(net, 256, scope='fc2', bn=True,
        is_training=is_training, bn_decay=bn_decay)

    # The first 3 numbers: box center coordinates (cx,cy,cz),
    # the next NUM_HEADING_BIN*2:  heading bin class scores and bin residuals
    # next NUM_SIZE_CLUSTER*4: box cluster scores and residuals
    output = tf_util.fully_connected(net,
        3+NUM_HEADING_BIN*2+NUM_SIZE_CLUSTER*4, activation_fn=None, scope='fc3')
    return output, end_points
def build_pointnet(X, out_dim, is_training, bn_decay, scope):
    n_points = X.get_shape()[1].value

    X_expanded = tf.expand_dims(X, -1)

    net = tf_util.conv2d(X_expanded, 64, [1,3], padding='VALID',
            stride=[1,1], bn=True, is_training=is_training,
            bn_decay=bn_decay, scope=scope+'_conv1')

    net = tf_util.conv2d(net, 64, [1,1], padding='VALID',
            stride=[1,1], bn=True, is_training=is_training,
            bn_decay=bn_decay, scope=scope+'_conv2')

    net = tf_util.conv2d(net, 64, [1,1], padding='VALID',
            stride=[1,1], bn=True, is_training=is_training,
            bn_decay=bn_decay, scope=scope+'_conv3')

    net = tf_util.conv2d(net, 128, [1,1], padding='VALID',
            stride=[1,1], bn=True, is_training=is_training,
            bn_decay=bn_decay, scope=scope+'_conv4')

    net = tf_util.conv2d(net, 1024, [1,1], padding='VALID',
            stride=[1,1], bn=True, is_training=is_training,
            bn_decay=bn_decay, scope=scope+'_conv5')

    net = tf_util.max_pool2d(net, [n_points, 1], padding='VALID',
            scope=scope+'_maxpool')

    net = tf.squeeze(net)

    net = tf_util.fully_connected(net, 512, bn=True,
            is_training=is_training, bn_decay=bn_decay,
            scope=scope+'_fc1')

    net = tf_util.fully_connected(net, 256, bn=True,
            is_training=is_training, bn_decay=bn_decay,
            scope=scope+'_fc2')

    net = tf_util.dropout(net, keep_prob=0.7, is_training=is_training,
            scope=scope+'_dp1')

    # Outputs.
    net = tf_util.fully_connected(net, out_dim,
            activation_fn=None, scope=scope+'_out')

    return net
Beispiel #30
0
def get_shape_model(point_cloud, is_training, bn_decay=None):
    # first get shape feature
    pointnet_feat = get_pointnet_model(point_cloud,
                                       is_training,
                                       bn_decay=bn_decay)
    # process pointnet
    pt_vec = tf_util.fully_connected(pointnet_feat, 1024, weight_decay=0.005, bn=True, \
                           is_training=is_training, scope='fwd_fc1', bn_decay=bn_decay)
    pt_vec = tf_util.fully_connected(pt_vec, 512,  weight_decay=0.005, bn=True, \
                           is_training=is_training, scope='fwd_fc2', bn_decay=bn_decay)
    pt_vec = tf_util.fully_connected(pt_vec, 128,  weight_decay=0.005, bn=True, \
                           is_training=is_training, scope='fwd_fc3', bn_decay=bn_decay)
    pt_vec = tf_util.fully_connected(pt_vec, 32,  weight_decay=0.005, bn=True, \
                           is_training=is_training, scope='fwd_fc4', bn_decay=bn_decay)
    shape_feat = tf_util.fully_connected(pt_vec, 9,  weight_decay=0.005, bn=True, \
                           is_training=is_training, scope='fwd_fc5', bn_decay=bn_decay)
    return shape_feat
def get_model(eventclouds, 
              seq_len,
              num_classes,
              is_training,
              bn_decay=None):
    """ input is B x S x N x 3, output B x num_classes """
    num_point = eventclouds.get_shape()[-2].value 
    batch_size = eventclouds.get_shape()[0].value 
    eventclouds = tf.reshape(eventclouds, [-1, num_point, 3])
    eventclouds = tf.expand_dims(eventclouds, -1)
   
    net = tf_util.conv2d(eventclouds, 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)
    net = tf_util.conv2d(net, 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)

    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.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='dp1')
    net = tf_util.fully_connected(net, num_classes, activation_fn=None, scope='fc3')
    print(net.shape)
    return net
Beispiel #32
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
    #    vx = point_cloud.get_shape()[1].value
    #    vy = point_cloud.get_shape()[2].value
    #    vz = point_cloud.get_shape()[3].value
    end_points = {}
    input_image = tf.expand_dims(point_cloud, -1)

    net = tf_util.conv3d(input_image,
                         32, [5, 5, 5],
                         scope='conv1',
                         stride=[2, 2, 2],
                         bn=True,
                         is_training=is_training,
                         padding='SAME',
                         bn_decay=bn_decay)

    net = tf_util.conv3d(net,
                         32, [3, 3, 3],
                         scope='conv2',
                         stride=[2, 2, 2],
                         bn=True,
                         is_training=is_training,
                         padding='SAME',
                         bn_decay=bn_decay)

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

    # MLP on global point cloud vector
    net = tf.reshape(net, [batch_size, -1])
    net = tf_util.fully_connected(net,
                                  128,
                                  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.fully_connected(net, 10, activation_fn=None, scope='fc2')

    return net, end_points
Beispiel #33
0
def get_model(point_cloud, is_training, num_classes, 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 = {}
    input_image = tf.expand_dims(point_cloud, -1)
    
    # Point functions (MLP implemented as conv2d)
    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)
    net = tf_util.conv2d(net, 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)
    point_features = net

    # Symmetric function: max pooling
    net = tf_util.max_pool2d(net, [num_point,1],
                             padding='VALID', scope='maxpool')
    
    # MLP on global point cloud vector
    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.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='dp1')
    net = tf_util.fully_connected(net, num_classes, activation_fn=None, scope='fc3')

    return net, end_points, point_features
def get_decoder(net, is_training, bn_decay, num_point, batch_size):
    net = tf_util.fully_connected(net,
                                  1024,
                                  bn=True,
                                  is_training=is_training,
                                  scope='fc1',
                                  bn_decay=bn_decay)
    net = tf_util.fully_connected(net,
                                  1024,
                                  bn=True,
                                  is_training=is_training,
                                  scope='fc2',
                                  bn_decay=bn_decay)
    net = tf_util.fully_connected(net,
                                  num_point,
                                  activation_fn=None,
                                  scope='fc3')
    return net
Beispiel #35
0
 def to_edge_translator(net):
     net = tf_util.fully_connected(net,
                                   256,
                                   bn=False,
                                   is_training=is_training_pl,
                                   scope='to_edge_1',
                                   bn_decay=None)
     net = tf_util.fully_connected(net,
                                   256,
                                   bn=False,
                                   is_training=is_training_pl,
                                   scope='to_edge_2',
                                   bn_decay=None)
     net = tf_util.fully_connected(net,
                                   256,
                                   activation_fn=None,
                                   scope='to_edge_3')
     return net
Beispiel #36
0
def get_model(images, is_training, num_classes, T, bn_decay=None):
    #fc1 = tf_util.fully_connected(images, 1200, bn_decay=bn_decay, is_training=is_training, scope='fc1')
    fc2 = tf_util.fully_connected(images,
                                  400,
                                  bn_decay=bn_decay,
                                  is_training=is_training,
                                  scope='fc2')
    fc2 = tf_util.dropout(fc2, is_training=is_training, scope='dp')
    logits = tf_util.fully_connected(fc2,
                                     num_classes,
                                     bn_decay=bn_decay,
                                     is_training=is_training,
                                     scope='logits')
    T = tf.cond(
        tf.cast(is_training, dtype=tf.float32) > 0.5, lambda: tf.constant(T),
        lambda: tf.constant(1.))
    logits = logits / T
    return logits
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 = {}
    input_image = tf.expand_dims(point_cloud, -1)
    
    # Point functions (MLP implemented as conv2d)
    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)
    net = tf_util.conv2d(net, 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)

    # Symmetric function: max pooling
    net = tf_util.max_pool2d(net, [num_point,1],
                             padding='VALID', scope='maxpool')
    
    # MLP on global point cloud vector
    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.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='dp1')
    net = tf_util.fully_connected(net, 40, activation_fn=None, scope='fc3')

    return net, end_points
Beispiel #38
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 = {}

    l0_xyz = point_cloud
    l0_points = None

    # Set abstraction layers
    l1_xyz, l1_points = pointnet_sa_module_msg(l0_xyz, l0_points, 512, [0.1,0.2,0.4], [16,32,128], [[32,32,64], [64,64,128], [64,96,128]], is_training, bn_decay, scope='layer1', use_nchw=True)
    l2_xyz, l2_points = pointnet_sa_module_msg(l1_xyz, l1_points, 128, [0.2,0.4,0.8], [32,64,128], [[64,64,128], [128,128,256], [128,128,256]], is_training, bn_decay, scope='layer2')
    l3_xyz, l3_points, _ = pointnet_sa_module(l2_xyz, l2_points, npoint=None, radius=None, nsample=None, mlp=[256,512,1024], mlp2=None, group_all=True, is_training=is_training, bn_decay=bn_decay, scope='layer3')

    # Fully connected layers
    net = tf.reshape(l3_points, [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.4, 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.4, is_training=is_training, scope='dp2')
    net = tf_util.fully_connected(net, 40, activation_fn=None, scope='fc3')

    return net, end_points
Beispiel #39
0
def get_center_regression_net(object_point_cloud, one_hot_vec,
                              is_training, bn_decay, end_points):
    ''' Regression network for center delta. a.k.a. T-Net.
    Input:
        object_point_cloud: TF tensor in shape (B,M,C)
            point clouds in 3D mask coordinate
        one_hot_vec: TF tensor in shape (B,3)
            length-3 vectors indicating predicted object type
    Output:
        predicted_center: TF tensor in shape (B,3)
    ''' 
    num_point = object_point_cloud.get_shape()[1].value
    net = tf.expand_dims(object_point_cloud, 2)
    net = tf_util.conv2d(net, 128, [1,1],
                         padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training,
                         scope='conv-reg1-stage1', bn_decay=bn_decay)
    net = tf_util.conv2d(net, 128, [1,1],
                         padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training,
                         scope='conv-reg2-stage1', bn_decay=bn_decay)
    net = tf_util.conv2d(net, 256, [1,1],
                         padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training,
                         scope='conv-reg3-stage1', bn_decay=bn_decay)
    net = tf_util.max_pool2d(net, [num_point,1],
        padding='VALID', scope='maxpool-stage1')
    net = tf.squeeze(net, axis=[1,2])
    net = tf.concat([net, one_hot_vec], axis=1)
    net = tf_util.fully_connected(net, 256, scope='fc1-stage1', bn=True,
        is_training=is_training, bn_decay=bn_decay)
    net = tf_util.fully_connected(net, 128, scope='fc2-stage1', bn=True,
        is_training=is_training, bn_decay=bn_decay)
    predicted_center = tf_util.fully_connected(net, 3, activation_fn=None,
        scope='fc3-stage1')
    return predicted_center, end_points
def get_model(point_cloud, one_hot_vec, is_training, bn_decay=None):
    """ Classification PointNet, input is BxNx4, onehotvec is Bx3, output BxNx2 """
    batch_size = point_cloud.get_shape()[0].value
    num_point = point_cloud.get_shape()[1].value
    end_points = {}

    input_image = tf.expand_dims(point_cloud, -1)

    net = tf_util.conv2d(input_image, 64, [1,6],
                         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)
    point_feat = tf_util.conv2d(net, 64, [1,1],
                         padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training,
                         scope='conv3', bn_decay=bn_decay)
    net = tf_util.conv2d(point_feat, 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 = tf.concat([global_feat, tf.expand_dims(tf.expand_dims(one_hot_vec, 1), 1)], axis=3)
    print 'Global Feat: ', global_feat
    global_feat_expand = tf.tile(global_feat, [1, num_point, 1, 1])
    print point_feat, global_feat_expand
    concat_feat = tf.concat(axis=3, values=[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.dropout(net, is_training, 'dp1', keep_prob=0.5)

    logits = tf_util.conv2d(net, 2, [1,1],
                         padding='VALID', stride=[1,1], activation_fn=None,
                         scope='conv10')
    logits = tf.squeeze(logits, [2]) # BxNxC
    print logits
    
    print '-----------'
    #net = tf.concat(axis=3, values=[net, tf.expand_dims(tf.slice(point_cloud, [0,0,0], [-1,-1,3]), 2)])
    mask = tf.slice(logits,[0,0,0],[-1,-1,1]) < tf.slice(logits,[0,0,1],[-1,-1,1])
    mask = tf.to_float(mask) # BxNx1
    mask_count = tf.tile(tf.reduce_sum(mask,axis=1,keep_dims=True), [1,1,3]) # Bx1x3
    print mask
    point_cloud_xyz = tf.slice(point_cloud, [0,0,0], [-1,-1,3]) # BxNx3

    # ---- Subtract points mean ----
    mask_xyz_mean = tf.reduce_sum(tf.tile(mask, [1,1,3])*point_cloud_xyz, axis=1, keep_dims=True) # Bx1x3
    mask_xyz_mean = mask_xyz_mean/tf.maximum(mask_count,1) # Bx1x3
    point_cloud_xyz_stage1 = point_cloud_xyz - tf.tile(mask_xyz_mean, [1,num_point,1])
    print 'Point cloud xyz stage1: ', point_cloud_xyz_stage1

    # ---- Regress 1st stage center ----
    net = tf.expand_dims(point_cloud_xyz_stage1, 2)
    print net
    net = tf_util.conv2d(net, 128, [1,1],
                         padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training,
                         scope='conv-reg1-stage1', bn_decay=bn_decay)
    net = tf_util.conv2d(net, 128, [1,1],
                         padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training,
                         scope='conv-reg2-stage1', bn_decay=bn_decay)
    net = tf_util.conv2d(net, 256, [1,1],
                         padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training,
                         scope='conv-reg3-stage1', bn_decay=bn_decay)
    mask_expand = tf.tile(tf.expand_dims(mask,-1), [1,1,1,256])
    masked_net = net*mask_expand
    print masked_net
    net = tf_util.max_pool2d(masked_net, [num_point,1], padding='VALID', scope='maxpool-stage1')
    net = tf.squeeze(net, axis=[1,2])
    print net
    net = tf.concat([net, one_hot_vec], axis=1)
    net = tf_util.fully_connected(net, 256, scope='fc1-stage1', bn=True, is_training=is_training, bn_decay=bn_decay)
    net = tf_util.fully_connected(net, 128, scope='fc2-stage1', bn=True, is_training=is_training, bn_decay=bn_decay)
    stage1_center = tf_util.fully_connected(net, 3, activation_fn=None, scope='fc3-stage1')
    stage1_center = stage1_center + tf.squeeze(mask_xyz_mean, axis=1) # Bx3
    end_points['stage1_center'] = stage1_center

    # ---- Subtract stage1 center ----
    point_cloud_xyz_submean = point_cloud_xyz - tf.expand_dims(stage1_center, 1)
    print 'Point cloud xyz submean: ', point_cloud_xyz_submean

    net = tf.expand_dims(point_cloud_xyz_submean, 2)
    print net
    net = tf_util.conv2d(net, 128, [1,1],
                         padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training,
                         scope='conv-reg1', bn_decay=bn_decay)
    net = tf_util.conv2d(net, 128, [1,1],
                         padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training,
                         scope='conv-reg2', bn_decay=bn_decay)
    net = tf_util.conv2d(net, 256, [1,1],
                         padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training,
                         scope='conv-reg3', bn_decay=bn_decay)
    net = tf_util.conv2d(net, 512, [1,1],
                         padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training,
                         scope='conv-reg4', bn_decay=bn_decay)
    mask_expand = tf.tile(tf.expand_dims(mask,-1), [1,1,1,512])
    masked_net = net*mask_expand
    print masked_net
    net = tf_util.max_pool2d(masked_net, [num_point,1], padding='VALID', scope='maxpool2')
    net = tf.squeeze(net, axis=[1,2])
    print net
    net = tf.concat([net, one_hot_vec], axis=1)
    net = tf_util.fully_connected(net, 512, scope='fc1', bn=True, is_training=is_training, bn_decay=bn_decay)
    net = tf_util.fully_connected(net, 256, scope='fc2', bn=True, is_training=is_training, bn_decay=bn_decay)

    # First 3 are cx,cy,cz, next NUM_HEADING_BIN*2 are for heading
    # next NUM_SIZE_CLUSTER*4 are for dimension
    output = tf_util.fully_connected(net, 3+NUM_HEADING_BIN*2+NUM_SIZE_CLUSTER*4, activation_fn=None, scope='fc3')
    print output

    center = tf.slice(output, [0,0], [-1,3])
    center = center + stage1_center # Bx3
    end_points['center'] = center

    heading_scores = tf.slice(output, [0,3], [-1,NUM_HEADING_BIN])
    heading_residuals_normalized = tf.slice(output, [0,3+NUM_HEADING_BIN], [-1,NUM_HEADING_BIN])
    end_points['heading_scores'] = heading_scores # BxNUM_HEADING_BIN
    end_points['heading_residuals_normalized'] = heading_residuals_normalized # BxNUM_HEADING_BIN (should be -1 to 1)
    end_points['heading_residuals'] = heading_residuals_normalized * (np.pi/NUM_HEADING_BIN) # BxNUM_HEADING_BIN
    
    size_scores = tf.slice(output, [0,3+NUM_HEADING_BIN*2], [-1,NUM_SIZE_CLUSTER]) # BxNUM_SIZE_CLUSTER
    size_residuals_normalized = tf.slice(output, [0,3+NUM_HEADING_BIN*2+NUM_SIZE_CLUSTER], [-1,NUM_SIZE_CLUSTER*3])
    size_residuals_normalized = tf.reshape(size_residuals_normalized, [batch_size, NUM_SIZE_CLUSTER, 3]) # BxNUM_SIZE_CLUSTERx3
    end_points['size_scores'] = size_scores
    end_points['size_residuals_normalized'] = size_residuals_normalized
    end_points['size_residuals'] = size_residuals_normalized * tf.expand_dims(tf.constant(mean_size_arr, dtype=tf.float32), 0)

    return logits, end_points
def get_model(point_cloud, input_label, is_training, cat_num, part_num, \
		batch_size, num_point, weight_decay, bn_decay=None):
    """ ConvNet baseline, input is BxNx3 gray image """
    end_points = {}

    with tf.variable_scope('transform_net1') as sc:
        K = 3
        transform = get_transform(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)
    out1 = tf_util.conv2d(input_image, 64, [1,K], padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training, scope='conv1', bn_decay=bn_decay)
    out2 = tf_util.conv2d(out1, 128, [1,1], padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training, scope='conv2', bn_decay=bn_decay)
    out3 = tf_util.conv2d(out2, 128, [1,1], padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training, scope='conv3', bn_decay=bn_decay)


    with tf.variable_scope('transform_net2') as sc:
        K = 128
        transform = get_transform_K(out3, is_training, bn_decay, K)

    end_points['transform'] = transform

    squeezed_out3 = tf.reshape(out3, [batch_size, num_point, 128])
    net_transformed = tf.matmul(squeezed_out3, transform)
    net_transformed = tf.expand_dims(net_transformed, [2])

    out4 = tf_util.conv2d(net_transformed, 512, [1,1], padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training, scope='conv4', bn_decay=bn_decay)
    out5 = tf_util.conv2d(out4, 2048, [1,1], padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training, scope='conv5', bn_decay=bn_decay)
    out_max = tf_util.max_pool2d(out5, [num_point,1], padding='VALID', scope='maxpool')

    # classification network
    net = tf.reshape(out_max, [batch_size, -1])
    net = tf_util.fully_connected(net, 256, bn=True, is_training=is_training, scope='cla/fc1', bn_decay=bn_decay)
    net = tf_util.fully_connected(net, 256, bn=True, is_training=is_training, scope='cla/fc2', bn_decay=bn_decay)
    net = tf_util.dropout(net, keep_prob=0.7, is_training=is_training, scope='cla/dp1')
    net = tf_util.fully_connected(net, cat_num, activation_fn=None, scope='cla/fc3')

    # segmentation network
    one_hot_label_expand = tf.reshape(input_label, [batch_size, 1, 1, cat_num])
    out_max = tf.concat(axis=3, values=[out_max, one_hot_label_expand])

    expand = tf.tile(out_max, [1, num_point, 1, 1])
    concat = tf.concat(axis=3, values=[expand, out1, out2, out3, out4, out5])

    net2 = tf_util.conv2d(concat, 256, [1,1], padding='VALID', stride=[1,1], bn_decay=bn_decay,
                        bn=True, is_training=is_training, scope='seg/conv1', weight_decay=weight_decay)
    net2 = tf_util.dropout(net2, keep_prob=0.8, is_training=is_training, scope='seg/dp1')
    net2 = tf_util.conv2d(net2, 256, [1,1], padding='VALID', stride=[1,1], bn_decay=bn_decay,
                        bn=True, is_training=is_training, scope='seg/conv2', weight_decay=weight_decay)
    net2 = tf_util.dropout(net2, keep_prob=0.8, is_training=is_training, scope='seg/dp2')
    net2 = tf_util.conv2d(net2, 128, [1,1], padding='VALID', stride=[1,1], bn_decay=bn_decay,
                        bn=True, is_training=is_training, scope='seg/conv3', weight_decay=weight_decay)
    net2 = tf_util.conv2d(net2, part_num, [1,1], padding='VALID', stride=[1,1], activation_fn=None, 
                        bn=False, scope='seg/conv4', weight_decay=weight_decay)

    net2 = tf.reshape(net2, [batch_size, num_point, part_num])

    return net, net2, end_points