signed

QiShunwang

“诚信为本、客户至上”

spconv学习笔记

2021/5/14 20:36:03   来源:

SparseConvolution

__init__

输入:

  • ndim:kernel_size, stride等需要复制的维度
  • in_channels: weight输入维度
  • out_channels: weight输出维度
  • kernel_size, stride, padding, dilation, groups, bias与Conv2d定义相同
  • subm: bool, 有没有submanifold
  • output_padding: deconv是output需要padding的大小
  • transposed: 是不是反卷积
  • inverse:是不是inverse (这里不懂)
  • indice_key: 用在input.find_indice_pair中 (这里不懂)
  • fused_bn: 是否融合conv和bn
    初始化SparseConv的weight和bias
self.weight = Parameter(torch.Tensor(*kernel_size, in_channels, out_channels))
if bias:
	self.bias = Parameter(torch.Tensor(out_channels))

reset_parameters

tensor初始化

forward

输入input是SparseConvTensor

SparseConvTensor

调用方式:

"""
voxel_features (torch.float32): Voxel features in shape (N, C).
coors (torch.int32): Coordinates in shape (N, 4), \
		the columns in the order of (batch_idx, z_idx, y_idx, x_idx).
self.sparse_shape (list[int]): Teh sparse shape of input tensor.
batch_size (int): Batch size
"""
input_sp_tensor = spconv.SparseConvTensor(voxel_features, coors, self.sparse_shape, batch_size)

__init__

  • features: (N, C) e.g. voxel features
  • indices: coors (N, 4)
  • spatial_shape: sparse_shape e.g. [41, 160, 1408] in SECOND
  • batch_size: batch_size
  • grid: 当spatial shape特别大时,要pre-allocate grid tensor
  • indice_dict: 初始化空{}

spatial_size

返回spatials_shape各个元素累乘值

find_indice_pair(self, key)

这里用过
key不是None时,返回indice_dict[key]
indice_dict:

input.indice_dict[self.indice_key] = (outids, indices, indice_pairs, indice_pair_num, spatial_shape)

初始化时,outids, indice_pairs, indice_pair_num通过ops.get_indice_pairs得到

get_indice_pairs
  • indices: coors (N, 4) batch_idx, z_idx, y_idx, x_idx
  • batch_size, spatial_shape, ksize等与其他定义相同

当非子流形时,out_shape由get_deconv_output_size或get_conv_output_size求出。

  • get_conv_output_size:
    ** 输入:input_size=spatial_shape=sparse_shape e.g. [41, 160, 1408] in SECOND
    ** o u t p u t _ s i z e i = i n p u t _ s i z e i + 2 ∗ p i − d i ∗ ( k i − 1 ) − 1 s i + 1 output\_size_i=\frac{input\_size_i+2*p_i-d_i*(k_i-1)-1} {s_i}+1 output_sizei=siinput_sizei+2pidi(ki1)1+1
  • get_deconv_output_size
    ** o u t p u t _ s i z e i = ( i n p u t _ s i z e i − 1 ) ∗ s i − 2 ∗ p i + k i + o u t _ p i output\_size_i=(input\_size_i-1)*s_i-2*p_i+k_i+out\_p_i output_sizei=(input_sizei1)si2pi+ki+out_pi

当子流形时:output_shape=spatial_shape=sparse_shape
真正调用的是sparse_conv_ext.get_indice_pairs_grid_Nd或sparse_conv_ext.get_indice_pairs_Nd
getIndicePair:

ops.fused_indice_conv / fusedIndiceConvBatchNorm

输入:

  • features:提取的features 比如voxel_features
  • self.weight: (*k, cin, cout)
  • self.bias: (cout)
  • indice_pairs / indicePairs (这里不懂)
  • indice_pair_num / indiceNum (这里不懂)
  • outids.shape[0] / numActOut (这里不懂)

filters view成(-1, cin, cout)维度

  1. if subM: N*cin*cout+cout (对么)
  2. if not subM: