def input_transform_net(points, is_training, name, dim=3, reused=None): """ Input (XYZ) Transform Net, input is BxNx3 points data Return: Transformation matrix of size 3xK """ pts_num = points.get_shape()[1].value batch_size = points.get_shape()[0].value net = pf.dense(points, 64, name + 'mlp1', is_training, activation_fn=tf.nn.relu, reuse=reused) net = pf.dense(net, 128, name + 'mlp2', is_training, activation_fn=tf.nn.relu, reuse=reused) net = pf.dense(net, 1024, name + 'mlp3', is_training, activation_fn=tf.nn.relu, reuse=reused) net = tf.expand_dims(net, axis=-1, name=name+'expand_dim') net = pf.max_pool2d(net, [pts_num, 1], stride=[1, 1], name=name + 'pooling') net = tf.reshape(net, [batch_size, 1024]) net = pf.dense(net, 128, name + 'mlp4', is_training, activation_fn=tf.nn.relu, reuse=reused) net = pf.dense(net, 64, name + 'mlp5', is_training, activation_fn=tf.nn.relu, reuse=reused) with tf.variable_scope(name + 'xyz_transform', reuse=reused): assert(dim == 3) weights = tf.get_variable('weights', [64, 3*dim], initializer=tf.constant_initializer(0.0), dtype=tf.float32) biases = tf.get_variable('biases', [3*dim], 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, dim]) return transform
def input_qtransform_net(points, is_training, name, reused=None): batch_size = points.get_shape()[0].value point_num = points.get_shape()[1].value net = pf.dense(points, 64, name + 'mlp1', is_training, activation_fn=tf.nn.relu, reuse=reused) net = pf.dense(net, 128, name + 'mlp2', is_training, activation_fn=tf.nn.relu, reuse=reused) net = pf.dense(net, 1024, name + 'mlp3', is_training, activation_fn=tf.nn.relu, reuse=reused) net = tf.expand_dims(net, axis=-1, name=name + 'expand_dim') net = pf.max_pool2d(net, [point_num, 1], stride=[1, 1], name=name+'pooling') net = tf.reshape(net, [batch_size, 1, 1024]) net = pf.dense(net, 128, name + 'mlp4', is_training, activation_fn=tf.nn.relu, reuse=reused) net = pf.dense(net, 64, name + 'mlp5', is_training, activation_fn=tf.nn.relu, reuse=reused) with tf.variable_scope(name+'q_transform', reuse=reused): weights = tf.get_variable('weights', [64, 4], initializer=tf.constant_initializer(0.0), dtype=tf.float32) biases = tf.get_variable('biases', [4], initializer=tf.constant_initializer(0.0), dtype=tf.float32) biases += tf.constant([1, 0, 0, 0], dtype=tf.float32) weights = tf.expand_dims(weights, 0) weights = tf.tile(weights, [batch_size, 1, 1]) transform = tf.matmul(net, weights) # [batch_size, 1, 4] each shape has a trans matrix transform = tf.nn.bias_add(transform, biases) qtransform = batch_quat_to_rotmat(transform) return qtransform
def input_transform_net(point_cloud, is_training,N, PP,KK=3): """ Input (XYZ) Transform Net, input is BxNx3 gray image Return: Transformation matrix of size 3xK """ input_image = tf.expand_dims(point_cloud, -1) print(input_image) net = pf.conv2d(input_image, 64, 'tconv1', is_training,(1,3)) net = pf.dense(net, 128, 'tconv2', is_training) net = pf.dense(net, 1024, 'tconv3', is_training) print(net) net = pf.max_pool2d(net,[1024,1],'tmaxpool') net = pf.dense(net, 512, 'tfc1',is_training) net = pf.dense(net, 256, 'tfc2',is_training) net = tf.reshape(net, (N, -1)) with tf.variable_scope('transform_XYZ') as sc: assert(KK==3) weights = tf.get_variable('weights', (256, 3*KK), initializer=tf.constant_initializer(0.0), dtype=tf.float32) biases = tf.get_variable('biases', (3*KK), 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, (N, 3, KK)) return transform
def point_feat_extract(self, points, name, is_training, is_trans, is_reused=None): pts_num = points.get_shape()[1].value if is_trans == 'q_trans': transform_matrix = input_qtransform_net(points, is_training, name+'rotation', reused = is_reused) points_t = tf.matmul(points, transform_matrix) else: if is_trans == 'trans': transform_matrix = input_transform_net(points, is_training, name+'rotation', reused = is_reused) points_t = tf.matmul(points, transform_matrix) else: points_t = points net = pf.dense(points_t, 64, name+'mlp1', is_training, reuse=is_reused, activation_fn=tf.nn.relu) net = pf.dense(net, 128, name+'mlp2', is_training, reuse=is_reused, activation_fn=tf.nn.relu) net = pf.dense(net, 256, name+'mlp3', is_training, reuse=is_reused, activation_fn=tf.nn.relu) net = pf.dense(net, 1024, name+'mlp4', is_training, reuse=is_reused, activation_fn=tf.nn.relu) pfts = net net = tf.expand_dims(net, axis=-1, name=name+'extend_input') net = pf.max_pool2d(net, [pts_num, 1], stride=[1, 1], name=name+'pooling') net_tile = tf.tile(tf.squeeze(net, axis=-1), [1, pts_num, 1]) concat_pfts = tf.concat([pfts, net_tile], axis=-1) if is_trans is not 'no_trans': return concat_pfts, tf.squeeze(net, axis=[1, 3]), transform_matrix, points_t else: return concat_pfts, tf.squeeze(net, axis=[1, 3]), points_t
def pointnet1(point_cloud, is_training, N, PP): transform = input_transform_net(point_cloud, is_training, N, PP, KK=3) point_cloud_transformed = tf.matmul(point_cloud, transform) input_image = tf.expand_dims(point_cloud_transformed, -1) # (N,PP,3,1) net = pf.conv2d(input_image, 64, 'p1_conv1', is_training,(1,3)) # (N,PP,1,64) net = pf.dense(net, 64, 'p1_mlp1', is_training) # (N,PP,1,64) net = pf.dense(net, 64, 'p1_mlp2', is_training) # (N,PP,1,64) net = pf.dense(net, 128, 'p1_mlp3', is_training) # (N,PP,1,128) net = pf.dense(net, 1024, 'p1_mlp4', is_training) # (N,PP,1,1024) net1 = net net = pf.max_pool2d(net,[PP,1],'p1_maxpool') # (N,1,1,1024) net = tf.squeeze(net, axis=[2]) net1 = tf.squeeze(net1, axis=[2]) return net,net1