先看工程中的调用
with tf.variable_scope('transform_net2') as sc:
transform = feature_transform_net(net, is_training, bn_decay, K=64)
with....类似C++里面的namespace、
输入的net是shape[32,1024,1,64],pointcloud乘以transformnet训练输出的32个3x3的矩阵进行旋转平移,保证了点云旋转不变性,再为了旋转继续拓展一维到32,1024,3,1。
然后经过conv1,卷积为32,1024,1,64,的tensor再经过conv2,继续卷积为32,1024,1,64.
最后来到第二个transform_net2进行特征值的旋转矩阵训练net,具体代码如下:
bn_decay为初始化过程中定义的指数增加learningrate。
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.variable_scope('transform_feat') as sc:
weights = tf.get_variable('weights', [256, K*K],
initializer=tf.constant_initializer(0.0),
dtype=tf.float32)
biases = tf.get_variable('biases', [K*K],
initializer=tf.constant_initializer(0.0),
dtype=tf.float32)
biases += tf.constant(np.eye(K).flatten(), dtype=tf.float32)
transform = tf.matmul(net, weights)
transform = tf.nn.bias_add(transform, biases)
transform = tf.reshape(transform, [batch_size, K, K])
return transform
第一句到第七句,可以参考pointnet学习(八)tf_util.conv2d以及pointnet tf_util.max_pool2d
第七句reshape,输出为32,1024,
第八句,第九句,pointnet tf_util.fully_connected,本质是声明一个输入的1024维度与输出512,256,初始化一个1024,512的weight以及512,256的weight。得到fullyconnect的乘积tensor
最后经过weight256,K*K(K=64)以及bias的到feature的transformnet矩阵,为32个64*64的旋转矩阵。
同样保障了特征值的形状不变性。