Sparse basic block for PartA^2. Sparse basic block implemented with submanifold sparse convolution. Args: inplanes (int): inplanes of block. planes (int): planes of block. stride (int): stride of the first block. Default: 1 downsample (None | Module): down s
| 65 | |
| 66 | |
| 67 | class SparseBasicBlock(BasicBlock, spconv.SparseModule): |
| 68 | """Sparse basic block for PartA^2. |
| 69 | |
| 70 | Sparse basic block implemented with submanifold sparse convolution. |
| 71 | |
| 72 | Args: |
| 73 | inplanes (int): inplanes of block. |
| 74 | planes (int): planes of block. |
| 75 | stride (int): stride of the first block. Default: 1 |
| 76 | downsample (None | Module): down sample module for block. |
| 77 | conv_cfg (dict): dictionary to construct and config conv layer. |
| 78 | Default: None |
| 79 | norm_cfg (dict): dictionary to construct and config norm layer. |
| 80 | Default: dict(type='BN') |
| 81 | """ |
| 82 | |
| 83 | expansion = 1 |
| 84 | |
| 85 | def __init__(self, |
| 86 | inplanes, |
| 87 | planes, |
| 88 | stride=1, |
| 89 | downsample=None, |
| 90 | conv_cfg=None, |
| 91 | norm_cfg=None): |
| 92 | spconv.SparseModule.__init__(self) |
| 93 | BasicBlock.__init__( |
| 94 | self, |
| 95 | inplanes, |
| 96 | planes, |
| 97 | stride=stride, |
| 98 | downsample=downsample, |
| 99 | conv_cfg=conv_cfg, |
| 100 | norm_cfg=norm_cfg) |
| 101 | |
| 102 | def forward(self, x): |
| 103 | identity = x.features |
| 104 | |
| 105 | assert x.features.dim() == 2, f'x.features.dim()={x.features.dim()}' |
| 106 | |
| 107 | out = self.conv1(x) |
| 108 | out.features = self.norm1(out.features) |
| 109 | out.features = self.relu(out.features) |
| 110 | |
| 111 | out = self.conv2(out) |
| 112 | out.features = self.norm2(out.features) |
| 113 | |
| 114 | if self.downsample is not None: |
| 115 | identity = self.downsample(x) |
| 116 | |
| 117 | out.features += identity |
| 118 | out.features = self.relu(out.features) |
| 119 | |
| 120 | return out |
| 121 | |
| 122 | |
| 123 | def make_sparse_convmodule(in_channels, |
no outgoing calls