From e45236161ec4deecbe7803308fcf45fac3842597 Mon Sep 17 00:00:00 2001 From: kyh980909 Date: Wed, 27 Nov 2024 19:07:05 +0900 Subject: [PATCH] Fix: Resolve matrix dimension mismatch issue in `_dispatch_kwargs` - Updated `_dispatch_kwargs` method to handle `cam_type` and `out_dir` more robustly. - Ensured proper handling of `cam2img` and `lidar2cam` matrix dimensions: - Added logic to convert 3x3 matrices to 4x4 for compatibility with downstream calculations. - Included validation checks for input dimensions to prevent runtime errors. - Improved error handling for unsupported or missing `cam_type` in the dataset. - Added debug logging to trace matrix shapes during preprocessing. These changes resolve the ValueError related to incompatible matrix dimensions during the `matmul` operation. --- demo/mono_det_demo.py | 2 +- mmdet3d/apis/inferencers/base_3d_inferencer.py | 3 ++- mmdet3d/apis/inferencers/mono_det3d_inferencer.py | 7 +++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/demo/mono_det_demo.py b/demo/mono_det_demo.py index 42416fd9f4..6fa70d985a 100644 --- a/demo/mono_det_demo.py +++ b/demo/mono_det_demo.py @@ -57,7 +57,7 @@ def parse_args(): call_args['inputs'] = dict( img=call_args.pop('img'), infos=call_args.pop('infos')) - call_args.pop('cam_type') + # call_args.pop('cam_type') if call_args['no_save_vis'] and call_args['no_save_pred']: call_args['out_dir'] = '' diff --git a/mmdet3d/apis/inferencers/base_3d_inferencer.py b/mmdet3d/apis/inferencers/base_3d_inferencer.py index 6564325e8c..173016fdff 100644 --- a/mmdet3d/apis/inferencers/base_3d_inferencer.py +++ b/mmdet3d/apis/inferencers/base_3d_inferencer.py @@ -167,7 +167,8 @@ def _dispatch_kwargs(self, kwargs['img_out_dir'] = out_dir kwargs['pred_out_dir'] = out_dir if cam_type != '': - kwargs['cam_type_dir'] = cam_type + kwargs['cam_type'] = cam_type + # kwargs['cam_type_dir'] = cam_type return super()._dispatch_kwargs(**kwargs) def __call__(self, diff --git a/mmdet3d/apis/inferencers/mono_det3d_inferencer.py b/mmdet3d/apis/inferencers/mono_det3d_inferencer.py index 22863ae166..82a23e52d0 100644 --- a/mmdet3d/apis/inferencers/mono_det3d_inferencer.py +++ b/mmdet3d/apis/inferencers/mono_det3d_inferencer.py @@ -117,6 +117,13 @@ def _inputs_to_list(self, lidar2cam = np.asarray( data_info['images'][cam_type]['lidar2cam'], dtype=np.float32) + + if cam2img.shape == (3, 3): + cam2img_fixed = np.eye(4) + cam2img_fixed[:3, :3] = cam2img + cam2img = cam2img_fixed + + if 'lidar2img' in data_info['images'][cam_type]: lidar2img = np.asarray( data_info['images'][cam_type]['lidar2img'],