Example #1
0
	def create_encoder(self, inputs):
		input_image = tf.expand_dims(inputs, -1)
		# Conv
		net = conv2d(input_image, 64, [1, 9], padding='VALID', stride=[1, 1],
		             bn=True, is_training=self.is_training, scope='conv1', bn_decay=self.bn_decay)
		net = conv2d(net, 64, [1, 1], padding='VALID', stride=[1, 1],
		             bn=True, is_training=self.is_training, scope='conv2', bn_decay=self.bn_decay)
		net = conv2d(net, 64, [1, 1], padding='VALID', stride=[1, 1],
		             bn=True, is_training=self.is_training, scope='conv3', bn_decay=self.bn_decay)
		net = conv2d(net, 128, [1, 1], padding='VALID', stride=[1, 1],
		             bn=True, is_training=self.is_training, scope='conv4', bn_decay=self.bn_decay)
		points_feat1 = conv2d(net, 1024, [1, 1], padding='VALID', stride=[1, 1],
		                      bn=True, is_training=self.is_training, scope='conv5', bn_decay=self.bn_decay)
		
		# MaxPooling
		pc_feat1 = max_pool2d(points_feat1, [NUM_POINT, 1], padding='VALID', scope='maxpool')
		
		# Fully Connected Layers
		pc_feat1 = tf.reshape(pc_feat1, [BATCH_SIZE, -1])
		pc_feat1 = fully_connected(pc_feat1, 256, bn=True, is_training=self.is_training,
		                           scope='fc1', bn_decay=self.bn_decay)
		pc_feat1 = fully_connected(pc_feat1, 128, bn=True, is_training=self.is_training,
		                           scope='fc2', bn_decay=self.bn_decay)
		
		# 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=[points_feat1, pc_feat1_expand])
		
		return points_feat1_concat
