pointnet學習(八)tf_util.conv2d

pointnet學習(七)中input_transform_net函數,通過條用tf_util.conv2d構建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)
def 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,
           is_training=None):
  """ 2D convolution with non-linear operation.

  Args:
    inputs: 4-D tensor variable BxHxWxC
    num_output_channels: int
    kernel_size: a list of 2 ints
    scope: string
    stride: a list of 2 ints
    padding: 'SAME' or 'VALID'
    use_xavier: bool, use xavier_initializer if true
    stddev: float, stddev for truncated_normal init
    weight_decay: float
    activation_fn: function
    bn: bool, whether to use batch norm
    bn_decay: float or float tensor variable in [0,1]
    is_training: bool Tensor variable

  Returns:
    Variable tensor
  """
  with tf.variable_scope(scope) as sc:
      kernel_h, kernel_w = kernel_size
      num_in_channels = inputs.get_shape()[-1].value
      kernel_shape = [kernel_h, kernel_w,
                      num_in_channels, num_output_channels]
      kernel = _variable_with_weight_decay('weights',
                                           shape=kernel_shape,
                                           use_xavier=use_xavier,
                                           stddev=stddev,
                                           wd=weight_decay)
      stride_h, stride_w = stride
      outputs = tf.nn.conv2d(inputs, kernel,
                             [1, stride_h, stride_w, 1],
                             padding=padding)
      biases = _variable_on_cpu('biases', [num_output_channels],
                                tf.constant_initializer(0.0))
      outputs = tf.nn.bias_add(outputs, biases)

      if bn:
        outputs = batch_norm_for_conv2d(outputs, is_training,
                                        bn_decay=bn_decay, scope='bn')

      if activation_fn is not None:
        outputs = activation_fn(outputs)
      return outputs

tf.variable_scope(scope) as sc有點namespace的感覺,這裏的namespace是tconv1

kernel_h, kernel_w = kernel_size(1x3)
num_in_channels = inputs.get_shape()[-1].value=1,參考get_shape()[-1]
kernel_shape = [kernel_h, kernel_w,
                num_in_channels, num_output_channels]=[1,3,1,64]
kernel = _variable_with_weight_decay('weights',
                                     shape=kernel_shape,
                                     use_xavier=use_xavier,
                                     stddev=stddev,
                                     wd=weight_decay)作用是返回一個weight的tensor,shape是[1,3,1,64],目的是爲了保障不同layer的weight近乎相同.

參考_variable_with_weight_decay

stride_h, stride_w = stride卷積步幅,因爲是2d卷積,所以是h和w這裏設置各爲1
outputs = tf.nn.conv2d(inputs, kernel,
                       [1, stride_h, stride_w, 1],
                       padding=padding)

調用了tf.nn.conv2d進行卷積輸出outputs[32,1024,1,64]。具體參考tf.nn.conv2d

biases = _variable_on_cpu('biases', [num_output_channels],
                          tf.constant_initializer(0.0))

_variable_with_weight_decay相同,初始化一個輸出爲64的(第一層net)tensor名字爲biases

outputs = tf.nn.bias_add(outputs, biases)給output每個點的64channnels加上biases

bn爲true

outputs = batch_norm_for_conv2d(outputs, is_training,
                                bn_decay=bn_decay, scope='bn')參考pointnet batch_norm_for_conv2d

參考pointnet batch_norm_for_conv2d,輸出batch方向的歸一化tensor 

activation_fn=tf.nn.relu激活函數爲relu,現在的激活函數有更新的,可以上網搜索一下

指定激活函數,relu

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章