open-mmlab / mmdetection3d

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

mm3d训练自己的kitti数据集报错。 #2568

Open xqh5201314 opened 1 year ago

xqh5201314 commented 1 year ago

Checklist

  1. The bug has not been fixed in the latest version.

Describe the bug

I made my own point cloud dataset (by using robosense rslidar_16) whicn obtains ".bin" and ".txt". When I started to train with pointpillars ,the bug ocurred as follow.

`Traceback (most recent call last): File "/home/chenyang/anaconda3/envs/mmlab3d/lib/python3.8/site-packages/mmengine/registry/build_functions.py", line 122, in build_from_cfg obj = obj_cls(**args) # type: ignore File "/home/chenyang/mmdetection3d/mmdet3d/datasets/det3d_dataset.py", line 129, in init super().init( File "/home/chenyang/anaconda3/envs/mmlab3d/lib/python3.8/site-packages/mmengine/dataset/base_dataset.py", line 250, in init self.full_init() File "/home/chenyang/anaconda3/envs/mmlab3d/lib/python3.8/site-packages/mmengine/dataset/base_dataset.py", line 310, in full_init self.data_bytes, self.data_address = self._serialize_data() File "/home/chenyang/anaconda3/envs/mmlab3d/lib/python3.8/site-packages/mmengine/dataset/base_dataset.py", line 772, in _serialize_data data_bytes = np.concatenate(data_list) File "<__array_function__ internals>", line 200, in concatenate ValueError: need at least one array to concatenate

Traceback (most recent call last): File "/home/chenyang/anaconda3/envs/mmlab3d/lib/python3.8/site-packages/mmengine/registry/build_functions.py", line 122, in build_from_cfg obj = obj_cls(*args) # type: ignore File "/home/chenyang/anaconda3/envs/mmlab3d/lib/python3.8/site-packages/mmengine/dataset/dataset_wrapper.py", line 211, in init self.dataset = DATASETS.build(dataset) File "/home/chenyang/anaconda3/envs/mmlab3d/lib/python3.8/site-packages/mmengine/registry/registry.py", line 548, in build return self.build_func(cfg, args, **kwargs, registry=self) File "/home/chenyang/anaconda3/envs/mmlab3d/lib/python3.8/site-packages/mmengine/registry/build_functions.py", line 144, in build_from_cfg raise type(e)( ValueError: class MyDataset in mmdet3d/datasets/my_dataset.py: need at least one array to concatenate

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "tools/train.py", line 135, in main() File "tools/train.py", line 131, in main runner.train() File "/home/chenyang/anaconda3/envs/mmlab3d/lib/python3.8/site-packages/mmengine/runner/runner.py", line 1687, in train self._train_loop = self.build_train_loop( File "/home/chenyang/anaconda3/envs/mmlab3d/lib/python3.8/site-packages/mmengine/runner/runner.py", line 1486, in build_train_loop loop = EpochBasedTrainLoop( File "/home/chenyang/anaconda3/envs/mmlab3d/lib/python3.8/site-packages/mmengine/runner/loops.py", line 44, in init super().init(runner, dataloader) File "/home/chenyang/anaconda3/envs/mmlab3d/lib/python3.8/site-packages/mmengine/runner/base_loop.py", line 26, in init self.dataloader = runner.build_dataloader( File "/home/chenyang/anaconda3/envs/mmlab3d/lib/python3.8/site-packages/mmengine/runner/runner.py", line 1346, in build_dataloader dataset = DATASETS.build(dataset_cfg) File "/home/chenyang/anaconda3/envs/mmlab3d/lib/python3.8/site-packages/mmengine/registry/registry.py", line 548, in build return self.build_func(cfg, *args, **kwargs, registry=self) File "/home/chenyang/anaconda3/envs/mmlab3d/lib/python3.8/site-packages/mmengine/registry/build_functions.py", line 144, in build_from_cfg raise type(e)( ValueError: class RepeatDataset in mmengine/dataset/dataset_wrapper.py: class MyDataset in mmdet3d/datasets/my_dataset.py: need at least one array to concatenate `