Example #2
0
def get_model(point_cloud, is_training, bn_decay=None):
    """
        Classification PointNetwork
        :param point_cloud:  point cloud BxNx3
        :param is_training: training flag
        :param bn_decay: decay flag
        :return: output model 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 (MPL 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)
    # Symetric 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
Example #3
0
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
Example #4
0
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
Example #5
0
def input_transform_net(point_cloud, is_training, bn_decay=None, K=3):
	""" Input (XYZ) Transform Net, input is BxNx3 gray image
		Return:
			Transformation matrix of size 3xK """
	# print('the input shape for t-net:', point_cloud.get_shape())
	batch_size = point_cloud.get_shape()[0].value
	num_point = point_cloud.get_shape()[1].value
	# point_cloud -> Tensor of (batch size, number of points, 3d coordinates)
	
	input_image = tf.expand_dims(point_cloud, -1)
	# point_cloud -> (batch size, number of points, 3d coordinates, 1)
	# batch size * height * width * channel
	
	'''tf_util.conv2d(inputs, num_output_channels, kernel_size, scope, stride=[1, 1], padding='SAME',
						use_xavier=True, stddev=1e-3, weight_decay=0.0, activation_fn=tf.nn.relu,
						bn=False, bn_decay=None(default is set to 0.9), is_training=None)'''
	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)
	
	# net = mlp_conv(input_image, [64, 128, 1024])
	net = tf_util.max_pool2d(net, [num_point, 1],
	                         padding='VALID', scope='tmaxpool')
	'''(default stride: (2, 2))'''
	# net = tf.reduce_max(net, axis=1, keep_dims=True, name='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)
		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, [batch_size, 3, K])
	return transform
Example #6
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 = 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
Example #7
0
def ae_encoder(batch_size,
               num_point,
               point_dim,
               input_image,
               is_training,
               bn_decay=None,
               embedding_dim=128):
    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)
    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,
                         embedding_dim, [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')
    net = tf.reshape(global_feat, [batch_size, -1])
    end_points = {'embedding': net}

    return net, end_points
Example #8
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
	
	# input_image = tf.expand_dims(point_cloud, -1)
	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
Example #9
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
Example #10
0
def get_model(point_cloud, is_training, bn_decay=None):
    """ ConvNet baseline, input is BxNx3 gray image """
    batch_size = point_cloud.get_shape()[0].value
    num_point = point_cloud.get_shape()[1].value

    input_image = tf.expand_dims(point_cloud, -1)
    # CONV
    net = tf_util.conv2d(input_image, 64, [1,9], 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)
    points_feat1 = tf_util.conv2d(net, 1024, [1,1], padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training, scope='conv5', bn_decay=bn_decay)
    # 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, -1])
    pc_feat1 = tf_util.fully_connected(pc_feat1, 256, bn=True, is_training=is_training, scope='fc1', bn_decay=bn_decay)
    pc_feat1 = tf_util.fully_connected(pc_feat1, 128, bn=True, is_training=is_training, scope='fc2', bn_decay=bn_decay)
    print(pc_feat1)
   
    # CONCAT 
    pc_feat1_expand = tf.tile(tf.reshape(pc_feat1, [batch_size, 1, 1, -1]), [1, num_point, 1, 1])
    print(points_feat1)
    print(pc_feat1_expand)
    points_feat1_concat = tf.concat(axis=3, values=[points_feat1, pc_feat1_expand])
    print(points_feat1_concat)
    
    # CONV 
    net = tf_util.conv2d(points_feat1_concat, 512, [1,1], padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training, scope='conv6')
    net = tf_util.conv2d(net, 256, [1,1], padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training, scope='conv7')
    net = tf_util.dropout(net, keep_prob=0.7, is_training=is_training, scope='dp1')
    net = tf_util.conv2d(net, 13, [1,1], padding='VALID', stride=[1,1],
                         activation_fn=None, scope='conv8')
    net = tf.squeeze(net, [2])

    return net
Example #11
0
    def pointnet(self, point_cloud, is_training, bn=True, bn_decay=None):
        """ Classification PointNet, input is BxNx3, output Bxn where n is num classes """
        batch_size = point_cloud.get_shape()[0].value
        num_point = point_cloud.get_shape()[1].value

        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=bn,
                             is_training=is_training,
                             scope='conv1',
                             bn_decay=bn_decay)
        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)
        net = tf_util.conv2d(net,
                             64, [1, 1],
                             padding='VALID',
                             stride=[1, 1],
                             bn=bn,
                             is_training=is_training,
                             scope='conv3',
                             bn_decay=bn_decay)
        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)
        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)

        # 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.layers.flatten(net)
        net = tf_util.fully_connected(net,
                                      512,
                                      bn=bn,
                                      is_training=is_training,
                                      scope='fc1',
                                      bn_decay=bn_decay)
        net = tf_util.fully_connected(net,
                                      256,
                                      bn=bn,
                                      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,
                                      self.n_classes,
                                      activation_fn=None,
                                      scope='fc3')

        return net
Example #12
0
def get_gen_model(point_cloud,
                  is_training,
                  scope,
                  bradius=1.0,
                  reuse=None,
                  use_rv=False,
                  use_bn=False,
                  use_ibn=False,
                  use_normal=False,
                  bn_decay=None,
                  up_ratio=4):

    with tf.variable_scope(scope, reuse=reuse) as sc:
        batch_size = point_cloud.get_shape()[0].value
        num_point = point_cloud.get_shape()[1].value
        pl_xyz = point_cloud[:, :, 0:3]
        input_pl = tf.expand_dims(pl_xyz, -1)

        net1 = tf_util2.conv2d(input_pl,
                               64, [1, 3],
                               padding='VALID',
                               stride=[1, 1],
                               bn=use_bn,
                               is_training=is_training,
                               scope='conv1',
                               bn_decay=bn_decay)
        net2 = tf_util2.conv2d(net1,
                               128, [1, 1],
                               padding='VALID',
                               stride=[1, 1],
                               bn=use_bn,
                               is_training=is_training,
                               scope='conv2',
                               bn_decay=bn_decay)

        net3 = tf_util2.conv2d(net2,
                               256, [1, 1],
                               padding='VALID',
                               stride=[1, 1],
                               bn=use_bn,
                               is_training=is_training,
                               scope='conv3',
                               bn_decay=bn_decay)
        net4 = tf_util2.conv2d(net3,
                               1024, [1, 1],
                               padding='VALID',
                               stride=[1, 1],
                               bn=use_bn,
                               is_training=is_training,
                               scope='conv4',
                               bn_decay=bn_decay)
        global_feat = tf_util.max_pool2d(net4, [num_point, 1],
                                         padding='VALID',
                                         scope='maxpool')

        global_feat_expand = tf.tile(global_feat, [1, num_point, 1, 1])
        original_xyz = tf.expand_dims(pl_xyz, 2)
        concat_feat = tf.concat(
            [original_xyz, net1, net2, net3, global_feat_expand], 3)

        feature_num = concat_feat.get_shape()[3].value
        net = tf_util2.conv2d(concat_feat,
                              feature_num * 4, [1, 1],
                              padding='VALID',
                              stride=[1, 1],
                              bn=use_bn,
                              is_training=is_training,
                              scope='conv5',
                              bn_decay=bn_decay)
        net = tf.squeeze(net, [2])
        net = tf.reshape(net, [batch_size, 4 * num_point, feature_num])
        net = tf.expand_dims(net, [2])

        net = tf_util2.conv2d(net,
                              1024, [1, 1],
                              padding='VALID',
                              stride=[1, 1],
                              bn=use_bn,
                              is_training=is_training,
                              scope='conv6',
                              bn_decay=bn_decay)
        net = tf_util2.conv2d(net,
                              512, [1, 1],
                              padding='VALID',
                              stride=[1, 1],
                              bn=use_bn,
                              is_training=is_training,
                              scope='conv7',
                              bn_decay=bn_decay)
        net = tf_util2.conv2d(net,
                              64, [1, 1],
                              padding='VALID',
                              stride=[1, 1],
                              bn=use_bn,
                              is_training=is_training,
                              scope='conv8',
                              bn_decay=bn_decay)
        net = tf_util2.conv2d(net,
                              3, [1, 1],
                              padding='VALID',
                              stride=[1, 1],
                              bn=use_bn,
                              is_training=is_training,
                              scope='conv9',
                              bn_decay=bn_decay,
                              activation_fn=None)
        net = tf.squeeze(net, [2])

    return net, None, None
Example #13
0
def get_model(point_cloud,
              input_label,
              is_training,
              cat_num,
              part_num,
              batch_size,
              num_point,
              weight_decay,
              bn_decay=None):
    """
        Get ConvNet baseline model.
        :param point_cloud:
        :param input_label:
        :param is_training:
        :param cat_num:
        :param part_num:
        :param batch_size:
        :param num_point:
        :param weight_decay:
        :param bn_decay:
        :return:
    """
    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
Example #14
0
def get_model(v,
              displacement,
              edges_ss,
              edges_ss_n,
              is_training,
              final_activation,
              bn_decay=None):
    """Generat mesh network

    :param v: variance normalized source vertices
    :param displacement: displacement of each vertex from variance normalized source to variance normalized target
    :param edges_ss: the ij vertix, to compute w_ij, specified for the source vertices
    :param edges_ss_n: number of edges
    :param is_training: need to check what it does, exactly.
    :param final_activation: what activation to put in the final layer that drives w_ij, if range to be limited this hsould be
    sigmoidal.
    :param bn_decay:  need to check what it does, exactly.
    :return: neural network that produces w_ij to be later assambled into a hessian. 
    """

    concat_source_displacement = tf.concat([v, displacement], 2)
    batch_size = v.get_shape()[0].value
    num_point = v.get_shape()[1].value
    input_image = tf.expand_dims(concat_source_displacement, -1)

    net = tf_util.conv2d(input_image,
                         64, [1, 4],
                         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.dropout(net, keep_prob=0.7, is_training=is_training,
    #                       scope='dp1')

    global_feat = tf_util.max_pool2d(net, [num_point, 1],
                                     padding='VALID',
                                     scope='maxpool')

    global_feat_expand = tf.tile(global_feat, [1, edges_ss_n, 1, 1])
    edges_expanded = tf.expand_dims(edges_ss, axis=2)
    concat_feat = tf.concat([edges_expanded, global_feat_expand], 3)

    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)
    dim = 2
    net = tf_util.conv2d(net,
                         dim, [1, 1],
                         padding='VALID',
                         stride=[1, 1],
                         activation_fn=final_activation,
                         is_training=is_training,
                         scope='conv10')

    w_ij = tf.squeeze(net, [2])  # BxNxC

    return w_ij
Example #15
0
def get_model(point_cloud,
              up_ratio,
              is_training,
              bradius=1.0,
              knn=30,
              scope='generator',
              weight_decay=0.0,
              bn_decay=None,
              bn=True,
              fd=64,
              fD=1024):
    with tf.variable_scope(scope, reuse=tf.AUTO_REUSE) as sc:
        batch_size = point_cloud.get_shape()[0].value
        num_point = point_cloud.get_shape()[1].value
        input_point_cloud = tf.expand_dims(point_cloud, -1)

        adj = tf_util.pairwise_distance(point_cloud)
        nn_idx = tf_util.knn(adj, k=knn)
        edge_feature = tf_util.get_edge_feature(input_point_cloud,
                                                nn_idx=nn_idx,
                                                k=knn)

        with tf.variable_scope('transform_net1') as sc:
            transform = input_transform_net(edge_feature,
                                            is_training,
                                            bn_decay,
                                            K=3)
        point_cloud_transformed = tf.matmul(point_cloud, transform)
        input_point_cloud = tf.expand_dims(point_cloud_transformed, -1)
        adj = tf_util.pairwise_distance(point_cloud_transformed)
        nn_idx = tf_util.knn(adj, k=knn)
        edge_feature = tf_util.get_edge_feature(input_point_cloud,
                                                nn_idx=nn_idx,
                                                k=knn)

        out1 = tf_util.conv2d(edge_feature,
                              fd, [1, 1],
                              padding='VALID',
                              stride=[1, 1],
                              bn=bn,
                              is_training=is_training,
                              weight_decay=weight_decay,
                              scope='dgcnn_conv1',
                              bn_decay=bn_decay)

        out2 = tf_util.conv2d(out1,
                              fd, [1, 1],
                              padding='VALID',
                              stride=[1, 1],
                              bn=bn,
                              is_training=is_training,
                              weight_decay=weight_decay,
                              scope='dgcnn_conv2',
                              bn_decay=bn_decay)

        net_max_1 = tf.reduce_max(out2, axis=-2, keep_dims=True)
        net_mean_1 = tf.reduce_mean(out2, axis=-2, keep_dims=True)

        out3 = tf_util.conv2d(tf.concat([net_max_1, net_mean_1], axis=-1),
                              fd, [1, 1],
                              padding='VALID',
                              stride=[1, 1],
                              bn=bn,
                              is_training=is_training,
                              weight_decay=weight_decay,
                              scope='dgcnn_conv3',
                              bn_decay=bn_decay)

        adj = tf_util.pairwise_distance(tf.squeeze(out3, axis=-2))
        nn_idx = tf_util.knn(adj, k=knn)
        edge_feature = tf_util.get_edge_feature(out3, nn_idx=nn_idx, k=knn)

        out4 = tf_util.conv2d(edge_feature,
                              fd, [1, 1],
                              padding='VALID',
                              stride=[1, 1],
                              bn=bn,
                              is_training=is_training,
                              weight_decay=weight_decay,
                              scope='dgcnn_conv4',
                              bn_decay=bn_decay)

        net_max_2 = tf.reduce_max(out4, axis=-2, keep_dims=True)
        net_mean_2 = tf.reduce_mean(out4, axis=-2, keep_dims=True)

        out5 = tf_util.conv2d(tf.concat([net_max_2, net_mean_2], axis=-1),
                              fd, [1, 1],
                              padding='VALID',
                              stride=[1, 1],
                              bn=bn,
                              is_training=is_training,
                              weight_decay=weight_decay,
                              scope='dgcnn_conv5',
                              bn_decay=bn_decay)

        adj = tf_util.pairwise_distance(tf.squeeze(out5, axis=-2))
        nn_idx = tf_util.knn(adj, k=knn)
        edge_feature = tf_util.get_edge_feature(out5, nn_idx=nn_idx, k=knn)

        out6 = tf_util.conv2d(edge_feature,
                              fd, [1, 1],
                              padding='VALID',
                              stride=[1, 1],
                              bn=bn,
                              is_training=is_training,
                              weight_decay=weight_decay,
                              scope='dgcnn_conv6',
                              bn_decay=bn_decay)

        net_max_3 = tf.reduce_max(out6, axis=-2, keep_dims=True)
        net_mean_3 = tf.reduce_mean(out6, axis=-2, keep_dims=True)

        out7 = tf_util.conv2d(tf.concat([net_max_3, net_mean_3], axis=-1),
                              fd, [1, 1],
                              padding='VALID',
                              stride=[1, 1],
                              bn=bn,
                              is_training=is_training,
                              weight_decay=weight_decay,
                              scope='dgcnn_conv7',
                              bn_decay=bn_decay)

        out8 = tf_util.conv2d(tf.concat([out3, out5, out7], axis=-1),
                              fD, [1, 1],
                              padding='VALID',
                              stride=[1, 1],
                              bn=bn,
                              is_training=is_training,
                              scope='dgcnn_conv8',
                              bn_decay=bn_decay)

        out_max = tf_util.max_pool2d(out8, [num_point, 1],
                                     padding='VALID',
                                     scope='maxpool')

        expand = tf.tile(out_max, [1, num_point, 1, 1])

        concat_unweight = tf.concat(axis=3,
                                    values=[
                                        expand, net_max_1, net_mean_1, out3,
                                        net_max_2, net_mean_2, out5, net_max_3,
                                        net_mean_3, out7, out8
                                    ])

        feat_list = [
            "expand", "net_max_1", "net_mean_1", "out3", "net_max_2",
            "net_mean_2", "out5", "net_max_3", "net_mean_3", "out7", "out8"
        ]

        out_attention = tf_util.conv2d(concat_unweight,
                                       128, [1, 1],
                                       padding='VALID',
                                       stride=[1, 1],
                                       bn_decay=bn_decay,
                                       bn=True,
                                       is_training=is_training,
                                       scope='attention_conv1',
                                       weight_decay=weight_decay)
        out_attention = tf_util.conv2d(out_attention,
                                       64, [1, 1],
                                       padding='VALID',
                                       stride=[1, 1],
                                       bn_decay=bn_decay,
                                       bn=True,
                                       is_training=is_training,
                                       scope='attention_conv2',
                                       weight_decay=weight_decay)
        out_attention = tf_util.conv2d(out_attention,
                                       len(feat_list), [1, 1],
                                       padding='VALID',
                                       stride=[1, 1],
                                       bn_decay=bn_decay,
                                       bn=True,
                                       is_training=is_training,
                                       scope='attention_conv3',
                                       weight_decay=weight_decay)

        out_attention = tf_util.max_pool2d(out_attention, [num_point, 1],
                                           padding='VALID',
                                           scope='attention_maxpool')
        out_attention = tf.nn.softmax(out_attention)
        tmp_attention = tf.squeeze(out_attention)

        for i in range(len(feat_list)):
            tmp1 = tf.slice(out_attention, [0, 0, 0, i], [1, 1, 1, 1])
            exec('dim = %s.get_shape()[-1].value' % feat_list[i])
            tmp2 = tf.tile(tmp1, [1, 1, 1, dim])
            if i == 0:
                attention_weight = tmp2
            else:
                attention_weight = tf.concat([attention_weight, tmp2], axis=-1)
        attention_weight = tf.tile(attention_weight, [1, num_point, 1, 1])
        concat = tf.multiply(concat_unweight, attention_weight)

        concat = tf_util.conv2d(concat,
                                256, [1, 1],
                                padding='VALID',
                                stride=[1, 1],
                                bn_decay=bn_decay,
                                bn=True,
                                is_training=is_training,
                                scope='concat_conv',
                                weight_decay=weight_decay)
        concat = tf_util.dropout(concat,
                                 keep_prob=0.6,
                                 is_training=is_training,
                                 scope='dg1')

        with tf.variable_scope('uv_predict'):
            uv_2d = tf_util.conv2d(concat,
                                   up_ratio * 2, [1, 1],
                                   padding='VALID',
                                   stride=[1, 1],
                                   bn_decay=bn_decay,
                                   activation_fn=None,
                                   bn=None,
                                   is_training=is_training,
                                   scope='uv_conv1',
                                   weight_decay=weight_decay)
            uv_2d = tf.reshape(uv_2d, [batch_size, num_point, up_ratio, 2])
            uv_2d = tf.concat(
                [uv_2d, tf.zeros([batch_size, num_point, up_ratio, 1])],
                axis=-1)

        with tf.variable_scope('T_predict'):
            affine_T = tf_util.conv2d(concat,
                                      9, [1, 1],
                                      padding='VALID',
                                      stride=[1, 1],
                                      bn_decay=bn_decay,
                                      activation_fn=None,
                                      bn=None,
                                      is_training=is_training,
                                      scope='patch_conv1',
                                      weight_decay=weight_decay)
            affine_T = tf.reshape(affine_T, [batch_size, num_point, 3, 3])

            uv_3d = tf.matmul(uv_2d, affine_T)
            uv_3d = uv_3d + tf.tile(tf.expand_dims(point_cloud, axis=-2),
                                    [1, 1, up_ratio, 1])
            uv_3d = tf.transpose(uv_3d, perm=[0, 2, 1, 3])
            uv_3d = tf.reshape(uv_3d, [batch_size, num_point * up_ratio, -1])

        with tf.variable_scope('normal_predict'):
            dense_normal_offset = tf_util.conv2d(concat,
                                                 up_ratio * 3, [1, 1],
                                                 padding='VALID',
                                                 stride=[1, 1],
                                                 bn_decay=bn_decay,
                                                 activation_fn=None,
                                                 bn=None,
                                                 is_training=is_training,
                                                 scope='normal_offset_conv1',
                                                 weight_decay=weight_decay)
            dense_normal_offset = tf.reshape(
                dense_normal_offset, [batch_size, num_point, up_ratio, 3])

            sparse_normal = tf.convert_to_tensor([0, 0, 1], dtype=tf.float32)
            sparse_normal = tf.expand_dims(sparse_normal, axis=0)
            sparse_normal = tf.expand_dims(sparse_normal, axis=0)
            sparse_normal = tf.expand_dims(sparse_normal, axis=0)
            sparse_normal = tf.tile(sparse_normal,
                                    [batch_size, num_point, 1, 1])
            sparse_normal = tf.matmul(sparse_normal, affine_T)
            sparse_normal = tf.nn.l2_normalize(sparse_normal, axis=-1)

            dense_normal = tf.tile(sparse_normal,
                                   [1, 1, up_ratio, 1]) + dense_normal_offset

            dense_normal = tf.nn.l2_normalize(dense_normal, axis=-1)
            dense_normal = tf.transpose(dense_normal, perm=[0, 2, 1, 3])
            dense_normal = tf.reshape(dense_normal,
                                      [batch_size, num_point * up_ratio, -1])

        with tf.variable_scope('up_layer'):
            if not np.isscalar(bradius):
                bradius_expand = tf.expand_dims(tf.expand_dims(bradius,
                                                               axis=-1),
                                                axis=-1)
            else:
                bradius_expand = bradius
            bradius_expand = bradius_expand
            grid = tf.expand_dims(uv_3d * bradius_expand, axis=2)

            concat_up = tf.tile(concat, (1, up_ratio, 1, 1))
            concat_up = tf.concat([concat_up, grid], axis=-1)

            concat_up = tf_util.conv2d(concat_up,
                                       128, [1, 1],
                                       padding='VALID',
                                       stride=[1, 1],
                                       bn=True,
                                       is_training=is_training,
                                       scope='up_layer1',
                                       bn_decay=bn_decay,
                                       weight_decay=weight_decay)

            concat_up = tf_util.dropout(concat_up,
                                        keep_prob=0.6,
                                        is_training=is_training,
                                        scope='up_dg1')

            concat_up = tf_util.conv2d(concat_up,
                                       128, [1, 1],
                                       padding='VALID',
                                       stride=[1, 1],
                                       bn=True,
                                       is_training=is_training,
                                       scope='up_layer2',
                                       bn_decay=bn_decay,
                                       weight_decay=weight_decay)
            concat_up = tf_util.dropout(concat_up,
                                        keep_prob=0.6,
                                        is_training=is_training,
                                        scope='up_dg2')

        # get xyz
        coord_z = tf_util.conv2d(concat_up,
                                 1, [1, 1],
                                 padding='VALID',
                                 stride=[1, 1],
                                 activation_fn=None,
                                 bn=False,
                                 is_training=is_training,
                                 scope='fc_layer',
                                 weight_decay=weight_decay)
        coord_z = tf.reshape(coord_z, [batch_size, up_ratio, num_point, 1])
        coord_z = tf.transpose(coord_z, perm=[0, 2, 1, 3])
        coord_z = tf.concat(
            [tf.zeros_like(coord_z),
             tf.zeros_like(coord_z), coord_z], axis=-1)

        coord_z = tf.matmul(coord_z, affine_T)
        coord_z = tf.transpose(coord_z, perm=[0, 2, 1, 3])
        coord_z = tf.reshape(coord_z, [batch_size, num_point * up_ratio, -1])

        coord = uv_3d + coord_z

    return coord, dense_normal, tf.squeeze(sparse_normal, [2])
Example #16
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
Example #17
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
Example #18
0
def get_model(point_cloud, is_training, 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')

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

    net = 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)
    net = tf_util.dropout(net,
                          keep_prob=0.8,
                          is_training=is_training,
                          scope='seg/dp1')
    net = tf_util.conv2d(net,
                         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)
    net = tf_util.dropout(net,
                          keep_prob=0.8,
                          is_training=is_training,
                          scope='seg/dp2')
    net = tf_util.conv2d(net,
                         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)
    net = tf_util.conv2d(net,
                         part_num, [1, 1],
                         padding='VALID',
                         stride=[1, 1],
                         activation_fn=None,
                         bn=False,
                         scope='seg/conv4',
                         weight_decay=weight_decay)

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

    return net, end_points
Example #19
0
def feature_transform_net(inputs, is_training, 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_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.compat.v1.variable_scope('transform_feat') as sc:
        weights = tf.compat.v1.get_variable(
            'weights', [256, K * K],
            initializer=tf.compat.v1.constant_initializer(0.0),
            dtype=tf.float32)
        biases = tf.compat.v1.get_variable(
            'biases', [K * K],
            initializer=tf.compat.v1.constant_initializer(0.0),
            dtype=tf.float32)
        biases.assign_add(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
Example #20
0
    def create_encoder(self, inputs, npts):
        """PointNet encoder"""

        inputs = tf.reshape(inputs, (BATCH_SIZE, NUM_POINT, 3))
        with tf.variable_scope('transform_net1') as sc:
            transform = input_transform_net(inputs,
                                            self.is_training,
                                            self.bn_decay,
                                            K=3)

        point_cloud_transformed = tf.matmul(inputs, transform)
        input_image = tf.expand_dims(point_cloud_transformed, -1)

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

        with tf.variable_scope('transform_net2') as sc:
            transform = feature_transform_net(net,
                                              self.is_training,
                                              self.bn_decay,
                                              K=64)
        net_transformed = tf.matmul(tf.squeeze(net, axis=[2]), transform)
        net_transformed = tf.expand_dims(net_transformed, [2])
        '''conv2d, with kernel size of [1,1,1,1] and stride of [1,1,1,1],
		basically equals with the MLPs'''

        # use_xavier=True, stddev=1e-3, weight_decay=0.0, activation_fn=tf.nn.relu,
        net = conv2d(net_transformed,
                     64, [1, 1],
                     scope='conv3',
                     padding='VALID',
                     stride=[1, 1],
                     bn=True,
                     is_training=self.is_training,
                     bn_decay=self.bn_decay)
        net = conv2d(net,
                     128, [1, 1],
                     padding='VALID',
                     stride=[1, 1],
                     bn=True,
                     is_training=self.is_training,
                     scope='conv4',
                     bn_decay=self.bn_decay)
        net = conv2d(net,
                     1024, [1, 1],
                     padding='VALID',
                     stride=[1, 1],
                     bn=True,
                     is_training=self.is_training,
                     scope='conv5',
                     bn_decay=self.bn_decay)

        net = max_pool2d(net, [NUM_POINT, 1], padding='VALID', scope='maxpool')

        features = tf.reshape(net, [BATCH_SIZE, -1])
        return features
def get_model(point_cloud,
              is_training,
              normals,
              use_local_frame=True,
              add_normals=False,
              bn=True,
              bn_decay=None,
              use_xavier=True,
              align_pointclouds=False,
              drop_prob=0.5,
              n_classes=1,
              k=20):
    """ Part segmentation DGCNN, input is BxNxnFeatures, output BxnClasses """

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

    # Input xyz coordinates
    input_xyz = tf.slice(point_cloud, [0, 0, 0], [-1, -1, 3])

    # Add tangent vectors and normals for local frames calculation
    local_frame_data = None
    if use_local_frame:
        tangent_vec1 = tf.slice(point_cloud, [0, 0, 3], [-1, -1, 3],
                                name="tangent_vec1")
        tangent_vec2 = tf.slice(point_cloud, [0, 0, 6], [-1, -1, 3],
                                name="tangent_vec2")
        local_frame_data = (tangent_vec1, tangent_vec2, normals)

    # Point clouds global alignment
    if align_pointclouds:
        # Calculate pairwise distance on global coordinates and find k-nn's for each point
        adj = tf_util.pairwise_distance(input_xyz)
        nn_idx = tf_util.knn(adj, k=k)
        input_xyz = tf.expand_dims(input_xyz, -1)
        edge_feature = tf_util.get_edge_feature(input_xyz, nn_idx=nn_idx, k=k)

        with tf.variable_scope('transform_net_global') as sc:
            global_transform = global_spatial_transformer(
                point_cloud=edge_feature,
                is_training=is_training,
                bn=bn,
                bn_decay=bn_decay,
                is_dist=True)
        input_xyz = tf.matmul(tf.squeeze(input_xyz, axis=-1), global_transform)

    if add_normals:
        if input_xyz.shape.ndims == 4:
            input_xyz = tf.squeeze(input_xyz, axis=-1)
        input_xyz = tf.concat([input_xyz, normals], axis=-1)

    input_image = tf.expand_dims(input_xyz, -1)
    adj = tf_util.pairwise_distance(input_xyz)
    nn_idx = tf_util.knn(adj, k=k)
    edge_feature = tf_util.get_edge_feature(input_image,
                                            nn_idx=nn_idx,
                                            k=k,
                                            use_local_frame=use_local_frame,
                                            local_frame_data=local_frame_data,
                                            add_normals=add_normals)

    # EdgeConv layer 1 {64, 64}
    out1 = tf_util.conv2d(edge_feature,
                          64, [1, 1],
                          padding='VALID',
                          stride=[1, 1],
                          bn=bn,
                          is_training=is_training,
                          scope='adj_conv1',
                          bn_decay=bn_decay,
                          is_dist=True,
                          use_xavier=use_xavier)

    out2 = tf_util.conv2d(out1,
                          64, [1, 1],
                          padding='VALID',
                          stride=[1, 1],
                          bn=bn,
                          is_training=is_training,
                          scope='adj_conv2',
                          bn_decay=bn_decay,
                          is_dist=True,
                          use_xavier=use_xavier)

    net_1 = tf.reduce_max(out2, axis=-2, keep_dims=True)

    # EdgeConv layer 2 {64, 64}
    adj = tf_util.pairwise_distance(net_1)
    nn_idx = tf_util.knn(adj, k=k)
    edge_feature = tf_util.get_edge_feature(net_1, nn_idx=nn_idx, k=k)

    out3 = tf_util.conv2d(edge_feature,
                          64, [1, 1],
                          padding='VALID',
                          stride=[1, 1],
                          bn=bn,
                          is_training=is_training,
                          scope='adj_conv3',
                          bn_decay=bn_decay,
                          is_dist=True,
                          use_xavier=use_xavier)

    out4 = tf_util.conv2d(out3,
                          64, [1, 1],
                          padding='VALID',
                          stride=[1, 1],
                          bn=bn,
                          is_training=is_training,
                          scope='adj_conv4',
                          bn_decay=bn_decay,
                          is_dist=True,
                          use_xavier=use_xavier)

    net_2 = tf.reduce_max(out4, axis=-2, keep_dims=True)

    # EdgeConv layer 3 {64}
    adj = tf_util.pairwise_distance(net_2)
    nn_idx = tf_util.knn(adj, k=k)
    edge_feature = tf_util.get_edge_feature(net_2, nn_idx=nn_idx, k=k)

    out5 = tf_util.conv2d(edge_feature,
                          64, [1, 1],
                          padding='VALID',
                          stride=[1, 1],
                          bn=bn,
                          is_training=is_training,
                          scope='adj_conv5',
                          bn_decay=bn_decay,
                          is_dist=True,
                          use_xavier=use_xavier)

    net_3 = tf.reduce_max(out5, axis=-2, keep_dims=True)

    # [EdgeConv1, EdgeConv2, EdgeConv3] -> MLP {64}
    out7 = tf_util.conv2d(tf.concat([net_1, net_2, net_3], axis=-1),
                          1024, [1, 1],
                          padding='VALID',
                          stride=[1, 1],
                          bn=bn,
                          is_training=is_training,
                          scope='adj_conv7',
                          bn_decay=bn_decay,
                          is_dist=True,
                          use_xavier=use_xavier)

    out_max = tf_util.max_pool2d(out7, [num_point, 1],
                                 padding='VALID',
                                 scope='maxpool')
    expand = tf.tile(out_max, [1, num_point, 1, 1])

    # Concat [global_feature, EdgeConv1, EdgeConv2, EdgeConv3]
    concat = tf.concat(axis=3, values=[expand, net_1, net_2, net_3])

    # FC layer - MLP{256, 256, 128, n_classes}
    net2 = tf_util.conv2d(concat,
                          256, [1, 1],
                          padding='VALID',
                          stride=[1, 1],
                          bn_decay=bn_decay,
                          bn=bn,
                          is_training=is_training,
                          scope='seg/conv1',
                          is_dist=True,
                          use_xavier=use_xavier)
    net2 = tf_util.dropout(net2,
                           keep_prob=1 - drop_prob,
                           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=bn,
                          is_training=is_training,
                          scope='seg/conv2',
                          is_dist=True,
                          use_xavier=use_xavier)
    net2 = tf_util.dropout(net2,
                           keep_prob=1 - drop_prob,
                           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=bn,
                          is_training=is_training,
                          scope='seg/conv3',
                          is_dist=True,
                          use_xavier=use_xavier)
    net2 = tf_util.conv2d(net2,
                          n_classes, [1, 1],
                          padding='VALID',
                          stride=[1, 1],
                          activation_fn=None,
                          bn=False,
                          scope='seg/conv4',
                          is_dist=False,
                          use_xavier=use_xavier)

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

    return net2
Example #22
0
def global_spatial_transformer(point_cloud,
                               is_training,
                               K=3,
                               bn=True,
                               bn_decay=None,
                               is_dist=True):
    """ Input (XYZ) Transform Net, input is BxNx3 gray image
        Return:
            Transformation matrix of size KxK """

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

    net = tf_util.conv2d(point_cloud,
                         64, [1, 1],
                         padding='VALID',
                         stride=[1, 1],
                         bn=bn,
                         is_training=is_training,
                         scope='tconv1',
                         bn_decay=bn_decay,
                         is_dist=is_dist)
    net = tf_util.conv2d(net,
                         128, [1, 1],
                         padding='VALID',
                         stride=[1, 1],
                         bn=bn,
                         is_training=is_training,
                         scope='tconv2',
                         bn_decay=bn_decay,
                         is_dist=is_dist)
    net = tf.reduce_max(net, axis=-2, keep_dims=True)

    net = tf_util.conv2d(net,
                         1024, [1, 1],
                         padding='VALID',
                         stride=[1, 1],
                         bn=bn,
                         is_training=is_training,
                         scope='tconv3',
                         bn_decay=bn_decay,
                         is_dist=is_dist)
    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=bn,
                                  is_training=is_training,
                                  scope='tfc1',
                                  bn_decay=bn_decay,
                                  is_dist=is_dist)
    net = tf_util.fully_connected(net,
                                  256,
                                  bn=bn,
                                  is_training=is_training,
                                  scope='tfc2',
                                  bn_decay=bn_decay,
                                  is_dist=is_dist)

    with tf.variable_scope('transform_XYZ') 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, [batch_size, K, K])

    return transform
Example #23
0
def get_model(point_cloud,
              is_training,
              mask=None,
              bn_decay=None,
              label_type="normal"):
    """Classification PointNet, input is BxNx3, output Bx40
        arguments:
            point_clound: numpy array
            is_training: boolean
            bn_decay: boolean or None
        output:
            tensorflow model
    """
    batch_size = point_cloud.get_shape()[0].value
    num_point = point_cloud.get_shape()[1].value

    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)

    # Point functions (MLP implemented as conv2d)
    with tf.variable_scope("conv1") as sc:
        net_conv1 = tf_util.conv2d(input_image,
                                   64, [1, 3],
                                   padding='VALID',
                                   stride=[1, 1],
                                   bn=True,
                                   is_training=is_training,
                                   scope='conv1_1',
                                   bn_decay=bn_decay)
        net_conv3 = tf.pad(input_image, [[0, 0], [1, 1], [0, 0], [0, 0]])
        net_conv3 = tf_util.conv2d(net_conv3,
                                   64, [3, 3],
                                   padding='VALID',
                                   stride=[1, 1],
                                   bn=True,
                                   is_training=is_training,
                                   scope='conv1_3',
                                   bn_decay=bn_decay)
        net_conv5 = tf.pad(input_image, [[0, 0], [2, 2], [0, 0], [0, 0]])
        net_conv5 = tf_util.conv2d(net_conv5,
                                   64, [5, 3],
                                   padding='VALID',
                                   stride=[1, 1],
                                   bn=True,
                                   is_training=is_training,
                                   scope='conv1_5',
                                   bn_decay=bn_decay)
        net = tf.concat([net_conv1, net_conv3, net_conv5], 3, name="concat_1")

    with tf.variable_scope("conv2") as sc:
        net_conv1 = tf_util.conv2d(net,
                                   128, [1, 1],
                                   padding='VALID',
                                   stride=[1, 1],
                                   bn=True,
                                   is_training=is_training,
                                   scope='conv2_1',
                                   bn_decay=bn_decay)
        net_conv3 = tf.pad(net, [[0, 0], [1, 1], [0, 0], [0, 0]])
        net_conv3 = tf_util.conv2d(net_conv3,
                                   128, [3, 1],
                                   padding='VALID',
                                   stride=[1, 1],
                                   bn=True,
                                   is_training=is_training,
                                   scope='conv2_3',
                                   bn_decay=bn_decay)
        net_conv5 = tf.pad(net, [[0, 0], [2, 2], [0, 0], [0, 0]])
        net_conv5 = tf_util.conv2d(net_conv5,
                                   128, [5, 1],
                                   padding='VALID',
                                   stride=[1, 1],
                                   bn=True,
                                   is_training=is_training,
                                   scope='conv2_5',
                                   bn_decay=bn_decay)
        net = tf.concat([net_conv1, net_conv3, net_conv5], 3, name="concat_2")

    with tf.variable_scope("conv3") as sc:
        net_conv1 = tf_util.conv2d(net,
                                   256, [1, 1],
                                   padding='VALID',
                                   stride=[1, 1],
                                   bn=True,
                                   is_training=is_training,
                                   scope='conv3_1',
                                   bn_decay=bn_decay)
        net_conv3 = tf.pad(net, [[0, 0], [1, 1], [0, 0], [0, 0]])
        net_conv3 = tf_util.conv2d(net_conv3,
                                   256, [3, 1],
                                   padding='VALID',
                                   stride=[1, 1],
                                   bn=True,
                                   is_training=is_training,
                                   scope='conv3_3',
                                   bn_decay=bn_decay)
        net_conv5 = tf.pad(net, [[0, 0], [2, 2], [0, 0], [0, 0]])
        net_conv5 = tf_util.conv2d(net_conv5,
                                   256, [5, 1],
                                   padding='VALID',
                                   stride=[1, 1],
                                   bn=True,
                                   is_training=is_training,
                                   scope='conv3_5',
                                   bn_decay=bn_decay)
        net = tf.concat([net_conv1, net_conv3, net_conv5], 3, name="concat_3")

    # masking
    net = tf.multiply(net, tf.cast(mask, tf.float32))

    net = tf_util.max_pool2d(net,
                             kernel_size=[num_point, 1],
                             scope='max_pooling',
                             padding='VALID')

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

    # 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.fully_connected(net,
                                  128,
                                  bn=True,
                                  is_training=is_training,
                                  scope='fc3',
                                  bn_decay=bn_decay)
    # net = tf_util.dropout(net, keep_prob=0.7, is_training=is_training,
    #                       scope='dp1')
    if label_type == "normal":
        output = tf_util.fully_connected(net,
                                         1,
                                         scope='fc4',
                                         activation_fn=None)
    elif label_type == "onehot":
        output = tf_util.fully_connected(net,
                                         10,
                                         scope="fc4",
                                         activation_fn=None)

    return output
Example #24
0
    def create_encoder(self, inputs, npts):
        # with tf.variable_scope('encoder_0', reuse=tf.AUTO_REUSE):
        #     features = mlp_conv(inputs, [128, 256])
        #     features_global = tf.reduce_max(features, axis=1, keep_dims=True, name='maxpool_0')
        #     features = tf.concat([features, tf.tile(features_global, [1, tf.shape(inputs)[1], 1])], axis=2)
        # with tf.variable_scope('encoder_1', reuse=tf.AUTO_REUSE):
        #     features = mlp_conv(features, [512, 1024])
        #     features = tf.reduce_max(features, axis=1, name='maxpool_1')
        # end_points = {}

        # if DATASET =='modelnet40':
        inputs = tf.reshape(inputs, (BATCH_SIZE, NUM_POINT, 3))

        with tf.variable_scope('transform_net1') as sc:
            transform = input_transform_net(inputs,
                                            self.is_training,
                                            self.bn_decay,
                                            K=3)

        point_cloud_transformed = tf.matmul(inputs, transform)
        input_image = tf.expand_dims(point_cloud_transformed, -1)

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

        with tf.variable_scope('transform_net2') as sc:
            transform = feature_transform_net(net,
                                              self.is_training,
                                              self.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])
        '''conv2d, with kernel size of [1,1,1,1] and stride of [1,1,1,1],
		basically equals with the MLPs'''

        # use_xavier=True, stddev=1e-3, weight_decay=0.0, activation_fn=tf.nn.relu,
        net = conv2d(net_transformed,
                     64, [1, 1],
                     scope='conv3',
                     padding='VALID',
                     stride=[1, 1],
                     bn=True,
                     is_training=self.is_training,
                     bn_decay=self.bn_decay)
        net = conv2d(net,
                     128, [1, 1],
                     padding='VALID',
                     stride=[1, 1],
                     bn=True,
                     is_training=self.is_training,
                     scope='conv4',
                     bn_decay=self.bn_decay)
        net = conv2d(net,
                     1024, [1, 1],
                     padding='VALID',
                     stride=[1, 1],
                     bn=True,
                     is_training=self.is_training,
                     scope='conv5',
                     bn_decay=self.bn_decay)

        net = max_pool2d(net, [NUM_POINT, 1], padding='VALID', scope='maxpool')

        features = tf.reshape(net, [BATCH_SIZE, -1])
        return features
Example #25
0
def get_model(point_cloud, is_training, num_class, bn_decay=None):
    """ Semantic segmentation PointNet, input is BxNxF, output Bxnum_class """
    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)

    # CONV layers
    net = tf_util.conv2d(input_image,
                         64, [1, 9],
                         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,
                         128, [1, 1],
                         padding='VALID',
                         stride=[1, 1],
                         bn=True,
                         is_training=is_training,
                         scope='conv3',
                         bn_decay=bn_decay)
    net = tf_util.conv2d(net,
                         512, [1, 1],
                         padding='VALID',
                         stride=[1, 1],
                         bn=True,
                         is_training=is_training,
                         scope='conv4',
                         bn_decay=bn_decay)
    points_feat1 = tf_util.conv2d(net,
                                  2048, [1, 1],
                                  padding='VALID',
                                  stride=[1, 1],
                                  bn=True,
                                  is_training=is_training,
                                  scope='conv5',
                                  bn_decay=bn_decay)
    # MAX Pooling
    pc_feat1 = tf_util.max_pool2d(points_feat1, [num_point, 1],
                                  padding='VALID',
                                  scope='maxpool1')
    # FC layers
    pc_feat1 = tf.reshape(pc_feat1, [batch_size, -1])
    pc_feat1 = tf_util.fully_connected(pc_feat1,
                                       512,
                                       bn=True,
                                       is_training=is_training,
                                       scope='fc1',
                                       bn_decay=bn_decay)
    pc_feat1 = tf_util.fully_connected(pc_feat1,
                                       256,
                                       bn=True,
                                       is_training=is_training,
                                       scope='fc2',
                                       bn_decay=bn_decay)

    # 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=[points_feat1, pc_feat1_expand])

    # CONV Layers
    net = tf_util.conv2d(points_feat1_concat,
                         512, [1, 1],
                         padding='VALID',
                         stride=[1, 1],
                         bn=True,
                         is_training=is_training,
                         scope='conv6')
    net = tf_util.conv2d(net,
                         256, [1, 1],
                         padding='VALID',
                         stride=[1, 1],
                         bn=True,
                         is_training=is_training,
                         scope='conv7')
    net = tf_util.conv2d(net,
                         128, [1, 1],
                         padding='VALID',
                         stride=[1, 1],
                         bn=True,
                         is_training=is_training,
                         scope='conv8')
    net = tf_util.conv2d(net,
                         128, [1, 1],
                         padding='VALID',
                         stride=[1, 1],
                         bn=True,
                         is_training=is_training,
                         scope='conv9')

    net = tf_util.dropout(net,
                          keep_prob=0.5,
                          is_training=is_training,
                          scope='dp1')

    net = tf_util.conv2d(net,
                         num_class, [1, 1],
                         padding='VALID',
                         stride=[1, 1],
                         activation_fn=None,
                         scope='conv10')
    net = tf.squeeze(net, [2])

    return net, end_points