def block_inside(i, o, index, norm_cfg): mn = spconv.SparseSequential() reps = 2 mn.add(build_norm_layer(norm_cfg, i)[1]) mn.add(nn.ReLU()) mn.add(SubMConv3d(i, i, 3, indice_key="su3_{}".format(index), bias=False)) mn.add(build_norm_layer(norm_cfg, i)[1]) mn.add(nn.ReLU()) mn.add(SubMConv3d(i, o, 3, indice_key="su3_{}".format(index), bias=False)) # mn.add(build_norm_layer(norm_cfg, o)[1]) # mn.add(nn.ReLU()) return mn
def __init__(self, num_input_features=128, norm_cfg=None, name="SASpMiddleResNetFHD", **kwargs): super(SASpMiddleResNetFHD, self).__init__() self.name = name self.dcn = None self.zero_init_residual = False if norm_cfg is None: norm_cfg = dict(type="BN1d", eps=1e-3, momentum=0.01) # input: # [1600, 1200, 41] self.middle_conv1 = spconv.SparseSequential( SubMConv3d(num_input_features, 16, 3, bias=False, indice_key="res0"), build_norm_layer(norm_cfg, 16)[1], nn.ReLU(), SparseBasicBlock(16, 16, norm_cfg=norm_cfg, indice_key="res0"), SparseBasicBlock(16, 16, norm_cfg=norm_cfg, indice_key="res0"), SparseConv3d(16, 32, 3, 2, padding=1, bias=False), # [1600, 1200, 41] -> [800, 600, 21] build_norm_layer(norm_cfg, 32)[1], nn.ReLU(), SparseBasicBlock(32, 32, norm_cfg=norm_cfg, indice_key="res1"), SparseBasicBlock(32, 32, norm_cfg=norm_cfg, indice_key="res1"), ) self.middle_conv2 = spconv.SparseSequential( SparseConv3d(32, 64, 3, 2, padding=1, bias=False), # [800, 600, 21] -> [400, 300, 11] build_norm_layer(norm_cfg, 64)[1], nn.ReLU(), SparseBasicBlock(64, 64, norm_cfg=norm_cfg, indice_key="res2"), SparseBasicBlock(64, 64, norm_cfg=norm_cfg, indice_key="res2"), ) self.middle_conv3 = spconv.SparseSequential( SparseConv3d(64, 128, 3, 2, padding=[0, 1, 1], bias=False), # [400, 300, 11] -> [200, 150, 5] build_norm_layer(norm_cfg, 128)[1], nn.ReLU(), SparseBasicBlock(128, 128, norm_cfg=norm_cfg, indice_key="res3"), SparseBasicBlock(128, 128, norm_cfg=norm_cfg, indice_key="res3"), ) self.end_conv = spconv.SparseSequential( SparseConv3d(128, 128, (3, 1, 1), (2, 1, 1), bias=False), # [200, 150, 5] -> [200, 150, 2] build_norm_layer(norm_cfg, 128)[1], nn.ReLU(), ) self.point_fc = nn.Linear(224, 64, bias=False) self.point_cls = nn.Linear(64, 1, bias=False) self.point_reg = nn.Linear(64, 3, bias=False)
def __init__(self, num_input_features=128, norm_cfg=None, name="SpMiddleFHD", **kwargs): super(SpMiddleFHDNobn, self).__init__() self.name = name self.dcn = None self.zero_init_residual = False if norm_cfg is None: norm_cfg = dict(type="BN1d", eps=1e-3, momentum=0.01) self.middle_conv = spconv.SparseSequential( SubMConv3d(num_input_features, 16, 3, bias=True, indice_key="subm0"), # build_norm_layer(norm_cfg, 16)[1], nn.ReLU(), SubMConv3d(16, 16, 3, bias=True, indice_key="subm0"), # build_norm_layer(norm_cfg, 16)[1], nn.ReLU(), SparseConv3d(16, 32, 3, 2, padding=1, bias=True), # [1600, 1200, 41] -> [800, 600, 21] # build_norm_layer(norm_cfg, 32)[1], nn.ReLU(), SubMConv3d(32, 32, 3, indice_key="subm1", bias=True), # build_norm_layer(norm_cfg, 32)[1], nn.ReLU(), SubMConv3d(32, 32, 3, indice_key="subm1", bias=True), # build_norm_layer(norm_cfg, 32)[1], nn.ReLU(), SparseConv3d(32, 64, 3, 2, padding=1, bias=True), # [800, 600, 21] -> [400, 300, 11] # build_norm_layer(norm_cfg, 64)[1], nn.ReLU(), SubMConv3d(64, 64, 3, indice_key="subm2", bias=True), # build_norm_layer(norm_cfg, 64)[1], nn.ReLU(), SubMConv3d(64, 64, 3, indice_key="subm2", bias=True), # build_norm_layer(norm_cfg, 64)[1], nn.ReLU(), SubMConv3d(64, 64, 3, indice_key="subm2", bias=True), # build_norm_layer(norm_cfg, 64)[1], nn.ReLU(), SparseConv3d(64, 64, 3, 2, padding=[0, 1, 1], bias=True), # [400, 300, 11] -> [200, 150, 5] # build_norm_layer(norm_cfg, 64)[1], nn.ReLU(), SubMConv3d(64, 64, 3, indice_key="subm3", bias=True), # build_norm_layer(norm_cfg, 64)[1], nn.ReLU(), SubMConv3d(64, 64, 3, indice_key="subm3", bias=True), # build_norm_layer(norm_cfg, 64)[1], nn.ReLU(), SubMConv3d(64, 64, 3, indice_key="subm3", bias=True), # build_norm_layer(norm_cfg, 64)[1], nn.ReLU(), SparseConv3d(64, 64, (3, 1, 1), (2, 1, 1), bias=True), # [200, 150, 5] -> [200, 150, 2] # build_norm_layer(norm_cfg, 64)[1], nn.ReLU(), )
def __init__(self, num_input_features=128, norm_cfg=None, name="SpMiddleFHD", **kwargs): super(SpMiddleFHD, self).__init__() self.name = name self.dcn = None self.zero_init_residual = False if norm_cfg is None: norm_cfg = dict(type="BN1d", eps=1e-3, momentum=0.01) self.middle_conv = spconv.SparseSequential( SubMConv3d(num_input_features, 16, 3, bias=False, indice_key="subm0"), build_norm_layer(norm_cfg, 16)[1], nn.ReLU(), SubMConv3d(16, 16, 3, bias=False, indice_key="subm0"), build_norm_layer(norm_cfg, 16)[1], nn.ReLU(), SparseConv3d(16, 32, 3, 2, padding=1, bias=False), # [41, 1600, 1408] -> [21, 800, 704] build_norm_layer(norm_cfg, 32)[1], nn.ReLU(), SubMConv3d(32, 32, 3, indice_key="subm1", bias=False), build_norm_layer(norm_cfg, 32)[1], nn.ReLU(), SubMConv3d(32, 32, 3, indice_key="subm1", bias=False), build_norm_layer(norm_cfg, 32)[1], nn.ReLU(), SparseConv3d(32, 64, 3, 2, padding=1, bias=False), # [21, 800, 704] -> [11, 400, 352] build_norm_layer(norm_cfg, 64)[1], nn.ReLU(), SubMConv3d(64, 64, 3, indice_key="subm2", bias=False), build_norm_layer(norm_cfg, 64)[1], nn.ReLU(), SubMConv3d(64, 64, 3, indice_key="subm2", bias=False), build_norm_layer(norm_cfg, 64)[1], nn.ReLU(), SubMConv3d(64, 64, 3, indice_key="subm2", bias=False), build_norm_layer(norm_cfg, 64)[1], nn.ReLU(), SparseConv3d(64, 64, 3, 2, padding=[0, 1, 1], bias=False), # [11, 400, 352] -> [5, 200, 176] build_norm_layer(norm_cfg, 64)[1], nn.ReLU(), SubMConv3d(64, 64, 3, indice_key="subm3", bias=False), build_norm_layer(norm_cfg, 64)[1], nn.ReLU(), SubMConv3d(64, 64, 3, indice_key="subm3", bias=False), build_norm_layer(norm_cfg, 64)[1], nn.ReLU(), SubMConv3d(64, 64, 3, indice_key="subm3", bias=False), build_norm_layer(norm_cfg, 64)[1], nn.ReLU(), SparseConv3d(64, 64, (3, 1, 1), (2, 1, 1), bias=False), # [5, 200, 176] -> [2, 200, 176] build_norm_layer(norm_cfg, 64)[1], nn.ReLU(), )
def __init__(self, num_input_features=128, norm_cfg=None, name="RCNNSpMiddleFHD", **kwargs): super(RCNNSpMiddleFHD, self).__init__() self.name = name self.dcn = None self.zero_init_residual = False if norm_cfg is None: norm_cfg = dict(type="BN1d", eps=1e-3, momentum=0.01) self.middle_conv = spconv.SparseSequential( SubMConv3d(num_input_features, 16, 3, bias=False, indice_key="subm0"), build_norm_layer(norm_cfg, 16)[1], nn.ReLU(), SubMConv3d(16, 16, 3, bias=False, indice_key="subm0"), build_norm_layer(norm_cfg, 16)[1], nn.ReLU(), SparseConv3d(16, 32, 3, 2, padding=1, bias=False), # [32, 80, 41] -> [16, 40, 21] build_norm_layer(norm_cfg, 32)[1], nn.ReLU(), SubMConv3d(32, 32, 3, bias=False, indice_key="subm1"), build_norm_layer(norm_cfg, 32)[1], nn.ReLU(), # SubMConv3d(32, 32, 3, bias=False, indice_key="subm1"), # build_norm_layer(norm_cfg, 32)[1], # nn.ReLU(), SparseConv3d(32, 64, 3, 2, bias=False, padding=1), # [16, 40, 21] -> [8, 20, 11] build_norm_layer(norm_cfg, 64)[1], nn.ReLU(), SubMConv3d(64, 64, 3, bias=False, indice_key="subm2"), build_norm_layer(norm_cfg, 64)[1], nn.ReLU(), # SubMConv3d(64, 64, 3, bias=False, indice_key="subm2"), # build_norm_layer(norm_cfg, 64)[1], # nn.ReLU(), # SubMConv3d(64, 64, 3, bias=False, indice_key="subm2"), # build_norm_layer(norm_cfg, 64)[1], # nn.ReLU(), SparseConv3d(64, 64, 3, 2, bias=False, padding=[1, 1, 0]), # [8, 20, 11] -> [4, 10, 5] build_norm_layer(norm_cfg, 64)[1], nn.ReLU(), SubMConv3d(64, 64, 3, bias=False, indice_key="subm3"), build_norm_layer(norm_cfg, 64)[1], nn.ReLU(), # SubMConv3d(64, 64, 3, bias=False, indice_key="subm3"), # build_norm_layer(norm_cfg, 64)[1], # nn.ReLU(), # SubMConv3d(64, 64, 3, bias=False, indice_key="subm3"), # build_norm_layer(norm_cfg, 64)[1], # nn.ReLU(), SparseConv3d(64, 64, (1, 1, 3), (1, 1, 2), bias=False), # [4, 10, 5] -> [4, 10, 2] build_norm_layer(norm_cfg, 64)[1], nn.ReLU(), )
def __init__(self, num_input_features=128, norm_cfg=None, name="SpMiddleResNetFHD", n_channels=[16, 32, 64, 128], **kwargs): super(SpMiddleResNetFHDv2, self).__init__() self.name = name self.dcn = None self.zero_init_residual = False if norm_cfg is None: norm_cfg = dict(type="BN1d", eps=1e-3, momentum=0.01) # input: # [1024, 1024, 56] self.middle_conv = spconv.SparseSequential( SubMConv3d(num_input_features, n_channels[0], 3, bias=False, indice_key="res0"), build_norm_layer(norm_cfg, n_channels[0])[1], nn.ReLU(), SparseBasicBlock(n_channels[0], n_channels[0], norm_cfg=norm_cfg, indice_key="res0"), SparseBasicBlock(n_channels[0], n_channels[0], norm_cfg=norm_cfg, indice_key="res0"), SparseConv3d(n_channels[0], n_channels[1], 3, 2, padding=1, bias=False), # [1024, 1024, 56] -> [512, 512, 28] build_norm_layer(norm_cfg, n_channels[1])[1], nn.ReLU(), SparseBasicBlock(n_channels[1], n_channels[1], norm_cfg=norm_cfg, indice_key="res1"), SparseBasicBlock(n_channels[1], n_channels[1], norm_cfg=norm_cfg, indice_key="res1"), # SparseBasicBlock(n_channels[1], n_channels[1], norm_cfg=norm_cfg, indice_key="res1"), SparseConv3d(n_channels[1], n_channels[2], 3, 2, padding=1, bias=False), # [512, 512, 28] -> [256, 256, 14] build_norm_layer(norm_cfg, n_channels[2])[1], nn.ReLU(), SparseBasicBlock(n_channels[2], n_channels[2], norm_cfg=norm_cfg, indice_key="res2"), SparseBasicBlock(n_channels[2], n_channels[2], norm_cfg=norm_cfg, indice_key="res2"), # SparseBasicBlock(n_channels[2], n_channels[2], norm_cfg=norm_cfg, indice_key="res2"), SparseConv3d(n_channels[2], n_channels[3], 3, 2, padding=1, bias=False), # [256, 256, 14] -> [128, 128, 7] build_norm_layer(norm_cfg, n_channels[3])[1], nn.ReLU(), SparseBasicBlock(n_channels[3], n_channels[3], norm_cfg=norm_cfg, indice_key="res3"), SparseBasicBlock(n_channels[3], n_channels[3], norm_cfg=norm_cfg, indice_key="res3"), # SparseBasicBlock(n_channels[3], n_channels[3], norm_cfg=norm_cfg, indice_key="res3"), SparseConv3d(n_channels[3], n_channels[3], (3, 1, 1), (2, 1, 1), bias=False), # [128, 128, 7] -> [64, 64, 3] build_norm_layer(norm_cfg, n_channels[3])[1], nn.ReLU(), )
def __init__(self, num_input_features=128, num_filters_down=[16, 32, 64, 64, 96, 128], dimension_feature_map=[128, 128, 128, 128], norm_cfg=None, name="tDBN_2", **kwargs): super(tDBN_2_bv, self).__init__() self.name = name self.dcn = None self.zero_init_residual = False if norm_cfg is None: norm_cfg = dict(type="BN1d", eps=1e-3, momentum=0.01) middle_layers = spconv.SparseSequential() input_filters_layers = num_filters_down[: 4] # feature channels in the raw data num_filter_fpn = num_filters_down[-4:] dimension_feature_map = dimension_feature_map dimension_kernel_size = [15, 7, 3, 1] # the main network framework self.block_input = spconv.SparseSequential( SubMConv3d(num_input_features, 16, 3, bias=True, indice_key="subm0"), # build_norm_layer(norm_cfg, 16)[1], nn.ReLU(), SubMConv3d(16, 16, 3, bias=True, indice_key="subm0"), # build_norm_layer(norm_cfg, 16)[1], nn.ReLU(), SparseConv3d(16, 32, 3, 2, padding=1, bias=True), # [1600, 1200, 41] -> [800, 600, 21] # build_norm_layer(norm_cfg, 32)[1], nn.ReLU(), SubMConv3d(32, 32, 3, indice_key="subm1", bias=True), # build_norm_layer(norm_cfg, 32)[1], nn.ReLU(), SubMConv3d(32, 32, 3, indice_key="subm1", bias=True), # build_norm_layer(norm_cfg, 32)[1], nn.ReLU(), SparseConv3d(32, 64, 3, 2, padding=[0, 2, 2], bias=True), # [800, 600, 21] -> [400, 300, 11] # build_norm_layer(norm_cfg, 64)[1], nn.ReLU(), # SubMConv3d(64, 64, 3, indice_key="subm2", bias=True), # # build_norm_layer(norm_cfg, 64)[1], # nn.ReLU(), # SubMConv3d(64, 64, 3, indice_key="subm2", bias=True), # # build_norm_layer(norm_cfg, 64)[1], # nn.ReLU(), # SubMConv3d(64, 64, 3, indice_key="subm2", bias=True), # # build_norm_layer(norm_cfg, 64)[1], # nn.ReLU(), ) # self.block0 = middle_layers m = spconv.SparseSequential() reps = 2 # residual_use = False # using residual block or not residual_use = True # using residual block or not _index = 0 for _ in range(reps): block(m, num_filter_fpn[0], num_filter_fpn[0], index=_index, residual_blocks=residual_use, norm_cfg=norm_cfg) self.x0_in = m for k in range(1, 4): m = spconv.SparseSequential() m.add( SparseConv3d(num_filter_fpn[k - 1], num_filter_fpn[k], 3, stride=2, bias=False, indice_key="conv{}".format(k))) m.add(build_norm_layer(norm_cfg, num_filter_fpn[k])[1]) m.add(nn.ReLU()) for _ in range(reps): if k == 4: block(m, num_filter_fpn[k], num_filter_fpn[k], index=k, dimension=2, residual_blocks=residual_use, norm_cfg=norm_cfg) else: block(m, num_filter_fpn[k], num_filter_fpn[k], index=k, dimension=3, residual_blocks=residual_use, norm_cfg=norm_cfg) if k == 1: self.x1_in = m elif k == 2: self.x2_in = m elif k == 3: self.x3_in = m for k in range(2, -1, -1): m = spconv.SparseSequential() m.add( SparseInverseConv3d(num_filter_fpn[k + 1], num_filter_fpn[k], 3, "conv{}".format(k + 1), bias=False) # no stride inputs ) m.add(build_norm_layer(norm_cfg, num_filter_fpn[k])[1]) m.add(nn.ReLU()) if k == 2: self.upsample32 = m elif k == 1: self.upsample21 = m elif k == 0: self.upsample10 = m m = spconv.SparseSequential() m.add(JoinTable()) for i in range(reps): block(m, num_filter_fpn[k] * (2 if i == 0 else 1), num_filter_fpn[k], index=(k + 100), residual_blocks=residual_use, norm_cfg=norm_cfg) if k == 2: self.concate2 = m elif k == 1: self.concate1 = m elif k == 0: self.concate0 = m m = spconv.SparseSequential() m.add( SparseConv3d(num_filter_fpn[k], dimension_feature_map[k], (dimension_kernel_size[k], 1, 1), (2, 1, 1), bias=False)) m.add(build_norm_layer(norm_cfg, dimension_feature_map[k])[1]) m.add(nn.ReLU()) if k == 2: self.feature_map2 = m elif k == 1: self.feature_map1 = m elif k == 0: self.feature_map0 = m
def __init__(self, num_input_features=4, num_filters_down=[16, 32, 64, 64, 96, 128], dimension_feature_map=[128, 128, 128, 128], norm_cfg=None, name="tDBN_1", **kwargs): super(tDBN_1_bv, self).__init__() self.name = name self.dcn = None self.zero_init_residual = False if norm_cfg is None: norm_cfg = dict(type="BN1d", eps=1e-3, momentum=0.01) middle_layers = spconv.SparseSequential() input_filters_layers = num_filters_down[: 4] # feature channels in the raw data num_filter_fpn = num_filters_down[-4:] dimension_feature_map = dimension_feature_map dimension_kernel_size = [15, 7, 3, 1] self.block0 = spconv.SparseSequential( SubMConv3d(num_input_features, 16, 3, bias=True, indice_key="subm0"), # build_norm_layer(norm_cfg, 16)[1], nn.ReLU(), SubMConv3d(16, 16, 3, bias=True, indice_key="subm0"), # build_norm_layer(norm_cfg, 16)[1], nn.ReLU(), SparseConv3d(16, 32, 3, 2, padding=1, bias=True), # [1600, 1200, 41] -> [800, 600, 21] # build_norm_layer(norm_cfg, 32)[1], nn.ReLU(), SubMConv3d(32, 32, 3, indice_key="subm1", bias=True), # build_norm_layer(norm_cfg, 32)[1], nn.ReLU(), SubMConv3d(32, 32, 3, indice_key="subm1", bias=True), # build_norm_layer(norm_cfg, 32)[1], nn.ReLU(), SparseConv3d(32, 64, 3, 2, padding=[0, 2, 2], bias=True), # [800, 600, 21] -> [400, 300, 11] # build_norm_layer(norm_cfg, 64)[1], nn.ReLU(), SubMConv3d(64, 64, 3, indice_key="subm2", bias=True), # build_norm_layer(norm_cfg, 64)[1], nn.ReLU(), SubMConv3d(64, 64, 3, indice_key="subm2", bias=True), # build_norm_layer(norm_cfg, 64)[1], nn.ReLU(), SubMConv3d(64, 64, 3, indice_key="subm2", bias=True), # build_norm_layer(norm_cfg, 64)[1], nn.ReLU(), ) # self.block0 = middle_layers m = spconv.SparseSequential() m.add( SparseConv3d(num_filter_fpn[0], dimension_feature_map[0], (dimension_kernel_size[0], 1, 1), (2, 1, 1), bias=False)) m.add(build_norm_layer(norm_cfg, dimension_feature_map[0])[1]) m.add(nn.ReLU()) # dense function add later self.feature_map0 = m reps = 2 residual_use = True # using residual block or not m = spconv.SparseSequential() ## block1-3 and feature map1-3 for k in range(1, 4): m.add( SparseConv3d(num_filter_fpn[k - 1], num_filter_fpn[k], 3, 2, bias=False)) m.add(build_norm_layer(norm_cfg, num_filter_fpn[k])[1]) m.add(nn.ReLU()) # dense function add later for _ in range(reps): block(m, num_filter_fpn[k], num_filter_fpn[k], index=k, residual_blocks=residual_use, norm_cfg=norm_cfg) if k == 1: self.block1 = m elif k == 2: self.block2 = m elif k == 3: self.block3 = m m = spconv.SparseSequential() m.add( SparseConv3d(num_filter_fpn[k], dimension_feature_map[k], (dimension_kernel_size[k], 1, 1), (2, 1, 1), bias=False)) m.add(build_norm_layer(norm_cfg, dimension_feature_map[k])[1]) m.add(nn.ReLU()) # adding dense in forward step if k == 1: self.feature_map1 = m elif k == 2: self.feature_map2 = m elif k == 3: self.feature_map3 = None # convert the sparse data into dense one # Sequential(scn.SparseToDense(3, dimension_feature_map[k])) ## last one is the 2D instead of 3D m = spconv.SparseSequential()
def __init__(self, num_input_features=128, norm_cfg=None, name="tDBN_2", **kwargs): super(tDBN_2, self).__init__() self.name = name self.dcn = None self.zero_init_residual = False if norm_cfg is None: norm_cfg = dict(type="BN1d", eps=1e-3, momentum=0.01) middle_layers = spconv.SparseSequential() num_filter_fpn = [32, 64, 96, 128] dimension_feature_map = [128, 128, 128, 128] dimension_kernel_size = [15, 7, 3, 1] # the main network framework m = spconv.SparseSequential() # -------------------------------------- ## block1 and feature map 0, convert from voxel into 3D tensor # -------------------------------------- for i, o in [[num_input_features, num_filter_fpn[0]] ]: # , [num_filter_fpn[0], num_filter_fpn[0]]]: m.add(SubMConv3d(i, o, 3, indice_key="subm_0", bias=False)) m.add(build_norm_layer(norm_cfg, o)[1]) m.add(nn.ReLU()) self.block_input = m m = spconv.SparseSequential() reps = 2 # residual_use = False # using residual block or not residual_use = True # using residual block or not _index = 0 for _ in range(reps): block(m, num_filter_fpn[0], num_filter_fpn[0], index=_index, residual_blocks=residual_use, norm_cfg=norm_cfg) self.x0_in = m for k in range(1, 4): m = spconv.SparseSequential() m.add( SparseConv3d(num_filter_fpn[k - 1], num_filter_fpn[k], 3, stride=2, bias=False, indice_key="conv{}".format(k))) m.add(build_norm_layer(norm_cfg, num_filter_fpn[k])[1]) m.add(nn.ReLU()) for _ in range(reps): if k == 4: block(m, num_filter_fpn[k], num_filter_fpn[k], index=k, dimension=2, residual_blocks=residual_use, norm_cfg=norm_cfg) else: block(m, num_filter_fpn[k], num_filter_fpn[k], index=k, dimension=3, residual_blocks=residual_use, norm_cfg=norm_cfg) if k == 1: self.x1_in = m elif k == 2: self.x2_in = m elif k == 3: self.x3_in = m for k in range(2, -1, -1): m = spconv.SparseSequential() m.add( SparseInverseConv3d(num_filter_fpn[k + 1], num_filter_fpn[k], 3, "conv{}".format(k + 1), bias=False) # no stride inputs ) m.add(build_norm_layer(norm_cfg, num_filter_fpn[k])[1]) m.add(nn.ReLU()) if k == 2: self.upsample32 = m elif k == 1: self.upsample21 = m elif k == 0: self.upsample10 = m m = spconv.SparseSequential() m.add(JoinTable()) for i in range(reps): block(m, num_filter_fpn[k] * (2 if i == 0 else 1), num_filter_fpn[k], index=(k + 100), residual_blocks=residual_use, norm_cfg=norm_cfg) if k == 2: self.concate2 = m elif k == 1: self.concate1 = m elif k == 0: self.concate0 = m m = spconv.SparseSequential() m.add( SparseConv3d(num_filter_fpn[k], dimension_feature_map[k], (dimension_kernel_size[k], 1, 1), (2, 1, 1), bias=False)) m.add(build_norm_layer(norm_cfg, dimension_feature_map[k])[1]) m.add(nn.ReLU()) if k == 2: self.feature_map2 = m elif k == 1: self.feature_map1 = m elif k == 0: self.feature_map0 = m
def __init__(self, num_input_features=128, norm_cfg=None, name="tDBN_1", **kwargs): super(tDBN_1, self).__init__() self.name = name self.dcn = None self.zero_init_residual = False if norm_cfg is None: norm_cfg = dict(type="BN1d", eps=1e-3, momentum=0.01) middle_layers = spconv.SparseSequential() num_filter_fpn = [32, 64, 96, 128] dimension_feature_map = [128, 128, 128, 128] dimension_kernel_size = [15, 7, 3, 1] for i, o in [[num_input_features, num_filter_fpn[0]]]: middle_layers.add( SubMConv3d(i, o, 3, indice_key="subm_0", bias=False)) middle_layers.add(build_norm_layer(norm_cfg, o)[1]) middle_layers.add(nn.ReLU()) self.block0 = middle_layers middle_layers = spconv.SparseSequential() middle_layers.add( SparseConv3d(num_filter_fpn[0], dimension_feature_map[0], (dimension_kernel_size[0], 1, 1), (2, 1, 1), bias=False)) middle_layers.add( build_norm_layer(norm_cfg, dimension_feature_map[0])[1]) middle_layers.add(nn.ReLU()) # dense function add later self.feature_map0 = middle_layers reps = 2 residual_use = True middle_layers = spconv.SparseSequential() ## block1-3 and feature map1-3 for k in range(1, 4): if k == 3: middle_layers.add( SparseConv3d(num_filter_fpn[k - 1], num_filter_fpn[k], 3, 2, bias=False)) middle_layers.add( build_norm_layer(norm_cfg, num_filter_fpn[k])[1]) middle_layers.add(nn.ReLU()) # dense function add later else: middle_layers.add( SparseConv3d(num_filter_fpn[k - 1], num_filter_fpn[k], 3, 2, bias=False)) middle_layers.add( build_norm_layer(norm_cfg, num_filter_fpn[k])[1]) middle_layers.add(nn.ReLU()) # 128*7*199*175 recurrent for _ in range(reps): block(middle_layers, num_filter_fpn[k], num_filter_fpn[k], index=k, residual_blocks=residual_use, norm_cfg=norm_cfg) if k == 1: self.block1 = middle_layers elif k == 2: self.block2 = middle_layers elif k == 3: self.block3 = middle_layers middle_layers = spconv.SparseSequential() middle_layers.add( SparseConv3d(num_filter_fpn[k], dimension_feature_map[k], (dimension_kernel_size[k], 1, 1), (2, 1, 1), bias=False)) middle_layers.add( build_norm_layer(norm_cfg, dimension_feature_map[k])[1]) middle_layers.add(nn.ReLU()) # adding dense in forward step if k == 1: self.feature_map1 = middle_layers elif k == 2: self.feature_map2 = middle_layers elif k == 3: self.feature_map3 = None # convert the sparse data into dense one # Sequential(scn.SparseToDense(3, dimension_feature_map[k])) ## last one is the 2D instead of 3D middle_layers = spconv.SparseSequential()
def block(m, i, o, dimension=3, index=0, residual_blocks=False, norm_cfg=None): # default using residual_block if dimension == 3: ## 3x3x3 convlution if residual_blocks: #ResNet style blocks m.add( SubMConv3d(i, o, 3, indice_key="su3_{}".format(index), bias=False)) m.add(ConcatTable().add(Identity()).add( block_inside(o, o, index, norm_cfg))) m.add(AddTable()) #m.add(SubMConv3d(2*o, o, 3, indice_key="su3_{}".format(index), bias = False)) m.add(build_norm_layer(norm_cfg, o)[1]) m.add(nn.ReLU()) else: m.add( SubMConv3d(i, i, 3, indice_key="su3_{}".format(index), bias=False)) m.add(build_norm_layer(norm_cfg, i)[1]) m.add(nn.ReLU()) m.add( SubMConv3d(i, o, 3, indice_key="su3_{}".format(index), bias=False)) m.add(build_norm_layer(norm_cfg, o)[1]) m.add(nn.ReLU()) else: # 2x2x2 convoltion if residual_blocks: #ResNet style blocks m.add(ConcatTable().add(Identity()).add( SubMConv2d(i, o, 3, indice_key="su2_{}".format(index), bias=False)).add(build_norm_layer( norm_cfg, o)[1]).add(nn.ReLU()).add( SubMConv2d( i, o, 3, indice_key="su2_{}".format(index), bias=False)).add( build_norm_layer( norm_cfg, o)[1]).add( nn.ReLU())).add(AddTable()) else: m.add(spconv.SparseSequential().add( SubMConv2d(i, o, 3, indice_key="su2_{}".format(index), bias=False)).add(build_norm_layer( norm_cfg, o)[1]).add(nn.ReLU()).add( SubMConv2d( i, o, 3, indice_key="su2_{}".format(index), bias=False)).add( build_norm_layer( norm_cfg, o)[1]).add(nn.ReLU()))