custom.py:

`# dataset settings dataset_type = 'MyDataset' data_root = 'data/my_data/' class_names = ['pedestrian', 'bicycle', 'car'] # replace with your dataset class point_cloud_range = [-40, -40, -2, 70.4, 40, 2] # adjust according to your dataset input_modality = dict(use_lidar=True, use_camera=False) metainfo = dict(classes=class_names)

train_pipeline = [ dict( type='LoadPointsFromFile', coord_type='LIDAR', load_dim=4, # replace with your point cloud data dimension use_dim=4), # replace with the actual dimension used in training and inference dict( type='LoadAnnotations3D', with_bbox_3d=True, with_label_3d=True), dict( type='ObjectNoise', num_try=100, translation_std=[1.0, 1.0, 0.5], global_rot_range=[0.0, 0.0], rot_range=[-0.78539816, 0.78539816]), dict(type='RandomFlip3D', flip_ratio_bev_horizontal=0.5), dict( type='GlobalRotScaleTrans', rot_range=[-0.78539816, 0.78539816], scale_ratio_range=[0.95, 1.05]), dict(type='PointsRangeFilter', point_cloud_range=point_cloud_range), dict(type='ObjectRangeFilter', point_cloud_range=point_cloud_range), dict(type='PointShuffle'), dict( type='Pack3DDetInputs',

keys=['points', 'gt_bboxes_3d', 'gt_labels_3d']

    keys=['points']
    )

] test_pipeline = [ dict( type='LoadPointsFromFile', coord_type='LIDAR', load_dim=4, # replace with your point cloud data dimension use_dim=4), dict(type='Pack3DDetInputs', keys=['points']) ] eval_pipeline = [ dict(type='LoadPointsFromFile', coord_type='LIDAR', load_dim=4, use_dim=4), dict(type='Pack3DDetInputs', keys=['points']), ] train_dataloader = dict( batch_size=6, num_workers=4, persistent_workers=True, sampler=dict(type='DefaultSampler', shuffle=True), dataset=dict( type='RepeatDataset', times=2, dataset=dict( type=dataset_type, data_root=data_root, ann_file='my_data_infos_train.pkl', # specify your training pkl info data_prefix=dict(pts='points'), pipeline=train_pipeline, modality=input_modality, test_mode=False, metainfo=metainfo, box_type_3d='LiDAR'))) val_dataloader = dict( batch_size=1, num_workers=1, persistent_workers=True, drop_last=False, sampler=dict(type='DefaultSampler', shuffle=False), dataset=dict( type=dataset_type, data_root=data_root, data_prefix=dict(pts='points'), ann_file='my_data_infos_val.pkl', # specify your validation pkl info pipeline=test_pipeline, modality=input_modality, test_mode=True, metainfo=metainfo, box_type_3d='LiDAR')) val_evaluator = dict( type='KittiMetric', ann_file=data_root + 'my_data_infos_val.pkl', # specify your validation pkl info metric='bbox') test_dataloader = dict( batch_size=1, num_workers=1, persistent_workers=True, drop_last=False, sampler=dict(type='DefaultSampler', shuffle=False), dataset=dict( type=dataset_type, data_root=data_root, data_prefix=dict(pts='points'), ann_file='my_data_infos_val.pkl', # specify your validation pkl info pipeline=test_pipeline, modality=input_modality, test_mode=True, metainfo=metainfo, box_type_3d='LiDAR')) test_evaluator = dict( type='KittiMetric', ann_file=data_root + 'my_data_infos_val.pkl', # specify your validation pkl info metric='bbox')`

pointpillars_hv_secfpn_custom.py:

`base = [ '../base/models/pointpillars_hv_secfpn_kitti.py', '../base/datasets/custom.py', '../base/schedules/cyclic-40e.py', '../base/default_runtime.py' ] voxel_size = [0.16, 0.16, 4] # adjust according to your dataset point_cloud_range = [-50, -40, -2, 70, 40, 2] # adjust according to your dataset model = dict( type='VoxelNet', data_preprocessor=dict( type='Det3DDataPreprocessor', voxel=True, voxel_layer=dict( max_num_points=32, point_cloud_range=point_cloud_range, voxel_size=voxel_size, max_voxels=(16000, 40000))), voxel_encoder=dict( type='PillarFeatureNet', in_channels=4, feat_channels=[64], with_distance=False, voxel_size=voxel_size, point_cloud_range=point_cloud_range),

the output_shape should be adjusted according to point_cloud_range

# and `voxel_size`
middle_encoder=dict(
    type='PointPillarsScatter', in_channels=64, output_shape=[496, 432]),
backbone=dict(
    type='SECOND',
    in_channels=64,
    layer_nums=[3, 5, 5],
    layer_strides=[2, 2, 2],
    out_channels=[64, 128, 256]),
neck=dict(
    type='SECONDFPN',
    in_channels=[64, 128, 256],
    upsample_strides=[1, 2, 4],
    out_channels=[128, 128, 128]),
bbox_head=dict(
    type='Anchor3DHead',
    num_classes=3,
    in_channels=384,
    feat_channels=384,
    use_direction_classifier=True,
    assign_per_class=True,
    # adjust the `ranges` and `sizes` according to your dataset
    anchor_generator=dict(
        type='AlignedAnchor3DRangeGenerator',
        ranges=[
            [0, -39.68, -0.6, 69.12, 39.68, -0.6],
            [0, -39.68, -0.6, 69.12, 39.68, -0.6],
            [0, -39.68, -1.78, 69.12, 39.68, -1.78],
        ],
        sizes=[[0.8, 0.6, 1.73], [1.76, 0.6, 1.73], [3.9, 1.6, 1.56]],
        rotations=[0, 1.57],
        reshape_out=False),
    diff_rad_by_sin=True,
    bbox_coder=dict(type='DeltaXYZWLHRBBoxCoder'),
    loss_cls=dict(
        type='mmdet.FocalLoss',
        use_sigmoid=True,
        gamma=2.0,
        alpha=0.25,
        loss_weight=1.0),
    loss_bbox=dict(
        type='mmdet.SmoothL1Loss', beta=1.0 / 9.0, loss_weight=2.0),
    loss_dir=dict(
        type='mmdet.CrossEntropyLoss', use_sigmoid=False,
        loss_weight=0.2)),
# model training and testing settings
train_cfg=dict(
    assigner=[
        dict(  # for Pedestrian
            type='Max3DIoUAssigner',
            iou_calculator=dict(type='BboxOverlapsNearest3D'),
            pos_iou_thr=0.5,
            neg_iou_thr=0.35,
            min_pos_iou=0.35,
            ignore_iof_thr=-1),
        dict(  # for Cyclist
            type='Max3DIoUAssigner',
            iou_calculator=dict(type='BboxOverlapsNearest3D'),
            pos_iou_thr=0.5,
            neg_iou_thr=0.35,
            min_pos_iou=0.35,
            ignore_iof_thr=-1),
        dict(  # for Car
            type='Max3DIoUAssigner',
            iou_calculator=dict(type='BboxOverlapsNearest3D'),
            pos_iou_thr=0.6,
            neg_iou_thr=0.45,
            min_pos_iou=0.45,
            ignore_iof_thr=-1),
    ],
    allowed_border=0,
    pos_weight=-1,
    debug=False),
test_cfg=dict(
    use_rotate_nms=True,
    nms_across_levels=False,
    nms_thr=0.01,
    score_thr=0.1,
    min_bbox_size=0,
    nms_pre=100,
    max_num=50))`

Reproduction I used command as follow.

python tools/train.py configs/pointpillars/pointpillars_hv_secfpn_custom.py

@lindahua

mm-assistant[bot] commented 1 year ago

We recommend using English or English & Chinese for issues so that we could have broader discussion.