open-mmlab / mmdetection3d

OpenMMLab's next-generation platform for general 3D object detection.
https://mmdetection3d.readthedocs.io/en/latest/
Apache License 2.0
5.25k stars 1.54k forks source link

[Bug] When calling mmdet3d in non mmdetection3d, many models are not registered. #2183

Closed weihongwei-zg closed 1 year ago

weihongwei-zg commented 1 year ago

Prerequisite

Task

I'm using the official example scripts/configs for the officially supported tasks/models/datasets.

Branch

1.1x branch https://github.com/open-mmlab/mmdetection3d/tree/1.1

Environment

System environment: sys.platform: linux Python: 3.7.13 (default, Mar 29 2022, 02:18:16) [GCC 7.5.0] CUDA available: True numpy_random_seed: 510644439 GPU 0: Quadro P5000 CUDA_HOME: /usr/local/cuda NVCC: Cuda compilation tools, release 10.2, V10.2.8 GCC: gcc (Ubuntu 5.5.0-12ubuntu1) 5.5.0 20171010 PyTorch: 1.8.0 PyTorch compiling details: PyTorch built with:

Runtime environment: cudnn_benchmark: False mp_cfg: {'mp_start_method': 'fork', 'opencv_num_threads': 0} dist_cfg: {'backend': 'nccl'} seed: None Distributed launcher: none Distributed training: False GPU number: 1

Reproduces the problem - code sample

from mmdet3d.utils import register_all_modules
register_all_modules(init_default_scope=False)

Reproduces the problem - command or script

from mmdet3d.utils import register_all_modules
register_all_modules(init_default_scope=False)

Reproduces the problem - error message

12/29/2022 17:51:58 - INFO - dair_v2x_for_detection - VIC-Sync test_A dataset, overall 851 frames 12/29/2022 17:51:58 - INFO - main - loading evaluator 12/29/2022 17:51:58 - INFO - main - loading model 0%| | 0/851 [00:00<?, ?it/s]12/29/2022 17:52:17 - INFO - mmdet3d_anymodel_lidar_early - building model 12/29/2022 17:52:17 - WARNING - trimesh - No FCL -- collision checking will not work /media/wangshuang/sdb/3d_new/mmdetection3d/mmdet3d/models/dense_heads/anchor3d_head.py:93: UserWarning: dir_offset and dir_limit_offset will be depressed and be incorporated into box coder in the future 'dir_offset and dir_limit_offset will be depressed and be ' local loads checkpoint from path: ../configs/vic3d/early-fusion-pointcloud/pointpillars/earlyfusion_veh_pointpillars.pth 0%| | 0/851 [00:22<?, ?it/s] Traceback (most recent call last): File "../v2x/models/detection_models/mmdet3d_anymodel_lidar_early.py", line 197, in forward pred_dict, id = self.pred(data, trans, pred_filter) File "../v2x/models/detection_models/mmdet3d_anymodel_lidar_early.py", line 144, in pred raise Exception Exception

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "eval.py", line 120, in eval_vic(args, dataset, model, evaluator) File "eval.py", line 40, in eval_vic None if not hasattr(dataset, "prev_inf_frame") else dataset.prev_inf_frame, File "/home/wangshuang/anaconda3/envs/mmlab/lib/python3.7/site-packages/torch/nn/modules/module.py", line 889, in _call_impl result = self.forward(*input, kwargs) File "../v2x/models/detection_models/mmdet3d_anymodel_lidar_early.py", line 107, in forward pred, id_veh = self.model(vic_frame.vehicle_frame(), None, filt) File "/home/wangshuang/anaconda3/envs/mmlab/lib/python3.7/site-packages/torch/nn/modules/module.py", line 889, in _call_impl result = self.forward(*input, *kwargs) File "../v2x/models/detection_models/mmdet3d_anymodel_lidar_early.py", line 208, in forward pred_dict, id = self.pred(data, trans, pred_filter) File "../v2x/models/detection_models/mmdet3d_anymodel_lidarearly.py", line 147, in pred result, = inference_detector(self.model, tmp) File "../v2x/models/model_utils/mmdet3d_utils.py", line 139, in inference_detector test_pipeline = Compose(test_pipeline) File "/home/wangshuang/anaconda3/envs/mmlab/lib/python3.7/site-packages/mmengine/dataset/base_dataset.py", line 36, in init transform = TRANSFORMS.build(transform) File "/home/wangshuang/anaconda3/envs/mmlab/lib/python3.7/site-packages/mmengine/registry/registry.py", line 421, in build return self.build_func(cfg, args, kwargs, registry=self) File "/home/wangshuang/anaconda3/envs/mmlab/lib/python3.7/site-packages/mmengine/registry/build_functions.py", line 101, in build_from_cfg f'{obj_type} is not in the {registry.name} registry. ' KeyError: 'LoadPointsFromFile is not in the transform registry. Please check whether the value of LoadPointsFromFile is correct or it was registered as expected. More details can be found at https://mmengine.readthedocs.io/en/latest/tutorials/config.html#import-custom-python-modules'

Additional information

The registration model code has been added, but you still need to change the registry one by one.

Tai-Wang commented 1 year ago

It seems you did not directly use the official mmdet3d repo. Could you please provide a link to your original used repo (maybe it required the old version of mmdet3d)?

weihongwei-zg commented 1 year ago

https://github.com/open-mmlab/mmdetection3d/blob/v0.17.1/mmdet3d/apis/inference.py

weihongwei-zg commented 1 year ago

The error code is in the reasoning part, when the model configuration is initialized. The new version is on line 66. https://github.com/open-mmlab/mmdetection3d/blob/v1.1.0rc2/mmdet3d/apis/inference.py

weihongwei-zg commented 1 year ago

The part of the code call I run is in this link. https://github.com/AIR-THU/DAIR-V2X/blob/main/v2x/models/detection_models/mmdet3d_anymodel_lidar_early.py

weihongwei-zg commented 1 year ago

I found that the 1.1.0rc2 code built in this way can be tested successfully, but the model.test encapsulates a lot of things, and I can't get the return value I want.How can I be compatible with older versions of inference code inference?

register_all_modules(init_default_scope=False) config.load_from = checkpoint model = RUNNERS.build(config) model.test() #model.to(device) #model.eval() return model

weihongwei-zg commented 1 year ago

I need the model to give me this value. result, _ = inference_detector(model, tmp)

weihongwei-zg commented 1 year ago

I added the registration code and changed some code in mmdet3d. Now it can be executed normally.