def __init__(self,
              num_input_features=4,
              use_norm=True,
              num_filters=[32, 128],
              with_distance=False,
              name='VoxelFeatureExtractor'):
     super(VoxelFeatureExtractor, self).__init__()
     self.name = name
     if use_norm:
         BatchNorm1d = change_default_args(eps=1e-3,
                                           momentum=0.01)(nn.BatchNorm1d)
         Linear = change_default_args(bias=False)(nn.Linear)
     else:
         BatchNorm1d = Empty
         Linear = change_default_args(bias=True)(nn.Linear)
     assert len(num_filters) == 2
     num_input_features += 3  # add mean features
     if with_distance:
         num_input_features += 1
     self._with_distance = with_distance
     self.vfe1 = VFELayer(num_input_features, num_filters[0], use_norm)
     self.vfe2 = VFELayer(num_filters[0], num_filters[1], use_norm)
     self.linear = Linear(num_filters[1], num_filters[1])
     # var_torch_init(self.linear.weight)
     # var_torch_init(self.linear.bias)
     self.norm = BatchNorm1d(num_filters[1])
    def __init__(self,
                 num_input_features=4,
                 use_norm=True,
                 num_filters=[32, 128],
                 with_distance=False,
                 name='VoxelFeatureExtractor'):
        super(VoxelFeatureExtractorV2, self).__init__()
        self.name = name
        if use_norm:
            BatchNorm1d = change_default_args(eps=1e-3,
                                              momentum=0.01)(nn.BatchNorm1d)
            Linear = change_default_args(bias=False)(nn.Linear)
        else:
            BatchNorm1d = Empty
            Linear = change_default_args(bias=True)(nn.Linear)
        assert len(num_filters) > 0
        num_input_features += 3
        if with_distance:
            num_input_features += 1
        self._with_distance = with_distance

        num_filters = [num_input_features] + num_filters
        filters_pairs = [[num_filters[i], num_filters[i + 1]]
                         for i in range(len(num_filters) - 1)]
        self.vfe_layers = nn.ModuleList(
            [VFELayer(i, o, use_norm) for i, o in filters_pairs])
        self.linear = Linear(num_filters[-1], num_filters[-1])
        # var_torch_init(self.linear.weight)
        # var_torch_init(self.linear.bias)
        self.norm = BatchNorm1d(num_filters[-1])
 def __init__(self, in_channels, out_channels, use_norm=True, name='vfe'):
     super(VFELayer, self).__init__()
     self.name = name
     self.units = int(out_channels / 2)
     if use_norm:
         BatchNorm1d = change_default_args(eps=1e-3,
                                           momentum=0.01)(nn.BatchNorm1d)
         Linear = change_default_args(bias=False)(nn.Linear)
     else:
         BatchNorm1d = Empty
         Linear = change_default_args(bias=True)(nn.Linear)
     self.linear = Linear(in_channels, self.units)
     self.norm = BatchNorm1d(self.units)
Beispiel #4
0
    def _make_layer(self, inplanes, planes, num_blocks, stride=1):
        if self._use_norm:
            if self._use_groupnorm:
                BatchNorm2d = change_default_args(num_groups=self._num_groups,
                                                  eps=1e-3)(GroupNorm)
            else:
                BatchNorm2d = change_default_args(eps=1e-3, momentum=0.01)(
                    nn.BatchNorm2d)
            Conv2d = change_default_args(bias=False)(nn.Conv2d)
            ConvTranspose2d = change_default_args(bias=False)(
                nn.ConvTranspose2d)
        else:
            BatchNorm2d = Empty
            Conv2d = change_default_args(bias=True)(nn.Conv2d)
            ConvTranspose2d = change_default_args(bias=True)(
                nn.ConvTranspose2d)

        block = Sequential(
            nn.ZeroPad2d(1),
            Conv2d(inplanes, planes, 3, stride=stride),
            BatchNorm2d(planes),
            nn.ReLU(),
        )
        for j in range(num_blocks):
            block.add(Conv2d(planes, planes, 3, padding=1))
            block.add(BatchNorm2d(planes))
            block.add(nn.ReLU())

        return block, planes
