"vscode:/vscode.git/clone" did not exist on "3bfdb4275c13ec8207ae78222b7895c01a01371b"
Unverified Commit 5e2fa8ce authored by ChaimZhu's avatar ChaimZhu Committed by GitHub
Browse files

[Refactor]: remove legacy builder.py and update corresponding unit tests (#2161)

* fix circle ci

* delete model builder

* fix comments
parent 9a425a11
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import pytest import pytest
import torch import torch
from mmdet3d.models.builder import build_loss from mmdet3d.registry import MODELS
def test_uncertain_smooth_l1_loss(): def test_uncertain_smooth_l1_loss():
...@@ -21,7 +21,7 @@ def test_uncertain_smooth_l1_loss(): ...@@ -21,7 +21,7 @@ def test_uncertain_smooth_l1_loss():
# test uncertain l1 loss # test uncertain l1 loss
uncertain_l1_loss_cfg = dict( uncertain_l1_loss_cfg = dict(
type='UncertainL1Loss', alpha=1.0, reduction='mean', loss_weight=1.0) type='UncertainL1Loss', alpha=1.0, reduction='mean', loss_weight=1.0)
uncertain_l1_loss = build_loss(uncertain_l1_loss_cfg) uncertain_l1_loss = MODELS.build(uncertain_l1_loss_cfg)
mean_l1_loss = uncertain_l1_loss(pred, target, sigma) mean_l1_loss = uncertain_l1_loss(pred, target, sigma)
expected_l1_loss = torch.tensor(4.7069) expected_l1_loss = torch.tensor(4.7069)
assert torch.allclose(mean_l1_loss, expected_l1_loss, atol=1e-4) assert torch.allclose(mean_l1_loss, expected_l1_loss, atol=1e-4)
...@@ -33,7 +33,7 @@ def test_uncertain_smooth_l1_loss(): ...@@ -33,7 +33,7 @@ def test_uncertain_smooth_l1_loss():
beta=0.5, beta=0.5,
reduction='mean', reduction='mean',
loss_weight=1.0) loss_weight=1.0)
uncertain_smooth_l1_loss = build_loss(uncertain_smooth_l1_loss_cfg) uncertain_smooth_l1_loss = MODELS.build(uncertain_smooth_l1_loss_cfg)
mean_smooth_l1_loss = uncertain_smooth_l1_loss(pred, target, sigma) mean_smooth_l1_loss = uncertain_smooth_l1_loss(pred, target, sigma)
expected_smooth_l1_loss = torch.tensor(3.9795) expected_smooth_l1_loss = torch.tensor(3.9795)
assert torch.allclose( assert torch.allclose(
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import pytest import pytest
import torch import torch
from mmdet3d.models.builder import build_middle_encoder from mmdet3d.registry import MODELS
def test_sparse_encoder(): def test_sparse_encoder():
...@@ -19,7 +19,7 @@ def test_sparse_encoder(): ...@@ -19,7 +19,7 @@ def test_sparse_encoder():
1)), 1)),
block_type='basicblock') block_type='basicblock')
sparse_encoder = build_middle_encoder(sparse_encoder_cfg).cuda() sparse_encoder = MODELS.build(sparse_encoder_cfg).cuda()
voxel_features = torch.rand([207842, 5]).cuda() voxel_features = torch.rand([207842, 5]).cuda()
coors = torch.randint(0, 4, [207842, 4]).cuda() coors = torch.randint(0, 4, [207842, 4]).cuda()
...@@ -41,7 +41,7 @@ def test_sparse_encoder_for_ssd(): ...@@ -41,7 +41,7 @@ def test_sparse_encoder_for_ssd():
1)), 1)),
block_type='basicblock') block_type='basicblock')
sparse_encoder = build_middle_encoder(sparse_encoder_for_ssd_cfg).cuda() sparse_encoder = MODELS.build(sparse_encoder_for_ssd_cfg).cuda()
voxel_features = torch.rand([207842, 5]).cuda() voxel_features = torch.rand([207842, 5]).cuda()
coors = torch.randint(0, 4, [207842, 4]).cuda() coors = torch.randint(0, 4, [207842, 4]).cuda()
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import torch import torch
from mmdet3d.models.builder import build_neck from mmdet3d.registry import MODELS
def test_dla_neck(): def test_dla_neck():
...@@ -19,7 +19,7 @@ def test_dla_neck(): ...@@ -19,7 +19,7 @@ def test_dla_neck():
start_level=2, start_level=2,
end_level=5, end_level=5,
norm_cfg=dict(type='GN', num_groups=32)) norm_cfg=dict(type='GN', num_groups=32))
neck = build_neck(neck_cfg) neck = MODELS.build(neck_cfg)
neck.init_weights() neck.init_weights()
neck.cuda() neck.cuda()
feats = [ feats = [
...@@ -37,7 +37,7 @@ def test_dla_neck(): ...@@ -37,7 +37,7 @@ def test_dla_neck():
end_level=5, end_level=5,
norm_cfg=dict(type='GN', num_groups=32), norm_cfg=dict(type='GN', num_groups=32),
use_dcn=False) use_dcn=False)
neck = build_neck(neck_cfg) neck = MODELS.build(neck_cfg)
neck.init_weights() neck.init_weights()
feats = [ feats = [
torch.rand(4, in_channels[i], feat_sizes[i], feat_sizes[i]) torch.rand(4, in_channels[i], feat_sizes[i], feat_sizes[i])
......
import pytest import pytest
import torch import torch
from mmdet3d.models.builder import build_neck from mmdet3d.registry import MODELS
def test_imvoxel_neck(): def test_imvoxel_neck():
...@@ -10,7 +10,7 @@ def test_imvoxel_neck(): ...@@ -10,7 +10,7 @@ def test_imvoxel_neck():
neck_cfg = dict( neck_cfg = dict(
type='OutdoorImVoxelNeck', in_channels=64, out_channels=256) type='OutdoorImVoxelNeck', in_channels=64, out_channels=256)
neck = build_neck(neck_cfg).cuda() neck = MODELS.build(neck_cfg).cuda()
inputs = torch.rand([1, 64, 216, 248, 12], device='cuda') inputs = torch.rand([1, 64, 216, 248, 12], device='cuda')
outputs = neck(inputs) outputs = neck(inputs)
assert outputs[0].shape == (1, 256, 248, 216) assert outputs[0].shape == (1, 256, 248, 216)
import pytest import pytest
import torch import torch
from mmdet3d.models.builder import build_neck from mmdet3d.registry import MODELS
def test_pointnet2_fp_neck(): def test_pointnet2_fp_neck():
...@@ -22,7 +22,7 @@ def test_pointnet2_fp_neck(): ...@@ -22,7 +22,7 @@ def test_pointnet2_fp_neck():
fp_channels=((1536, 512, 512), (768, 512, 512), (608, 256, 256), fp_channels=((1536, 512, 512), (768, 512, 512), (608, 256, 256),
(257, 128, 128))) (257, 128, 128)))
neck = build_neck(neck_cfg) neck = MODELS.build(neck_cfg)
neck.init_weights() neck.init_weights()
if torch.cuda.is_available(): if torch.cuda.is_available():
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import pytest import pytest
import torch import torch
from mmdet3d.models.builder import build_backbone, build_neck from mmdet3d.registry import MODELS
def test_secfpn(): def test_secfpn():
...@@ -12,8 +12,7 @@ def test_secfpn(): ...@@ -12,8 +12,7 @@ def test_secfpn():
upsample_strides=[1, 2], upsample_strides=[1, 2],
out_channels=[4, 6], out_channels=[4, 6],
) )
from mmdet3d.models.builder import build_neck neck = MODELS.build(neck_cfg)
neck = build_neck(neck_cfg)
assert neck.deblocks[0][0].in_channels == 2 assert neck.deblocks[0][0].in_channels == 2
assert neck.deblocks[1][0].in_channels == 3 assert neck.deblocks[1][0].in_channels == 3
assert neck.deblocks[0][0].out_channels == 4 assert neck.deblocks[0][0].out_channels == 4
...@@ -29,7 +28,7 @@ def test_secfpn(): ...@@ -29,7 +28,7 @@ def test_secfpn():
out_channels=[2, 2], out_channels=[2, 2],
) )
with pytest.raises(AssertionError): with pytest.raises(AssertionError):
build_neck(neck_cfg) MODELS.build(neck_cfg)
neck_cfg = dict( neck_cfg = dict(
type='SECONDFPN', type='SECONDFPN',
...@@ -38,7 +37,7 @@ def test_secfpn(): ...@@ -38,7 +37,7 @@ def test_secfpn():
out_channels=[2, 2], out_channels=[2, 2],
) )
with pytest.raises(AssertionError): with pytest.raises(AssertionError):
build_neck(neck_cfg) MODELS.build(neck_cfg)
def test_centerpoint_fpn(): def test_centerpoint_fpn():
...@@ -52,7 +51,7 @@ def test_centerpoint_fpn(): ...@@ -52,7 +51,7 @@ def test_centerpoint_fpn():
norm_cfg=dict(type='BN', eps=1e-3, momentum=0.01), norm_cfg=dict(type='BN', eps=1e-3, momentum=0.01),
conv_cfg=dict(type='Conv2d', bias=False)) conv_cfg=dict(type='Conv2d', bias=False))
second = build_backbone(second_cfg) second = MODELS.build(second_cfg)
# centerpoint usage of fpn # centerpoint usage of fpn
centerpoint_fpn_cfg = dict( centerpoint_fpn_cfg = dict(
...@@ -71,9 +70,9 @@ def test_centerpoint_fpn(): ...@@ -71,9 +70,9 @@ def test_centerpoint_fpn():
upsample_strides=[1, 2, 4], upsample_strides=[1, 2, 4],
out_channels=[2, 2, 2]) out_channels=[2, 2, 2])
second_fpn = build_neck(fpn_cfg) second_fpn = MODELS.build(fpn_cfg)
centerpoint_second_fpn = build_neck(centerpoint_fpn_cfg) centerpoint_second_fpn = MODELS.build(centerpoint_fpn_cfg)
input = torch.rand([2, 2, 32, 32]) input = torch.rand([2, 2, 32, 32])
sec_output = second(input) sec_output = second(input)
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import pytest import pytest
import torch import torch
from mmdet3d.models.builder import build_voxel_encoder from mmdet3d.registry import MODELS
def test_pillar_feature_net(): def test_pillar_feature_net():
...@@ -16,7 +16,7 @@ def test_pillar_feature_net(): ...@@ -16,7 +16,7 @@ def test_pillar_feature_net():
voxel_size=(0.2, 0.2, 8), voxel_size=(0.2, 0.2, 8),
point_cloud_range=(-51.2, -51.2, -5.0, 51.2, 51.2, 3.0), point_cloud_range=(-51.2, -51.2, -5.0, 51.2, 51.2, 3.0),
norm_cfg=dict(type='BN1d', eps=1e-3, momentum=0.01)) norm_cfg=dict(type='BN1d', eps=1e-3, momentum=0.01))
pillar_feature_net = build_voxel_encoder(pillar_feature_net_cfg) pillar_feature_net = MODELS.build(pillar_feature_net_cfg)
features = torch.rand([97297, 20, 5]) features = torch.rand([97297, 20, 5])
num_voxels = torch.randint(1, 100, [97297]) num_voxels = torch.randint(1, 100, [97297])
......
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
import pytest import pytest
import torch import torch
from mmdet3d.models.builder import build_voxel_encoder from mmdet3d.registry import MODELS
def test_hard_simple_VFE(): def test_hard_simple_VFE():
if not torch.cuda.is_available(): if not torch.cuda.is_available():
pytest.skip('test requires GPU and torch+cuda') pytest.skip('test requires GPU and torch+cuda')
hard_simple_VFE_cfg = dict(type='HardSimpleVFE', num_features=5) hard_simple_VFE_cfg = dict(type='HardSimpleVFE', num_features=5)
hard_simple_VFE = build_voxel_encoder(hard_simple_VFE_cfg) hard_simple_VFE = MODELS.build(hard_simple_VFE_cfg)
features = torch.rand([240000, 10, 5]) features = torch.rand([240000, 10, 5])
num_voxels = torch.randint(1, 10, [240000]) num_voxels = torch.randint(1, 10, [240000])
......
...@@ -7,8 +7,7 @@ from mmcv import Config ...@@ -7,8 +7,7 @@ from mmcv import Config
from mmcv.parallel import MMDataParallel from mmcv.parallel import MMDataParallel
from mmengine.runner import load_checkpoint from mmengine.runner import load_checkpoint
from mmdet3d.datasets import build_dataset from mmdet3d.registry import DATASETS, MODELS
from mmdet3d.models import build_detector
from tools.misc.fuse_conv_bn import fuse_module from tools.misc.fuse_conv_bn import fuse_module
...@@ -40,7 +39,7 @@ def main(): ...@@ -40,7 +39,7 @@ def main():
# build the dataloader # build the dataloader
# TODO: support multiple images per gpu (only minor changes are needed) # TODO: support multiple images per gpu (only minor changes are needed)
dataset = build_dataset(cfg.data.test) dataset = DATASETS.build(cfg.data.test)
# TODO fix this # TODO fix this
def build_dataloader(): def build_dataloader():
...@@ -55,7 +54,7 @@ def main(): ...@@ -55,7 +54,7 @@ def main():
# build the model and load checkpoint # build the model and load checkpoint
cfg.model.train_cfg = None cfg.model.train_cfg = None
model = build_detector(cfg.model, test_cfg=cfg.get('test_cfg')) model = MODELS.build(cfg.model, test_cfg=cfg.get('test_cfg'))
load_checkpoint(model, args.checkpoint, map_location='cpu') load_checkpoint(model, args.checkpoint, map_location='cpu')
if args.fuse_conv_bn: if args.fuse_conv_bn:
model = fuse_module(model) model = fuse_module(model)
......
...@@ -11,7 +11,7 @@ from mmengine import track_iter_progress ...@@ -11,7 +11,7 @@ from mmengine import track_iter_progress
from pycocotools import mask as maskUtils from pycocotools import mask as maskUtils
from pycocotools.coco import COCO from pycocotools.coco import COCO
from mmdet3d.datasets import build_dataset from mmdet3d.registry import DATASETS
from mmdet3d.structures.ops import box_np_ops as box_np_ops from mmdet3d.structures.ops import box_np_ops as box_np_ops
...@@ -218,7 +218,7 @@ def create_groundtruth_database(dataset_class_name, ...@@ -218,7 +218,7 @@ def create_groundtruth_database(dataset_class_name,
file_client_args=file_client_args) file_client_args=file_client_args)
]) ])
dataset = build_dataset(dataset_cfg) dataset = DATASETS.build(dataset_cfg)
if database_save_path is None: if database_save_path is None:
database_save_path = osp.join(data_path, f'{info_prefix}_gt_database') database_save_path = osp.join(data_path, f'{info_prefix}_gt_database')
...@@ -587,7 +587,7 @@ class GTDatabaseCreater: ...@@ -587,7 +587,7 @@ class GTDatabaseCreater:
file_client_args=file_client_args) file_client_args=file_client_args)
]) ])
self.dataset = build_dataset(dataset_cfg) self.dataset = DATASETS.build(dataset_cfg)
self.pipeline = self.dataset.pipeline self.pipeline = self.dataset.pipeline
if self.database_save_path is None: if self.database_save_path is None:
self.database_save_path = osp.join( self.database_save_path = osp.join(
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
import argparse import argparse
import mmengine import mmengine
from mmcv import Config from mmengine import Config
from mmdet3d.datasets import build_dataset from mmdet3d.registry import DATASETS
def parse_args(): def parse_args():
...@@ -30,7 +30,7 @@ def main(): ...@@ -30,7 +30,7 @@ def main():
cfg.data.test.test_mode = True cfg.data.test.test_mode = True
# build the dataset # build the dataset
dataset = build_dataset(cfg.data.test) dataset = DATASETS.build(cfg.data.test)
results = mmengine.load(args.result) results = mmengine.load(args.result)
if getattr(dataset, 'show', None) is not None: if getattr(dataset, 'show', None) is not None:
......
...@@ -6,7 +6,7 @@ import torch ...@@ -6,7 +6,7 @@ import torch
from mmcv import Config from mmcv import Config
from mmengine.runner import load_state_dict from mmengine.runner import load_state_dict
from mmdet3d.models import build_detector from mmdet3d.registry import MODELS
def parse_args(): def parse_args():
...@@ -103,7 +103,7 @@ def main(): ...@@ -103,7 +103,7 @@ def main():
checkpoint = torch.load(args.checkpoint) checkpoint = torch.load(args.checkpoint)
cfg = parse_config(checkpoint['meta']['config']) cfg = parse_config(checkpoint['meta']['config'])
# Build the model and load checkpoint # Build the model and load checkpoint
model = build_detector( model = MODELS.build(
cfg.model, cfg.model,
train_cfg=cfg.get('train_cfg'), train_cfg=cfg.get('train_cfg'),
test_cfg=cfg.get('test_cfg')) test_cfg=cfg.get('test_cfg'))
......
...@@ -6,7 +6,7 @@ import torch ...@@ -6,7 +6,7 @@ import torch
from mmengine import Config from mmengine import Config
from mmengine.runner import load_state_dict from mmengine.runner import load_state_dict
from mmdet3d.models import build_detector from mmdet3d.registry import MODELS
def parse_args(): def parse_args():
...@@ -79,7 +79,7 @@ def main(): ...@@ -79,7 +79,7 @@ def main():
checkpoint = torch.load(args.checkpoint) checkpoint = torch.load(args.checkpoint)
cfg = parse_config(checkpoint['meta']['config']) cfg = parse_config(checkpoint['meta']['config'])
# Build the model and load checkpoint # Build the model and load checkpoint
model = build_detector( model = MODELS.build(
cfg.model, cfg.model,
train_cfg=cfg.get('train_cfg'), train_cfg=cfg.get('train_cfg'),
test_cfg=cfg.get('test_cfg')) test_cfg=cfg.get('test_cfg'))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment