Commit c2fe651f authored by zhangshilong's avatar zhangshilong Committed by ChaimZhu
Browse files

refactor directory

parent bc5806ba
...@@ -5,8 +5,8 @@ import numpy as np ...@@ -5,8 +5,8 @@ import numpy as np
import torch import torch
from mmengine.testing import assert_allclose from mmengine.testing import assert_allclose
from mmdet3d.core import DepthInstance3DBoxes
from mmdet3d.datasets import ScanNetDataset, ScanNetSegDataset from mmdet3d.datasets import ScanNetDataset, ScanNetSegDataset
from mmdet3d.structures import DepthInstance3DBoxes
from mmdet3d.utils import register_all_modules from mmdet3d.utils import register_all_modules
......
...@@ -5,8 +5,8 @@ import numpy as np ...@@ -5,8 +5,8 @@ import numpy as np
import torch import torch
from mmengine.testing import assert_allclose from mmengine.testing import assert_allclose
from mmdet3d.core import DepthInstance3DBoxes
from mmdet3d.datasets import SUNRGBDDataset from mmdet3d.datasets import SUNRGBDDataset
from mmdet3d.structures import DepthInstance3DBoxes
def _generate_scannet_dataset_config(): def _generate_scannet_dataset_config():
......
...@@ -8,7 +8,7 @@ from mmengine.testing import assert_allclose ...@@ -8,7 +8,7 @@ from mmengine.testing import assert_allclose
from utils import create_data_info_after_loading from utils import create_data_info_after_loading
from mmdet3d.datasets import GlobalAlignment, RandomFlip3D from mmdet3d.datasets import GlobalAlignment, RandomFlip3D
from mmdet3d.datasets.pipelines import GlobalRotScaleTrans from mmdet3d.datasets.transforms import GlobalRotScaleTrans
class TestGlobalRotScaleTrans(unittest.TestCase): class TestGlobalRotScaleTrans(unittest.TestCase):
......
...@@ -6,10 +6,10 @@ import torch ...@@ -6,10 +6,10 @@ import torch
from mmengine.testing import assert_allclose from mmengine.testing import assert_allclose
from utils import create_dummy_data_info from utils import create_dummy_data_info
from mmdet3d.core import DepthPoints, LiDARPoints from mmdet3d.datasets.transforms import PointSegClassMapping
from mmdet3d.datasets.pipelines import PointSegClassMapping from mmdet3d.datasets.transforms.loading import (LoadAnnotations3D,
from mmdet3d.datasets.pipelines.loading import (LoadAnnotations3D,
LoadPointsFromFile) LoadPointsFromFile)
from mmdet3d.structures import DepthPoints, LiDARPoints
class TestLoadPointsFromFile(unittest.TestCase): class TestLoadPointsFromFile(unittest.TestCase):
......
...@@ -5,8 +5,8 @@ import torch ...@@ -5,8 +5,8 @@ import torch
from mmengine.testing import assert_allclose from mmengine.testing import assert_allclose
from utils import create_data_info_after_loading from utils import create_data_info_after_loading
from mmdet3d.core import LiDARInstance3DBoxes from mmdet3d.datasets.transforms.formating import Pack3DDetInputs
from mmdet3d.datasets.pipelines.formating import Pack3DDetInputs from mmdet3d.structures import LiDARInstance3DBoxes
class TestPack3DDetInputs(unittest.TestCase): class TestPack3DDetInputs(unittest.TestCase):
......
# Copyright (c) OpenMMLab. All rights reserved. # Copyright (c) OpenMMLab. All rights reserved.
import numpy as np import numpy as np
from mmdet3d.core import LiDARInstance3DBoxes
# create a dummy `results` to test the pipeline # create a dummy `results` to test the pipeline
from mmdet3d.datasets import LoadAnnotations3D, LoadPointsFromFile from mmdet3d.datasets import LoadAnnotations3D, LoadPointsFromFile
from mmdet3d.datasets.pipelines.loading import LoadImageFromFileMono3D from mmdet3d.datasets.transforms.loading import LoadImageFromFileMono3D
from mmdet3d.structures import LiDARInstance3DBoxes
def create_dummy_data_info(with_ann=True): def create_dummy_data_info(with_ann=True):
......
# Copyright (c) OpenMMLab. All rights reserved.
import numpy as np
import pytest
import torch
from mmdet3d.core.evaluation.indoor_eval import average_precision, indoor_eval
def test_indoor_eval():
if not torch.cuda.is_available():
pytest.skip()
from mmdet3d.core.bbox.structures import Box3DMode, DepthInstance3DBoxes
det_infos = [{
'labels_3d':
torch.tensor([0, 1, 2, 2, 0, 3, 1, 2, 3, 2]),
'boxes_3d':
DepthInstance3DBoxes(
torch.tensor([[
-2.4089e-03, -3.3174e+00, 4.9438e-01, 2.1668e+00, 2.8431e-01,
1.6506e+00, 0.0000e+00
],
[
-3.4269e-01, -2.7565e+00, 2.8144e-02, 6.8554e-01,
9.6854e-01, 6.1755e-01, 0.0000e+00
],
[
-3.8320e+00, -1.0646e+00, 1.7074e-01, 2.4981e-01,
4.4708e-01, 6.2538e-01, 0.0000e+00
],
[
4.1073e-01, 3.3757e+00, 3.4311e-01, 8.0617e-01,
2.8679e-01, 1.6060e+00, 0.0000e+00
],
[
6.1199e-01, -3.1041e+00, 4.1873e-01, 1.2310e+00,
4.0162e-01, 1.7303e+00, 0.0000e+00
],
[
-5.9877e-01, -2.6011e+00, 1.1148e+00, 1.5704e-01,
7.5957e-01, 9.6930e-01, 0.0000e+00
],
[
2.7462e-01, -3.0088e+00, 6.5231e-02, 8.1208e-01,
4.1861e-01, 3.7339e-01, 0.0000e+00
],
[
-1.4704e+00, -2.0024e+00, 2.7479e-01, 1.7888e+00,
1.0566e+00, 1.3704e+00, 0.0000e+00
],
[
8.2727e-02, -3.1160e+00, 2.5690e-01, 1.4054e+00,
2.0772e-01, 9.6792e-01, 0.0000e+00
],
[
2.6896e+00, 1.9881e+00, 1.1566e+00, 9.9885e-02,
3.5713e-01, 4.5638e-01, 0.0000e+00
]]),
origin=(0.5, 0.5, 0)),
'scores_3d':
torch.tensor([
1.7516e-05, 1.0167e-06, 8.4486e-07, 7.1048e-02, 6.4274e-05,
1.5003e-07, 5.8102e-06, 1.9399e-08, 5.3126e-07, 1.8630e-09
])
}]
label2cat = {
0: 'cabinet',
1: 'bed',
2: 'chair',
3: 'sofa',
}
gt_annos = [{
'gt_num':
10,
'gt_boxes_upright_depth':
np.array([[
-2.4089e-03, -3.3174e+00, 4.9438e-01, 2.1668e+00, 2.8431e-01,
1.6506e+00, 0.0000e+00
],
[
-3.4269e-01, -2.7565e+00, 2.8144e-02, 6.8554e-01,
9.6854e-01, 6.1755e-01, 0.0000e+00
],
[
-3.8320e+00, -1.0646e+00, 1.7074e-01, 2.4981e-01,
4.4708e-01, 6.2538e-01, 0.0000e+00
],
[
4.1073e-01, 3.3757e+00, 3.4311e-01, 8.0617e-01,
2.8679e-01, 1.6060e+00, 0.0000e+00
],
[
6.1199e-01, -3.1041e+00, 4.1873e-01, 1.2310e+00,
4.0162e-01, 1.7303e+00, 0.0000e+00
],
[
-5.9877e-01, -2.6011e+00, 1.1148e+00, 1.5704e-01,
7.5957e-01, 9.6930e-01, 0.0000e+00
],
[
2.7462e-01, -3.0088e+00, 6.5231e-02, 8.1208e-01,
4.1861e-01, 3.7339e-01, 0.0000e+00
],
[
-1.4704e+00, -2.0024e+00, 2.7479e-01, 1.7888e+00,
1.0566e+00, 1.3704e+00, 0.0000e+00
],
[
8.2727e-02, -3.1160e+00, 2.5690e-01, 1.4054e+00,
2.0772e-01, 9.6792e-01, 0.0000e+00
],
[
2.6896e+00, 1.9881e+00, 1.1566e+00, 9.9885e-02,
3.5713e-01, 4.5638e-01, 0.0000e+00
]]),
'class':
np.array([0, 1, 2, 0, 0, 3, 1, 3, 3, 2])
}]
ret_value = indoor_eval(
gt_annos,
det_infos, [0.25, 0.5],
label2cat,
box_type_3d=DepthInstance3DBoxes,
box_mode_3d=Box3DMode.DEPTH)
assert np.isclose(ret_value['cabinet_AP_0.25'], 0.666667)
assert np.isclose(ret_value['bed_AP_0.25'], 1.0)
assert np.isclose(ret_value['chair_AP_0.25'], 0.5)
assert np.isclose(ret_value['mAP_0.25'], 0.708333)
assert np.isclose(ret_value['mAR_0.25'], 0.833333)
def test_indoor_eval_less_classes():
if not torch.cuda.is_available():
pytest.skip()
from mmdet3d.core.bbox.structures import Box3DMode, DepthInstance3DBoxes
det_infos = [{
'labels_3d':
torch.tensor([0]),
'boxes_3d':
DepthInstance3DBoxes(torch.tensor([[1., 1., 1., 1., 1., 1., 1.]])),
'scores_3d':
torch.tensor([.5])
}, {
'labels_3d':
torch.tensor([1]),
'boxes_3d':
DepthInstance3DBoxes(torch.tensor([[1., 1., 1., 1., 1., 1., 1.]])),
'scores_3d':
torch.tensor([.5])
}]
label2cat = {0: 'cabinet', 1: 'bed', 2: 'chair'}
gt_annos = [{
'gt_num':
2,
'gt_boxes_upright_depth':
np.array([[0., 0., 0., 1., 1., 1., 1.], [1., 1., 1., 1., 1., 1., 1.]]),
'class':
np.array([2, 0])
}, {
'gt_num':
1,
'gt_boxes_upright_depth':
np.array([
[1., 1., 1., 1., 1., 1., 1.],
]),
'class':
np.array([1])
}]
ret_value = indoor_eval(
gt_annos,
det_infos, [0.25, 0.5],
label2cat,
box_type_3d=DepthInstance3DBoxes,
box_mode_3d=Box3DMode.DEPTH)
assert np.isclose(ret_value['mAP_0.25'], 0.666667)
assert np.isclose(ret_value['mAR_0.25'], 0.666667)
def test_average_precision():
ap = average_precision(
np.array([[0.25, 0.5, 0.75], [0.25, 0.5, 0.75]]),
np.array([[1., 1., 1.], [1., 1., 1.]]), '11points')
assert abs(ap[0] - 0.06611571) < 0.001
...@@ -5,8 +5,8 @@ from unittest.mock import patch ...@@ -5,8 +5,8 @@ from unittest.mock import patch
import numpy as np import numpy as np
import torch import torch
from mmdet3d.core import DepthInstance3DBoxes from mmdet3d.evaluation.metrics import IndoorMetric
from mmdet3d.metrics import IndoorMetric from mmdet3d.structures import DepthInstance3DBoxes
class TestIndoorMetric(unittest.TestCase): class TestIndoorMetric(unittest.TestCase):
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import numpy as np import numpy as np
import torch import torch
from mmdet3d.core import instance_seg_eval from mmdet3d.evaluation import instance_seg_eval
def test_instance_seg_eval(): def test_instance_seg_eval():
......
...@@ -5,8 +5,8 @@ import numpy as np ...@@ -5,8 +5,8 @@ import numpy as np
import torch import torch
from mmengine.data import BaseDataElement from mmengine.data import BaseDataElement
from mmdet3d.core.data_structures import Det3DDataSample, PointData from mmdet3d.evaluation.metrics import InstanceSegMetric
from mmdet3d.metrics import InstanceSegMetric from mmdet3d.structures import Det3DDataSample, PointData
class TestInstanceSegMetric(unittest.TestCase): class TestInstanceSegMetric(unittest.TestCase):
......
...@@ -3,8 +3,7 @@ import numpy as np ...@@ -3,8 +3,7 @@ import numpy as np
import pytest import pytest
import torch import torch
from mmdet3d.core.evaluation.kitti_utils.eval import (do_eval, eval_class, from mmdet3d.evaluation import do_eval, eval_class, kitti_eval
kitti_eval)
def test_do_eval(): def test_do_eval():
......
...@@ -3,9 +3,8 @@ import pytest ...@@ -3,9 +3,8 @@ import pytest
import torch import torch
from mmengine.data import InstanceData from mmengine.data import InstanceData
from mmdet3d.core import Det3DDataSample from mmdet3d.evaluation.metrics import KittiMetric
from mmdet3d.core.bbox import LiDARInstance3DBoxes from mmdet3d.structures import Det3DDataSample, LiDARInstance3DBoxes
from mmdet3d.metrics import KittiMetric
data_root = 'tests/data/kitti' data_root = 'tests/data/kitti'
......
...@@ -3,7 +3,7 @@ import numpy as np ...@@ -3,7 +3,7 @@ import numpy as np
import pytest import pytest
import torch import torch
from mmdet3d.core.evaluation.seg_eval import seg_eval from mmdet3d.evaluation.functional.seg_eval import seg_eval
def test_indoor_eval(): def test_indoor_eval():
......
...@@ -4,8 +4,8 @@ import unittest ...@@ -4,8 +4,8 @@ import unittest
import torch import torch
from mmengine.data import BaseDataElement from mmengine.data import BaseDataElement
from mmdet3d.core.data_structures import Det3DDataSample, PointData from mmdet3d.evaluation.metrics import SegMetric
from mmdet3d.metrics import SegMetric from mmdet3d.structures import Det3DDataSample, PointData
class TestSegMetric(unittest.TestCase): class TestSegMetric(unittest.TestCase):
......
...@@ -7,7 +7,7 @@ import torch ...@@ -7,7 +7,7 @@ import torch
def test_dgcnn_gf_module(): def test_dgcnn_gf_module():
if not torch.cuda.is_available(): if not torch.cuda.is_available():
pytest.skip() pytest.skip()
from mmdet3d.ops import DGCNNGFModule from mmdet3d.models.layers import DGCNNGFModule
self = DGCNNGFModule( self = DGCNNGFModule(
mlp_channels=[18, 64, 64], mlp_channels=[18, 64, 64],
...@@ -60,7 +60,7 @@ def test_dgcnn_gf_module(): ...@@ -60,7 +60,7 @@ def test_dgcnn_gf_module():
def test_dgcnn_fa_module(): def test_dgcnn_fa_module():
if not torch.cuda.is_available(): if not torch.cuda.is_available():
pytest.skip() pytest.skip()
from mmdet3d.ops import DGCNNFAModule from mmdet3d.models.layers import DGCNNFAModule
self = DGCNNFAModule(mlp_channels=[24, 16]).cuda() self = DGCNNFAModule(mlp_channels=[24, 16]).cuda()
assert self.mlps.layer0.conv.in_channels == 24 assert self.mlps.layer0.conv.in_channels == 24
...@@ -75,7 +75,7 @@ def test_dgcnn_fa_module(): ...@@ -75,7 +75,7 @@ def test_dgcnn_fa_module():
def test_dgcnn_fp_module(): def test_dgcnn_fp_module():
if not torch.cuda.is_available(): if not torch.cuda.is_available():
pytest.skip() pytest.skip()
from mmdet3d.ops import DGCNNFPModule from mmdet3d.models.layers import DGCNNFPModule
self = DGCNNFPModule(mlp_channels=[24, 16]).cuda() self = DGCNNFPModule(mlp_channels=[24, 16]).cuda()
assert self.mlps.layer0.conv.in_channels == 24 assert self.mlps.layer0.conv.in_channels == 24
......
...@@ -7,7 +7,7 @@ import torch ...@@ -7,7 +7,7 @@ import torch
def test_paconv_sa_module_msg(): def test_paconv_sa_module_msg():
if not torch.cuda.is_available(): if not torch.cuda.is_available():
pytest.skip() pytest.skip()
from mmdet3d.ops import PAConvSAModuleMSG from mmdet3d.models.layers import PAConvSAModuleMSG
# paconv_num_kernels should have same length as mlp_channels # paconv_num_kernels should have same length as mlp_channels
with pytest.raises(AssertionError): with pytest.raises(AssertionError):
...@@ -105,7 +105,7 @@ def test_paconv_sa_module_msg(): ...@@ -105,7 +105,7 @@ def test_paconv_sa_module_msg():
def test_paconv_sa_module(): def test_paconv_sa_module():
if not torch.cuda.is_available(): if not torch.cuda.is_available():
pytest.skip() pytest.skip()
from mmdet3d.ops import build_sa_module from mmdet3d.models.layers import build_sa_module
sa_cfg = dict( sa_cfg = dict(
type='PAConvSAModule', type='PAConvSAModule',
num_point=16, num_point=16,
...@@ -164,7 +164,7 @@ def test_paconv_sa_module(): ...@@ -164,7 +164,7 @@ def test_paconv_sa_module():
def test_paconv_cuda_sa_module_msg(): def test_paconv_cuda_sa_module_msg():
if not torch.cuda.is_available(): if not torch.cuda.is_available():
pytest.skip() pytest.skip()
from mmdet3d.ops import PAConvCUDASAModuleMSG from mmdet3d.models.layers import PAConvCUDASAModuleMSG
# paconv_num_kernels should have same length as mlp_channels # paconv_num_kernels should have same length as mlp_channels
with pytest.raises(AssertionError): with pytest.raises(AssertionError):
...@@ -245,7 +245,7 @@ def test_paconv_cuda_sa_module_msg(): ...@@ -245,7 +245,7 @@ def test_paconv_cuda_sa_module_msg():
def test_paconv_cuda_sa_module(): def test_paconv_cuda_sa_module():
if not torch.cuda.is_available(): if not torch.cuda.is_available():
pytest.skip() pytest.skip()
from mmdet3d.ops import build_sa_module from mmdet3d.models.layers import build_sa_module
sa_cfg = dict( sa_cfg = dict(
type='PAConvCUDASAModule', type='PAConvCUDASAModule',
num_point=16, num_point=16,
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import pytest import pytest
import torch import torch
from mmdet3d.ops import PAConv, PAConvCUDA from mmdet3d.models.layers import PAConv, PAConvCUDA
def test_paconv(): def test_paconv():
......
...@@ -7,7 +7,7 @@ import torch ...@@ -7,7 +7,7 @@ import torch
def test_pointnet_sa_module_msg(): def test_pointnet_sa_module_msg():
if not torch.cuda.is_available(): if not torch.cuda.is_available():
pytest.skip() pytest.skip()
from mmdet3d.ops import PointSAModuleMSG from mmdet3d.models.layers import PointSAModuleMSG
self = PointSAModuleMSG( self = PointSAModuleMSG(
num_point=16, num_point=16,
...@@ -152,7 +152,7 @@ def test_pointnet_sa_module_msg(): ...@@ -152,7 +152,7 @@ def test_pointnet_sa_module_msg():
def test_pointnet_sa_module(): def test_pointnet_sa_module():
if not torch.cuda.is_available(): if not torch.cuda.is_available():
pytest.skip() pytest.skip()
from mmdet3d.ops import build_sa_module from mmdet3d.models.layers import build_sa_module
sa_cfg = dict( sa_cfg = dict(
type='PointSAModule', type='PointSAModule',
num_point=16, num_point=16,
...@@ -211,7 +211,7 @@ def test_pointnet_sa_module(): ...@@ -211,7 +211,7 @@ def test_pointnet_sa_module():
def test_pointnet_fp_module(): def test_pointnet_fp_module():
if not torch.cuda.is_available(): if not torch.cuda.is_available():
pytest.skip() pytest.skip()
from mmdet3d.ops import PointFPModule from mmdet3d.models.layers import PointFPModule
self = PointFPModule(mlp_channels=[24, 16]).cuda() self = PointFPModule(mlp_channels=[24, 16]).cuda()
assert self.mlps.layer0.conv.in_channels == 24 assert self.mlps.layer0.conv.in_channels == 24
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
import pytest import pytest
import torch import torch
from mmdet3d.ops import SparseBasicBlock from mmdet3d.models.layers import SparseBasicBlock
from mmdet3d.ops.spconv import IS_SPCONV2_AVAILABLE from mmdet3d.models.layers.spconv import IS_SPCONV2_AVAILABLE
if IS_SPCONV2_AVAILABLE: if IS_SPCONV2_AVAILABLE:
from spconv.pytorch import (SparseConv3d, SparseConvTensor, from spconv.pytorch import (SparseConv3d, SparseConvTensor,
...@@ -97,7 +97,7 @@ def test_SparseBasicBlock(): ...@@ -97,7 +97,7 @@ def test_SparseBasicBlock():
def test_make_sparse_convmodule(): def test_make_sparse_convmodule():
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')
from mmdet3d.ops import make_sparse_convmodule from mmdet3d.models.layers import make_sparse_convmodule
voxel_features = torch.tensor( voxel_features = torch.tensor(
[[6.56126, 0.9648336, -1.7339306, 0.315], [[6.56126, 0.9648336, -1.7339306, 0.315],
......
...@@ -3,7 +3,7 @@ import torch ...@@ -3,7 +3,7 @@ import torch
def test_vote_module(): def test_vote_module():
from mmdet3d.models.model_utils import VoteModule from mmdet3d.models.layers import VoteModule
vote_loss = dict( vote_loss = dict(
type='ChamferDistance', type='ChamferDistance',
......
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