Beispiel #5
0
    def __init__(self,
                 use_norm=True,
                 num_class=2,
                 layer_nums=(3, 5, 5),
                 layer_strides=(2, 2, 2),
                 num_filters=(128, 128, 256),
                 upsample_strides=(1, 2, 4),
                 num_upsample_filters=(256, 256, 256),
                 num_input_features=128,
                 num_anchor_per_loc=2,
                 encode_background_as_zeros=True,
                 use_direction_classifier=True,
                 use_groupnorm=False,
                 num_groups=32,
                 use_bev=False,
                 box_code_size=7,
                 use_rc_net=False,
                 name='rpn'):
        super(RPNBase, self).__init__()
        self._num_anchor_per_loc = num_anchor_per_loc
        self._use_direction_classifier = use_direction_classifier
        self._use_bev = use_bev
        self._use_rc_net = use_rc_net

        self._layer_strides = layer_strides
        self._num_filters = num_filters
        self._layer_nums = layer_nums
        self._upsample_strides = upsample_strides
        self._num_upsample_filters = num_upsample_filters
        self._num_input_features = num_input_features
        self._use_norm = use_norm
        self._use_groupnorm = use_groupnorm
        self._num_groups = num_groups
        assert len(layer_strides) == len(layer_nums)
        assert len(num_filters) == len(layer_nums)
        assert len(num_upsample_filters) == len(upsample_strides)
        self._upsample_start_idx = len(layer_nums) - len(upsample_strides)
        must_equal_list = []
        for i in range(len(upsample_strides)):
            must_equal_list.append(upsample_strides[i] /
                                   layer_strides[i + self._upsample_start_idx])
        for val in must_equal_list:
            assert val == must_equal_list[0]

        if use_norm:
            if use_groupnorm:
                BatchNorm2d = change_default_args(num_groups=num_groups,
                                                  eps=1e-3)(GroupNorm)
            else:
                BatchNorm2d = change_default_args(eps=1e-3, momentum=0.01)(
                    nn.BatchNorm2d)
            Conv2d = change_default_args(bias=False)(nn.Conv2d)
            ConvTranspose2d = change_default_args(bias=False)(
                nn.ConvTranspose2d)
        else:
            BatchNorm2d = Empty
            Conv2d = change_default_args(bias=True)(nn.Conv2d)
            ConvTranspose2d = change_default_args(bias=True)(
                nn.ConvTranspose2d)

        in_filters = [num_input_features, *num_filters[:-1]]
        blocks = []
        deblocks = []

        for i, layer_num in enumerate(layer_nums):
            block, num_out_filters = self._make_layer(in_filters[i],
                                                      num_filters[i],
                                                      layer_num,
                                                      stride=layer_strides[i])
            blocks.append(block)
            if i - self._upsample_start_idx >= 0:
                deblock = nn.Sequential(
                    ConvTranspose2d(
                        num_out_filters,
                        num_upsample_filters[i - self._upsample_start_idx],
                        upsample_strides[i - self._upsample_start_idx],
                        stride=upsample_strides[i - self._upsample_start_idx]),
                    BatchNorm2d(
                        num_upsample_filters[i - self._upsample_start_idx]),
                    nn.ReLU(),
                )
                deblocks.append(deblock)
        self.blocks = nn.ModuleList(blocks)
        self.deblocks = nn.ModuleList(deblocks)

        if encode_background_as_zeros:
            num_cls = num_anchor_per_loc * num_class
        else:
            num_cls = num_anchor_per_loc * (num_class + 1)
        if len(num_upsample_filters) == 0:
            final_num_filters = num_out_filters
        else:
            final_num_filters = sum(num_upsample_filters)
        self.conv_cls = nn.Conv2d(final_num_filters, num_cls, 1)
        self.conv_box = nn.Conv2d(final_num_filters,
                                  num_anchor_per_loc * box_code_size, 1)
        if use_direction_classifier:
            self.conv_dir_cls = nn.Conv2d(final_num_filters,
                                          num_anchor_per_loc * 2, 1)
Beispiel #6
0
 def __init__(self,
              output_shape,
              use_norm=True,
              num_input_features=128,
              num_filters_down1=[64],
              num_filters_down2=[64, 64],
              name='SpMiddleFHD'):
     super(SpMiddleFHD, self).__init__()
     self.name = name
     if use_norm:
         BatchNorm2d = change_default_args(eps=1e-3,
                                           momentum=0.01)(nn.BatchNorm2d)
         BatchNorm1d = change_default_args(eps=1e-3,
                                           momentum=0.01)(nn.BatchNorm1d)
         Conv2d = change_default_args(bias=False)(nn.Conv2d)
         SpConv3d = change_default_args(bias=False)(spconv.SparseConv3d)
         SubMConv3d = change_default_args(bias=False)(spconv.SubMConv3d)
         ConvTranspose2d = change_default_args(bias=False)(
             nn.ConvTranspose2d)
     else:
         BatchNorm2d = Empty
         BatchNorm1d = Empty
         Conv2d = change_default_args(bias=True)(nn.Conv2d)
         SpConv3d = change_default_args(bias=True)(spconv.SparseConv3d)
         SubMConv3d = change_default_args(bias=True)(spconv.SubMConv3d)
         ConvTranspose2d = change_default_args(bias=True)(
             nn.ConvTranspose2d)
     sparse_shape = np.array(output_shape[1:4]) + [1, 0, 0]
     # sparse_shape[0] = 11
     # print(sparse_shape)
     self.sparse_shape = sparse_shape
     self.voxel_output_shape = output_shape
     # input: # [1600, 1200, 41]
     self.middle_conv = spconv.SparseSequential(
         SubMConv3d(num_input_features, 16, 3, indice_key="subm0"),
         BatchNorm1d(16),
         nn.ReLU(),
         SubMConv3d(16, 16, 3, indice_key="subm0"),
         BatchNorm1d(16),
         nn.ReLU(),
         SpConv3d(16, 32, 3, 2,
                  padding=1),  # [1600, 1200, 41] -> [800, 600, 21]
         BatchNorm1d(32),
         nn.ReLU(),
         SubMConv3d(32, 32, 3, indice_key="subm1"),
         BatchNorm1d(32),
         nn.ReLU(),
         SubMConv3d(32, 32, 3, indice_key="subm1"),
         BatchNorm1d(32),
         nn.ReLU(),
         SpConv3d(32, 64, 3, 2,
                  padding=1),  # [800, 600, 21] -> [400, 300, 11]
         BatchNorm1d(64),
         nn.ReLU(),
         SubMConv3d(64, 64, 3, indice_key="subm2"),
         BatchNorm1d(64),
         nn.ReLU(),
         SubMConv3d(64, 64, 3, indice_key="subm2"),
         BatchNorm1d(64),
         nn.ReLU(),
         SubMConv3d(64, 64, 3, indice_key="subm2"),
         BatchNorm1d(64),
         nn.ReLU(),
         SpConv3d(64, 64, 3, 2,
                  padding=[0, 1, 1]),  # [400, 300, 11] -> [200, 150, 5]
         BatchNorm1d(64),
         nn.ReLU(),
         SubMConv3d(64, 64, 3, indice_key="subm3"),
         BatchNorm1d(64),
         nn.ReLU(),
         SubMConv3d(64, 64, 3, indice_key="subm3"),
         BatchNorm1d(64),
         nn.ReLU(),
         SubMConv3d(64, 64, 3, indice_key="subm3"),
         BatchNorm1d(64),
         nn.ReLU(),
         SpConv3d(64, 64, (3, 1, 1),
                  (2, 1, 1)),  # [200, 150, 5] -> [200, 150, 2]
         BatchNorm1d(64),
         nn.ReLU(),
     )
     self.max_batch_size = 6