├── README.md ├── det3 ├── __init__.py ├── dataloader │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-37.pyc │ │ └── kittidata.cpython-37.pyc │ ├── augmentor.py │ ├── basedata.py │ ├── carladata.py │ ├── kittidata.py │ ├── lyftdata.py │ ├── udidata.py │ └── waymodata.py ├── ops │ ├── __init__.py │ ├── boxop.py │ ├── io.py │ ├── iou.py │ ├── ops.py │ └── src │ │ ├── boxop.cpp │ │ ├── boxop_cuda.cpp │ │ ├── boxop_cuda_kernel.cu │ │ ├── iou.cpp │ │ ├── iou_cuda.cpp │ │ ├── iou_cuda_kernel.cu │ │ └── setup.py ├── utils │ ├── __init__.py │ ├── import_tool.py │ ├── log_tool.py │ ├── torch_utils.py │ └── utils.py └── visualizer │ ├── __init__.py │ └── vis.py ├── openpcuct ├── LICENSE ├── data │ └── kitti │ │ └── ImageSets │ │ ├── test.txt │ │ ├── train.txt │ │ └── val.txt ├── docker │ ├── Dockerfile │ └── RTX3090Dockerfile ├── pcdet │ ├── __init__.py │ ├── config.py │ ├── datasets │ │ ├── __init__.py │ │ ├── augmentor │ │ │ ├── __init__.py │ │ │ ├── __pycache__ │ │ │ │ ├── __init__.cpython-37.pyc │ │ │ │ ├── augmentor_utils.cpython-37.pyc │ │ │ │ ├── data_augmentor.cpython-37.pyc │ │ │ │ └── database_sampler.cpython-37.pyc │ │ │ ├── augmentor_utils.py │ │ │ ├── data_augmentor.py │ │ │ └── database_sampler.py │ │ ├── dataset.py │ │ ├── kitti │ │ │ ├── __init__.py │ │ │ ├── __pycache__ │ │ │ │ ├── __init__.cpython-37.pyc │ │ │ │ ├── kitti_dataset.cpython-37.pyc │ │ │ │ └── kitti_utils.cpython-37.pyc │ │ │ ├── kitti_dataset.py │ │ │ ├── kitti_object_eval_python │ │ │ │ ├── LICENSE │ │ │ │ ├── README.md │ │ │ │ ├── __init__.py │ │ │ │ ├── __pycache__ │ │ │ │ │ ├── __init__.cpython-37.pyc │ │ │ │ │ ├── eval.cpython-37.pyc │ │ │ │ │ ├── evaluate.cpython-37.pyc │ │ │ │ │ ├── kitti_common.cpython-37.pyc │ │ │ │ │ └── rotate_iou.cpython-37.pyc │ │ │ │ ├── eval.py │ │ │ │ ├── evaluate.py │ │ │ │ ├── kitti_common.py │ │ │ │ └── rotate_iou.py │ │ │ └── kitti_utils.py │ │ ├── lyft │ │ │ ├── __init__.py │ │ │ ├── __pycache__ │ │ │ │ ├── __init__.cpython-37.pyc │ │ │ │ └── lyft_dataset.cpython-37.pyc │ │ │ ├── lyft_dataset.py │ │ │ ├── lyft_mAP_eval │ │ │ │ ├── __init__.py │ │ │ │ └── lyft_eval.py │ │ │ └── lyft_utils.py │ │ ├── nuscenes │ │ │ ├── __init__.py │ │ │ ├── __pycache__ │ │ │ │ ├── __init__.cpython-37.pyc │ │ │ │ └── nuscenes_dataset.cpython-37.pyc │ │ │ ├── nuscenes_dataset.py │ │ │ └── nuscenes_utils.py │ │ ├── pandaset │ │ │ ├── __init__.py │ │ │ ├── __pycache__ │ │ │ │ ├── __init__.cpython-37.pyc │ │ │ │ └── pandaset_dataset.cpython-37.pyc │ │ │ └── pandaset_dataset.py │ │ ├── processor │ │ │ ├── __init__.py │ │ │ ├── __pycache__ │ │ │ │ ├── __init__.cpython-37.pyc │ │ │ │ ├── data_processor.cpython-37.pyc │ │ │ │ └── point_feature_encoder.cpython-37.pyc │ │ │ ├── data_processor.py │ │ │ └── point_feature_encoder.py │ │ └── waymo │ │ │ ├── __init__.py │ │ │ ├── __pycache__ │ │ │ ├── __init__.cpython-37.pyc │ │ │ └── waymo_dataset.cpython-37.pyc │ │ │ ├── waymo_dataset.py │ │ │ ├── waymo_eval.py │ │ │ └── waymo_utils.py │ ├── models │ │ ├── __init__.py │ │ ├── backbones_2d │ │ │ ├── __init__.py │ │ │ ├── __pycache__ │ │ │ │ ├── __init__.cpython-37.pyc │ │ │ │ └── base_bev_backbone.cpython-37.pyc │ │ │ ├── base_bev_backbone.py │ │ │ └── map_to_bev │ │ │ │ ├── __init__.py │ │ │ │ ├── __pycache__ │ │ │ │ ├── __init__.cpython-37.pyc │ │ │ │ ├── conv2d_collapse.cpython-37.pyc │ │ │ │ ├── height_compression.cpython-37.pyc │ │ │ │ └── pointpillar_scatter.cpython-37.pyc │ │ │ │ ├── conv2d_collapse.py │ │ │ │ ├── height_compression.py │ │ │ │ └── pointpillar_scatter.py │ │ ├── backbones_3d │ │ │ ├── __init__.py │ │ │ ├── __pycache__ │ │ │ │ ├── __init__.cpython-37.pyc │ │ │ │ ├── pointnet2_backbone.cpython-37.pyc │ │ │ │ ├── spconv_backbone.cpython-37.pyc │ │ │ │ └── spconv_unet.cpython-37.pyc │ │ │ ├── pfe │ │ │ │ ├── __init__.py │ │ │ │ ├── __pycache__ │ │ │ │ │ ├── __init__.cpython-37.pyc │ │ │ │ │ └── voxel_set_abstraction.cpython-37.pyc │ │ │ │ └── voxel_set_abstraction.py │ │ │ ├── pointnet2_backbone.py │ │ │ ├── spconv_backbone.py │ │ │ ├── spconv_unet.py │ │ │ └── vfe │ │ │ │ ├── __init__.py │ │ │ │ ├── __pycache__ │ │ │ │ ├── __init__.cpython-37.pyc │ │ │ │ ├── dynamic_mean_vfe.cpython-37.pyc │ │ │ │ ├── dynamic_pillar_vfe.cpython-37.pyc │ │ │ │ ├── image_vfe.cpython-37.pyc │ │ │ │ ├── mean_vfe.cpython-37.pyc │ │ │ │ ├── pillar_vfe.cpython-37.pyc │ │ │ │ └── vfe_template.cpython-37.pyc │ │ │ │ ├── dynamic_mean_vfe.py │ │ │ │ ├── dynamic_pillar_vfe.py │ │ │ │ ├── image_vfe.py │ │ │ │ ├── image_vfe_modules │ │ │ │ ├── __init__.py │ │ │ │ ├── __pycache__ │ │ │ │ │ └── __init__.cpython-37.pyc │ │ │ │ ├── f2v │ │ │ │ │ ├── __init__.py │ │ │ │ │ ├── __pycache__ │ │ │ │ │ │ ├── __init__.cpython-37.pyc │ │ │ │ │ │ ├── frustum_grid_generator.cpython-37.pyc │ │ │ │ │ │ ├── frustum_to_voxel.cpython-37.pyc │ │ │ │ │ │ └── sampler.cpython-37.pyc │ │ │ │ │ ├── frustum_grid_generator.py │ │ │ │ │ ├── frustum_to_voxel.py │ │ │ │ │ └── sampler.py │ │ │ │ └── ffn │ │ │ │ │ ├── __init__.py │ │ │ │ │ ├── __pycache__ │ │ │ │ │ ├── __init__.cpython-37.pyc │ │ │ │ │ └── depth_ffn.cpython-37.pyc │ │ │ │ │ ├── ddn │ │ │ │ │ ├── __init__.py │ │ │ │ │ ├── __pycache__ │ │ │ │ │ │ ├── __init__.cpython-37.pyc │ │ │ │ │ │ ├── ddn_deeplabv3.cpython-37.pyc │ │ │ │ │ │ └── ddn_template.cpython-37.pyc │ │ │ │ │ ├── ddn_deeplabv3.py │ │ │ │ │ └── ddn_template.py │ │ │ │ │ ├── ddn_loss │ │ │ │ │ ├── __init__.py │ │ │ │ │ ├── __pycache__ │ │ │ │ │ │ ├── __init__.cpython-37.pyc │ │ │ │ │ │ ├── balancer.cpython-37.pyc │ │ │ │ │ │ └── ddn_loss.cpython-37.pyc │ │ │ │ │ ├── balancer.py │ │ │ │ │ └── ddn_loss.py │ │ │ │ │ └── depth_ffn.py │ │ │ │ ├── mean_vfe.py │ │ │ │ ├── pillar_vfe.py │ │ │ │ └── vfe_template.py │ │ ├── dense_heads │ │ │ ├── __init__.py │ │ │ ├── __pycache__ │ │ │ │ ├── __init__.cpython-37.pyc │ │ │ │ ├── anchor_head_multi.cpython-37.pyc │ │ │ │ ├── anchor_head_single.cpython-37.pyc │ │ │ │ ├── anchor_head_template.cpython-37.pyc │ │ │ │ ├── center_head.cpython-37.pyc │ │ │ │ ├── point_head_box.cpython-37.pyc │ │ │ │ ├── point_head_simple.cpython-37.pyc │ │ │ │ ├── point_head_template.cpython-37.pyc │ │ │ │ └── point_intra_part_head.cpython-37.pyc │ │ │ ├── anchor_head_multi.py │ │ │ ├── anchor_head_single.py │ │ │ ├── anchor_head_template.py │ │ │ ├── center_head.py │ │ │ ├── point_head_box.py │ │ │ ├── point_head_simple.py │ │ │ ├── point_head_template.py │ │ │ ├── point_intra_part_head.py │ │ │ └── target_assigner │ │ │ │ ├── __init__.py │ │ │ │ ├── __pycache__ │ │ │ │ ├── __init__.cpython-37.pyc │ │ │ │ ├── anchor_generator.cpython-37.pyc │ │ │ │ ├── atss_target_assigner.cpython-37.pyc │ │ │ │ └── axis_aligned_target_assigner.cpython-37.pyc │ │ │ │ ├── anchor_generator.py │ │ │ │ ├── atss_target_assigner.py │ │ │ │ └── axis_aligned_target_assigner.py │ │ ├── detectors │ │ │ ├── PartA2_net.py │ │ │ ├── __init__.py │ │ │ ├── __pycache__ │ │ │ │ ├── PartA2_net.cpython-37.pyc │ │ │ │ ├── __init__.cpython-37.pyc │ │ │ │ ├── caddn.cpython-37.pyc │ │ │ │ ├── centerpoint.cpython-37.pyc │ │ │ │ ├── detector3d_template.cpython-37.pyc │ │ │ │ ├── point_rcnn.cpython-37.pyc │ │ │ │ ├── pointpillar.cpython-37.pyc │ │ │ │ ├── pv_rcnn.cpython-37.pyc │ │ │ │ ├── pv_rcnn_plusplus.cpython-37.pyc │ │ │ │ ├── second_net.cpython-37.pyc │ │ │ │ ├── second_net_iou.cpython-37.pyc │ │ │ │ └── voxel_rcnn.cpython-37.pyc │ │ │ ├── caddn.py │ │ │ ├── centerpoint.py │ │ │ ├── detector3d_template.py │ │ │ ├── point_rcnn.py │ │ │ ├── pointpillar.py │ │ │ ├── pv_rcnn.py │ │ │ ├── pv_rcnn_plusplus.py │ │ │ ├── second_net.py │ │ │ ├── second_net_iou.py │ │ │ └── voxel_rcnn.py │ │ ├── model_utils │ │ │ ├── __init__.py │ │ │ ├── __pycache__ │ │ │ │ ├── __init__.cpython-37.pyc │ │ │ │ ├── basic_block_2d.cpython-37.pyc │ │ │ │ ├── centernet_utils.cpython-37.pyc │ │ │ │ └── model_nms_utils.cpython-37.pyc │ │ │ ├── basic_block_2d.py │ │ │ ├── centernet_utils.py │ │ │ └── model_nms_utils.py │ │ └── roi_heads │ │ │ ├── __init__.py │ │ │ ├── __pycache__ │ │ │ ├── __init__.cpython-37.pyc │ │ │ ├── partA2_head.cpython-37.pyc │ │ │ ├── pointrcnn_head.cpython-37.pyc │ │ │ ├── pvrcnn_head.cpython-37.pyc │ │ │ ├── roi_head_template.cpython-37.pyc │ │ │ ├── second_head.cpython-37.pyc │ │ │ └── voxelrcnn_head.cpython-37.pyc │ │ │ ├── partA2_head.py │ │ │ ├── pointrcnn_head.py │ │ │ ├── pvrcnn_head.py │ │ │ ├── roi_head_template.py │ │ │ ├── second_head.py │ │ │ ├── target_assigner │ │ │ ├── __init__.py │ │ │ ├── __pycache__ │ │ │ │ ├── __init__.cpython-37.pyc │ │ │ │ └── proposal_target_layer.cpython-37.pyc │ │ │ └── proposal_target_layer.py │ │ │ └── voxelrcnn_head.py │ ├── ops │ │ ├── __init__.py │ │ ├── iou3d_nms │ │ │ ├── __init__.py │ │ │ ├── __pycache__ │ │ │ │ ├── __init__.cpython-37.pyc │ │ │ │ └── iou3d_nms_utils.cpython-37.pyc │ │ │ ├── iou3d_nms_utils.py │ │ │ └── src │ │ │ │ ├── iou3d_cpu.cpp │ │ │ │ ├── iou3d_cpu.h │ │ │ │ ├── iou3d_nms.cpp │ │ │ │ ├── iou3d_nms.h │ │ │ │ ├── iou3d_nms_api.cpp │ │ │ │ └── iou3d_nms_kernel.cu │ │ ├── pointnet2 │ │ │ ├── __init__.py │ │ │ ├── __pycache__ │ │ │ │ └── __init__.cpython-37.pyc │ │ │ ├── pointnet2_batch │ │ │ │ ├── __init__.py │ │ │ │ ├── __pycache__ │ │ │ │ │ ├── __init__.cpython-37.pyc │ │ │ │ │ ├── pointnet2_modules.cpython-37.pyc │ │ │ │ │ └── pointnet2_utils.cpython-37.pyc │ │ │ │ ├── pointnet2_modules.py │ │ │ │ ├── pointnet2_utils.py │ │ │ │ └── src │ │ │ │ │ ├── ball_query.cpp │ │ │ │ │ ├── ball_query_gpu.cu │ │ │ │ │ ├── ball_query_gpu.h │ │ │ │ │ ├── cuda_utils.h │ │ │ │ │ ├── group_points.cpp │ │ │ │ │ ├── group_points_gpu.cu │ │ │ │ │ ├── group_points_gpu.h │ │ │ │ │ ├── interpolate.cpp │ │ │ │ │ ├── interpolate_gpu.cu │ │ │ │ │ ├── interpolate_gpu.h │ │ │ │ │ ├── pointnet2_api.cpp │ │ │ │ │ ├── sampling.cpp │ │ │ │ │ ├── sampling_gpu.cu │ │ │ │ │ └── sampling_gpu.h │ │ │ └── pointnet2_stack │ │ │ │ ├── __init__.py │ │ │ │ ├── __pycache__ │ │ │ │ ├── __init__.cpython-37.pyc │ │ │ │ ├── pointnet2_modules.cpython-37.pyc │ │ │ │ ├── pointnet2_utils.cpython-37.pyc │ │ │ │ ├── voxel_pool_modules.cpython-37.pyc │ │ │ │ └── voxel_query_utils.cpython-37.pyc │ │ │ │ ├── pointnet2_modules.py │ │ │ │ ├── pointnet2_utils.py │ │ │ │ ├── src │ │ │ │ ├── ball_query.cpp │ │ │ │ ├── ball_query_gpu.cu │ │ │ │ ├── ball_query_gpu.h │ │ │ │ ├── cuda_utils.h │ │ │ │ ├── group_points.cpp │ │ │ │ ├── group_points_gpu.cu │ │ │ │ ├── group_points_gpu.h │ │ │ │ ├── interpolate.cpp │ │ │ │ ├── interpolate_gpu.cu │ │ │ │ ├── interpolate_gpu.h │ │ │ │ ├── pointnet2_api.cpp │ │ │ │ ├── sampling.cpp │ │ │ │ ├── sampling_gpu.cu │ │ │ │ ├── sampling_gpu.h │ │ │ │ ├── vector_pool.cpp │ │ │ │ ├── vector_pool_gpu.cu │ │ │ │ ├── vector_pool_gpu.h │ │ │ │ ├── voxel_query.cpp │ │ │ │ ├── voxel_query_gpu.cu │ │ │ │ └── voxel_query_gpu.h │ │ │ │ ├── voxel_pool_modules.py │ │ │ │ └── voxel_query_utils.py │ │ ├── roiaware_pool3d │ │ │ ├── __init__.py │ │ │ ├── __pycache__ │ │ │ │ ├── __init__.cpython-37.pyc │ │ │ │ └── roiaware_pool3d_utils.cpython-37.pyc │ │ │ ├── roiaware_pool3d_utils.py │ │ │ └── src │ │ │ │ ├── roiaware_pool3d.cpp │ │ │ │ └── roiaware_pool3d_kernel.cu │ │ └── roipoint_pool3d │ │ │ ├── __init__.py │ │ │ ├── __pycache__ │ │ │ ├── __init__.cpython-37.pyc │ │ │ └── roipoint_pool3d_utils.cpython-37.pyc │ │ │ ├── roipoint_pool3d_utils.py │ │ │ └── src │ │ │ ├── roipoint_pool3d.cpp │ │ │ └── roipoint_pool3d_kernel.cu │ ├── utils │ │ ├── __init__.py │ │ ├── box_coder_utils.py │ │ ├── box_utils.py │ │ ├── calibration_kitti.py │ │ ├── common_utils.py │ │ ├── commu_utils.py │ │ ├── loss_utils.py │ │ ├── object3d_kitti.py │ │ ├── spconv_utils.py │ │ └── transform_utils.py │ └── version.py ├── pcuct │ ├── __init__.py │ ├── datasets │ │ ├── __init__.py │ │ └── kitti │ │ │ ├── __init__.py │ │ │ ├── __pycache__ │ │ │ ├── __init__.cpython-37.pyc │ │ │ └── kitti_dataset.cpython-37.pyc │ │ │ ├── kitti_dataset.py │ │ │ └── kitti_object_eval_python │ │ │ ├── __pycache__ │ │ │ ├── eval.cpython-37.pyc │ │ │ └── kitti_common.cpython-37.pyc │ │ │ ├── eval.py │ │ │ ├── evaluate.py │ │ │ └── kitti_common.py │ ├── gen_model │ │ ├── __init__.py │ │ ├── infer.py │ │ ├── jiou.py │ │ ├── label.py │ │ └── vis.py │ ├── laplace_approx │ │ ├── __init__.py │ │ ├── bayesian_models │ │ │ ├── __init__.py │ │ │ ├── __pycache__ │ │ │ │ ├── __init__.cpython-37.pyc │ │ │ │ ├── point_rcnn.cpython-37.pyc │ │ │ │ ├── pointpillar.cpython-37.pyc │ │ │ │ ├── pv_rcnn.cpython-37.pyc │ │ │ │ └── second_net.cpython-37.pyc │ │ │ ├── point_rcnn.py │ │ │ ├── pointpillar.py │ │ │ ├── pv_rcnn.py │ │ │ └── second_net.py │ │ └── fisher │ │ │ ├── __init__.py │ │ │ ├── __pycache__ │ │ │ ├── __init__.cpython-37.pyc │ │ │ └── fisher.cpython-37.pyc │ │ │ └── fisher.py │ ├── ops │ │ └── jiou │ │ │ ├── __init__.py │ │ │ ├── jiou_utils.py │ │ │ └── src │ │ │ ├── jiou_3d.cpp │ │ │ ├── jiou_bev.cpp │ │ │ ├── utils.cpp │ │ │ └── utils.h │ └── utils │ │ ├── __init__.py │ │ ├── bayesian_utils.py │ │ ├── debug_utils.py │ │ ├── eval_utils.py │ │ └── uct_calib_utils.py ├── setup.py ├── setup_pcuct.py └── tools │ ├── _init_path.py │ ├── analyze_results.py │ ├── calc_weight_uct.py │ ├── cfgs │ ├── dataset_configs │ │ ├── kitti_dataset.yaml │ │ ├── lyft_dataset.yaml │ │ ├── nuscenes_dataset.yaml │ │ ├── pandaset_dataset.yaml │ │ └── waymo_dataset.yaml │ └── kitti_models │ │ ├── CaDDN.yaml │ │ ├── PartA2.yaml │ │ ├── PartA2_free.yaml │ │ ├── pointpillar.yaml │ │ ├── pointpillar_newaugs.yaml │ │ ├── pointpillar_pyramid_aug.yaml │ │ ├── pointrcnn.yaml │ │ ├── pointrcnn_iou.yaml │ │ ├── pv_rcnn.yaml │ │ ├── second.yaml │ │ ├── second_iou.yaml │ │ ├── second_multihead.yaml │ │ └── voxel_rcnn_car.yaml │ ├── demo.py │ ├── deploy_experiments.py │ ├── eval_utils │ ├── __pycache__ │ │ └── eval_utils.cpython-37.pyc │ └── eval_utils.py │ ├── gen_pred_uct.py │ ├── scripts │ ├── clear_gpus.sh │ ├── plot_calibration_plots.py │ ├── reproduce_experiments.py │ └── setup.sh │ ├── test.py │ ├── train.py │ ├── train_utils │ ├── optimization │ │ ├── __init__.py │ │ ├── fastai_optim.py │ │ └── learning_schedules_fastai.py │ └── train_utils.py │ ├── vis_uct.py │ └── visual_utils │ ├── open3d_vis_utils.py │ └── visualize_utils.py └── validate_data ├── experiment_data └── .gitignore └── result_data └── .gitignore /det3/__init__.py: -------------------------------------------------------------------------------- 1 | from . import utils -------------------------------------------------------------------------------- /det3/dataloader/__init__.py: -------------------------------------------------------------------------------- 1 | from . import kittidata -------------------------------------------------------------------------------- /det3/dataloader/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/det3/dataloader/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /det3/dataloader/__pycache__/kittidata.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/det3/dataloader/__pycache__/kittidata.cpython-37.pyc -------------------------------------------------------------------------------- /det3/ops/__init__.py: -------------------------------------------------------------------------------- 1 | from det3.ops.ops import * -------------------------------------------------------------------------------- /det3/ops/io.py: -------------------------------------------------------------------------------- 1 | ''' 2 | File Created: Sat Feb 29 2020 3 | 4 | ''' 5 | import json 6 | import pickle 7 | import numpy as np 8 | from PIL import Image 9 | 10 | def read_txt_(path:str): 11 | with open(path, 'r') as f: 12 | l = f.readlines() 13 | l = [itm.rstrip() for itm in l] 14 | return l 15 | 16 | def write_txt_(obj:list, path:str): 17 | s = "\n".join(obj) 18 | with open(path, 'w+') as f: 19 | f.write(s) 20 | 21 | def read_npy_(path:str): 22 | surf = path.split(".")[-1] 23 | assert surf == "npy" 24 | p = np.load(path) 25 | assert not np.isnan(np.sum(p)) 26 | return p 27 | 28 | def write_npy_(obj:np.ndarray, path:str): 29 | surf = path.split(".")[-1] 30 | assert surf == "npy" 31 | np.save(path, obj) 32 | 33 | def read_pcd_(path:str): 34 | import open3d 35 | surf = path.split(".")[-1] 36 | assert surf == "pcd" 37 | pcd = open3d.io.read_point_cloud(path) 38 | return np.asarray(pcd.points) 39 | 40 | def write_pcd_(obj:np.ndarray, path:str): 41 | import open3d 42 | surf = path.split(".")[-1] 43 | assert surf == "pcd" 44 | pcd = open3d.geometry.PointCloud() 45 | pcd.points = open3d.utility.Vector3dVector(obj) 46 | open3d.io.write_point_cloud(path, pcd) 47 | 48 | def read_bin_(path:str, dtype): 49 | return np.fromfile(path, dtype=dtype) 50 | 51 | def write_bin_(obj:np.ndarray, path:str): 52 | with open(path, 'wb') as f: 53 | obj.tofile(f) 54 | 55 | def read_img_(path:str): 56 | return np.array(Image.open(path, 'r')) 57 | 58 | def write_img_(obj:np.ndarray, path:str): 59 | Image.fromarray(obj).save(path) 60 | 61 | def read_pkl_(path:str): 62 | with open(path, 'rb') as f: 63 | pkl = pickle.load(f) 64 | return pkl 65 | 66 | def write_pkl_(obj, path:str): 67 | with open(path, 'wb') as f: 68 | pickle.dump(obj, f) 69 | 70 | def read_json_(path:str): 71 | with open(path, encoding='utf-8') as f: 72 | res = f.read() 73 | result = json.loads(res) 74 | return result 75 | -------------------------------------------------------------------------------- /det3/ops/src/boxop.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * File Created: Mon Mar 02 2020 3 | 4 | */ 5 | 6 | #include 7 | 8 | torch::Tensor get_corner_box_2drot(torch::Tensor boxes){ 9 | // auto device = boxes.device(); 10 | // auto dtype = boxes.dtype(); 11 | // auto options = torch::TensorOptions().device(device).dtype(dtype); 12 | // auto M = boxes.size(0); 13 | auto l = boxes.narrow(1, 2, 1); 14 | auto w = boxes.narrow(1, 3, 1); 15 | auto theta = boxes.narrow(1, 4, 1); 16 | auto p1 = torch::stack({-l/2.0, w/2.0}, /*dim=*/1); 17 | auto p2 = torch::stack({ l/2.0, w/2.0}, /*dim=*/1); 18 | auto p3 = torch::stack({ l/2.0,-w/2.0}, /*dim=*/1); 19 | auto p4 = torch::stack({-l/2.0,-w/2.0}, /*dim=*/1); 20 | auto pts = torch::stack({p1, p2, p3, p4}, /*dim=*/0) 21 | .transpose(0, 1).squeeze(); 22 | auto tr_vecs = boxes.narrow(1, 0, 2).unsqueeze(1).repeat({1, 4, 1}); 23 | auto cry = torch::cos(theta); auto sry = torch::sin(theta); 24 | auto R_r0 = torch::stack({cry, -sry}, /*dim=*/1).squeeze(); 25 | auto R_r1 = torch::stack({sry, cry}, /*dim=*/1).squeeze(); 26 | auto R = torch::stack({R_r0, R_r1}, /*dim=*/1); 27 | pts = torch::bmm(R, pts.transpose(-2, -1)).transpose(-2, -1); 28 | pts += tr_vecs; 29 | return pts; 30 | } 31 | 32 | PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) { 33 | m.def("get_corner_box_2drot", &get_corner_box_2drot, "get_corner_box_2drot"); 34 | } -------------------------------------------------------------------------------- /det3/ops/src/boxop_cuda.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * File Created: Thu Mar 05 2020 3 | 4 | */ 5 | #include 6 | #include 7 | 8 | // CUDA declarations 9 | torch::Tensor crop_pts_3drot_cuda( 10 | torch::Tensor boxes, 11 | torch::Tensor pts); 12 | 13 | // C++ interface 14 | #define CHECK_CUDA(x) TORCH_CHECK(x.type().is_cuda(), #x " must be a CUDA tensor") 15 | #define CHECK_CONTIGUOUS(x) TORCH_CHECK(x.is_contiguous(), #x " must be contiguous") 16 | #define CHECK_INPUT(x) CHECK_CUDA(x); CHECK_CONTIGUOUS(x) 17 | 18 | torch::Tensor crop_pts_3drot( 19 | torch::Tensor boxes, 20 | torch::Tensor pts) 21 | { 22 | CHECK_INPUT(boxes); 23 | CHECK_INPUT(pts); 24 | return crop_pts_3drot_cuda(boxes, pts); 25 | } 26 | 27 | PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) { 28 | m.def("crop_pts_3drot", &crop_pts_3drot, "crop_pts_3drot (CUDA)"); 29 | } -------------------------------------------------------------------------------- /det3/ops/src/iou.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * File Created: Mon Mar 02 2020 3 | 4 | */ 5 | 6 | #include 7 | 8 | torch::Tensor compute_intersect_2d(torch::Tensor box, torch::Tensor others) { 9 | auto box_x = box[0]; auto box_y = box[1]; 10 | auto box_l = box[2]; auto box_w = box[3]; 11 | auto box_xmin = box_x - box_l/2.0; 12 | auto box_xmax = box_x + box_l/2.0; 13 | auto box_ymin = box_y - box_w/2.0; 14 | auto box_ymax = box_y + box_w/2.0; 15 | auto others_x = others.narrow(1, 0, 1); 16 | auto others_y = others.narrow(1, 1, 1); 17 | auto others_l = others.narrow(1, 2, 1); 18 | auto others_w = others.narrow(1, 3, 1); 19 | auto others_xmin = others_x - others_l/2.0; 20 | auto others_ymin = others_y - others_w/2.0; 21 | auto others_xmax = others_x + others_l/2.0; 22 | auto others_ymax = others_y + others_w/2.0; 23 | auto xx1 = torch::max(box_xmin, others_xmin); 24 | auto yy1 = torch::max(box_ymin, others_ymin); 25 | auto xx2 = torch::min(box_xmax, others_xmax); 26 | auto yy2 = torch::min(box_ymax, others_ymax); 27 | auto w = torch::clamp(xx2 - xx1, 0.0, std::numeric_limits::infinity()); 28 | auto h = torch::clamp(yy2 - yy1, 0.0, std::numeric_limits::infinity()); 29 | return (w * h).flatten(); 30 | } 31 | 32 | PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) { 33 | m.def("compute_intersect_2d", &compute_intersect_2d, "compute_intersect_2d"); 34 | } -------------------------------------------------------------------------------- /det3/ops/src/iou_cuda.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * File Created: Wed Mar 04 2020 3 | 4 | * This is converted from the python code: 5 | * https://github.com/traveller59/second.pytorch/blob/master/second/core/non_max_suppression/ 6 | * https://github.com/hongzhenwang/RRPN-revise/tree/master/lib/rotation 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | // CUDA declarations 13 | torch::Tensor compute_intersect_2drot_cuda( 14 | torch::Tensor boxes, 15 | torch::Tensor query_boxes); 16 | 17 | // C++ interface 18 | #define CHECK_CUDA(x) TORCH_CHECK(x.type().is_cuda(), #x " must be a CUDA tensor") 19 | #define CHECK_CONTIGUOUS(x) TORCH_CHECK(x.is_contiguous(), #x " must be contiguous") 20 | #define CHECK_INPUT(x) CHECK_CUDA(x); CHECK_CONTIGUOUS(x) 21 | 22 | torch::Tensor compute_intersect_2drot( 23 | torch::Tensor boxes, 24 | torch::Tensor query_boxes) 25 | { 26 | CHECK_INPUT(boxes); 27 | CHECK_INPUT(query_boxes); 28 | return compute_intersect_2drot_cuda(boxes, query_boxes); 29 | } 30 | 31 | PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) { 32 | m.def("compute_intersect_2drot", &compute_intersect_2drot, "compute_intersect_2drot (CUDA)"); 33 | } -------------------------------------------------------------------------------- /det3/ops/src/setup.py: -------------------------------------------------------------------------------- 1 | ''' 2 | File Created: Mon Mar 02 2020 3 | 4 | ''' 5 | 6 | from setuptools import setup, Extension 7 | from torch.utils import cpp_extension 8 | 9 | setup(name='iou_cpp', 10 | ext_modules=[cpp_extension.CppExtension('iou_cpp', ['iou.cpp'])], 11 | cmdclass={'build_ext': cpp_extension.BuildExtension}) 12 | setup(name='boxop_cpp', 13 | ext_modules=[cpp_extension.CppExtension('boxop_cpp', ['boxop.cpp'])], 14 | cmdclass={'build_ext': cpp_extension.BuildExtension}) 15 | setup(name='iou_cuda', 16 | ext_modules=[cpp_extension.CUDAExtension('iou_cuda', ['iou_cuda.cpp', 'iou_cuda_kernel.cu'])], 17 | cmdclass={'build_ext': cpp_extension.BuildExtension}) 18 | setup(name='boxop_cuda', 19 | ext_modules=[cpp_extension.CUDAExtension('boxop_cuda', ['boxop_cuda.cpp', 'boxop_cuda_kernel.cu'])], 20 | cmdclass={'build_ext': cpp_extension.BuildExtension}) -------------------------------------------------------------------------------- /det3/utils/__init__.py: -------------------------------------------------------------------------------- 1 | from . import utils -------------------------------------------------------------------------------- /det3/utils/import_tool.py: -------------------------------------------------------------------------------- 1 | import importlib.util 2 | 3 | def load_module(path, name): 4 | ''' 5 | Note: this function will make the decorator of a function 6 | works more than one times. 7 | ''' 8 | spec = importlib.util.spec_from_file_location(name, path) 9 | foo = importlib.util.module_from_spec(spec) 10 | spec.loader.exec_module(foo) 11 | return getattr(foo, name) 12 | -------------------------------------------------------------------------------- /det3/visualizer/__init__.py: -------------------------------------------------------------------------------- 1 | from . import vis -------------------------------------------------------------------------------- /openpcuct/docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM nvidia/cuda:10.2-cudnn7-devel-ubuntu18.04 2 | 3 | RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections 4 | 5 | # Fix the apt-get error from nvidia-docker 6 | RUN rm /etc/apt/sources.list.d/cuda.list 7 | RUN rm /etc/apt/sources.list.d/nvidia-ml.list 8 | RUN apt-key del 7fa2af80 9 | RUN apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/3bf863cc.pub 10 | RUN apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/7fa2af80.pub 11 | 12 | # Install basics 13 | RUN apt-get update -y \ 14 | && apt-get install build-essential \ 15 | && apt-get install -y apt-utils git curl ca-certificates bzip2 tree htop wget \ 16 | && apt-get install -y libglib2.0-0 libsm6 libxext6 libxrender-dev bmon iotop g++ python3.7 python3.7-dev python3.7-distutils 17 | 18 | # Install cmake v3.13.2 19 | RUN apt-get purge -y cmake && \ 20 | mkdir /root/temp && \ 21 | cd /root/temp && \ 22 | wget https://github.com/Kitware/CMake/releases/download/v3.13.2/cmake-3.13.2.tar.gz && \ 23 | tar -xzvf cmake-3.13.2.tar.gz && \ 24 | cd cmake-3.13.2 && \ 25 | bash ./bootstrap && \ 26 | make && \ 27 | make install && \ 28 | cmake --version && \ 29 | rm -rf /root/temp 30 | 31 | # Install python 32 | ENV LANG=C.UTF-8 LC_ALL=C.UTF-8 33 | ENV PATH /opt/conda/bin:$PATH 34 | 35 | RUN apt-get update --fix-missing && \ 36 | apt-get install -y wget bzip2 ca-certificates curl git && \ 37 | apt-get clean && \ 38 | rm -rf /var/lib/apt/lists/* 39 | 40 | RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-4.7.12.1-Linux-x86_64.sh -O ~/miniconda.sh && \ 41 | /bin/bash ~/miniconda.sh -b -p /opt/conda && \ 42 | rm ~/miniconda.sh && \ 43 | /opt/conda/bin/conda clean -tipsy && \ 44 | ln -s /opt/conda/etc/profile.d/conda.sh /etc/profile.d/conda.sh && \ 45 | echo ". /opt/conda/etc/profile.d/conda.sh" >> ~/.bashrc && \ 46 | echo "conda activate base" >> ~/.bashrc 47 | 48 | ENV TINI_VERSION v0.18.0 49 | ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /usr/bin/tini 50 | RUN chmod +x /usr/bin/tini 51 | 52 | ENTRYPOINT [ "/usr/bin/tini", "--" ] 53 | CMD [ "/bin/bash" ] 54 | 55 | # Install python packages 56 | RUN conda install numpy llvmlite numba -c conda-forge 57 | # Install torch and torchvision 58 | # See https://pytorch.org/ for other options if you use a different version of CUDA 59 | RUN conda install pytorch==1.10.1 torchvision==0.11.2 torchaudio==0.10.1 cudatoolkit=10.2 -c pytorch 60 | 61 | # Install python packages 62 | RUN conda install tensorboardX==2.0 easydict==1.9 tqdm -c conda-forge 63 | RUN conda install scikit-image==0.19.2 pyyaml==6.0 six==1.16.0 sharedarray==3.2.1 -c conda-forge 64 | RUN conda install wandb==0.12.14 pandas==1.3.5 matplotlib==3.5.1 -c conda-forge 65 | 66 | # Install Boost geometry 67 | RUN wget https://jaist.dl.sourceforge.net/project/boost/boost/1.68.0/boost_1_68_0.tar.gz && \ 68 | tar xzvf boost_1_68_0.tar.gz && \ 69 | cp -r ./boost_1_68_0/boost /usr/include && \ 70 | rm -rf ./boost_1_68_0 && \ 71 | rm -rf ./boost_1_68_0.tar.gz 72 | 73 | # A weired problem that hasn't been solved yet 74 | RUN pip uninstall -y SharedArray && \ 75 | pip install SharedArray 76 | 77 | RUN pip install spconv-cu102 78 | 79 | ENV PYTHONPATH /usr/app -------------------------------------------------------------------------------- /openpcuct/docker/RTX3090Dockerfile: -------------------------------------------------------------------------------- 1 | FROM nvidia/cuda:11.3.1-cudnn8-devel-ubuntu18.04 2 | 3 | RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections 4 | 5 | # Fix the apt-get error from nvidia-docker 6 | RUN rm /etc/apt/sources.list.d/cuda.list 7 | RUN rm /etc/apt/sources.list.d/nvidia-ml.list 8 | RUN apt-key del 7fa2af80 9 | RUN apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/3bf863cc.pub 10 | RUN apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/7fa2af80.pub 11 | 12 | # Install basics 13 | RUN apt-get update -y \ 14 | && apt-get install build-essential \ 15 | && apt-get install -y apt-utils git curl ca-certificates bzip2 tree htop wget \ 16 | && apt-get install -y libglib2.0-0 libsm6 libxext6 libxrender-dev bmon iotop g++ python3.7 python3.7-dev python3.7-distutils 17 | 18 | # Install cmake v3.13.2 19 | RUN apt-get purge -y cmake && \ 20 | mkdir /root/temp && \ 21 | cd /root/temp && \ 22 | wget https://github.com/Kitware/CMake/releases/download/v3.13.2/cmake-3.13.2.tar.gz && \ 23 | tar -xzvf cmake-3.13.2.tar.gz && \ 24 | cd cmake-3.13.2 && \ 25 | bash ./bootstrap && \ 26 | make && \ 27 | make install && \ 28 | cmake --version && \ 29 | rm -rf /root/temp 30 | 31 | # Install python 32 | ENV LANG=C.UTF-8 LC_ALL=C.UTF-8 33 | ENV PATH /opt/conda/bin:$PATH 34 | 35 | RUN apt-get update --fix-missing && \ 36 | apt-get install -y wget bzip2 ca-certificates curl git && \ 37 | apt-get clean && \ 38 | rm -rf /var/lib/apt/lists/* 39 | 40 | RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-4.7.12.1-Linux-x86_64.sh -O ~/miniconda.sh && \ 41 | /bin/bash ~/miniconda.sh -b -p /opt/conda && \ 42 | rm ~/miniconda.sh && \ 43 | /opt/conda/bin/conda clean -tipsy && \ 44 | ln -s /opt/conda/etc/profile.d/conda.sh /etc/profile.d/conda.sh && \ 45 | echo ". /opt/conda/etc/profile.d/conda.sh" >> ~/.bashrc && \ 46 | echo "conda activate base" >> ~/.bashrc 47 | 48 | ENV TINI_VERSION v0.18.0 49 | ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /usr/bin/tini 50 | RUN chmod +x /usr/bin/tini 51 | 52 | ENTRYPOINT [ "/usr/bin/tini", "--" ] 53 | CMD [ "/bin/bash" ] 54 | 55 | # Install python packages 56 | RUN conda install numpy llvmlite numba -c conda-forge 57 | # Install torch and torchvision 58 | # See https://pytorch.org/ for other options if you use a different version of CUDA 59 | RUN conda install pytorch==1.10.1 torchvision==0.11.2 torchaudio==0.10.1 cudatoolkit=11.3 -c pytorch -c conda-forge 60 | 61 | # Install python packages 62 | RUN conda install tensorboardX==2.0 easydict==1.9 tqdm -c conda-forge 63 | RUN conda install scikit-image==0.19.2 pyyaml==6.0 six==1.16.0 sharedarray==3.2.1 -c conda-forge 64 | RUN conda install wandb==0.12.14 pandas==1.3.5 matplotlib==3.5.1 -c conda-forge 65 | 66 | # Install Boost geometry 67 | RUN wget https://jaist.dl.sourceforge.net/project/boost/boost/1.68.0/boost_1_68_0.tar.gz && \ 68 | tar xzvf boost_1_68_0.tar.gz && \ 69 | cp -r ./boost_1_68_0/boost /usr/include && \ 70 | rm -rf ./boost_1_68_0 && \ 71 | rm -rf ./boost_1_68_0.tar.gz 72 | 73 | # A weired problem that hasn't been solved yet 74 | RUN pip uninstall -y SharedArray && \ 75 | pip install SharedArray 76 | 77 | RUN pip install spconv-cu113 78 | 79 | ENV PYTHONPATH /usr/app -------------------------------------------------------------------------------- /openpcuct/pcdet/__init__.py: -------------------------------------------------------------------------------- 1 | import subprocess 2 | from pathlib import Path 3 | 4 | from .version import __version__ 5 | 6 | __all__ = [ 7 | '__version__' 8 | ] 9 | 10 | 11 | def get_git_commit_number(): 12 | if not (Path(__file__).parent / '../.git').exists(): 13 | return '0000000' 14 | 15 | cmd_out = subprocess.run(['git', 'rev-parse', 'HEAD'], stdout=subprocess.PIPE) 16 | git_commit_number = cmd_out.stdout.decode('utf-8')[:7] 17 | return git_commit_number 18 | 19 | 20 | script_version = get_git_commit_number() 21 | 22 | 23 | if script_version not in __version__: 24 | __version__ = __version__ + '+py%s' % script_version 25 | -------------------------------------------------------------------------------- /openpcuct/pcdet/config.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import yaml 4 | from easydict import EasyDict 5 | 6 | 7 | def log_config_to_file(cfg, pre='cfg', logger=None): 8 | for key, val in cfg.items(): 9 | if isinstance(cfg[key], EasyDict): 10 | logger.info('\n%s.%s = edict()' % (pre, key)) 11 | log_config_to_file(cfg[key], pre=pre + '.' + key, logger=logger) 12 | continue 13 | logger.info('%s.%s: %s' % (pre, key, val)) 14 | 15 | 16 | def cfg_from_list(cfg_list, config): 17 | """Set config keys via list (e.g., from command line).""" 18 | from ast import literal_eval 19 | assert len(cfg_list) % 2 == 0 20 | for k, v in zip(cfg_list[0::2], cfg_list[1::2]): 21 | key_list = k.split('.') 22 | d = config 23 | for subkey in key_list[:-1]: 24 | assert subkey in d, 'NotFoundKey: %s' % subkey 25 | d = d[subkey] 26 | subkey = key_list[-1] 27 | assert subkey in d, 'NotFoundKey: %s' % subkey 28 | try: 29 | value = literal_eval(v) 30 | except: 31 | value = v 32 | 33 | if type(value) != type(d[subkey]) and isinstance(d[subkey], EasyDict): 34 | key_val_list = value.split(',') 35 | for src in key_val_list: 36 | cur_key, cur_val = src.split(':') 37 | val_type = type(d[subkey][cur_key]) 38 | cur_val = val_type(cur_val) 39 | d[subkey][cur_key] = cur_val 40 | elif type(value) != type(d[subkey]) and isinstance(d[subkey], list): 41 | val_list = value.split(',') 42 | for k, x in enumerate(val_list): 43 | val_list[k] = type(d[subkey][0])(x) 44 | d[subkey] = val_list 45 | else: 46 | assert type(value) == type(d[subkey]), \ 47 | 'type {} does not match original type {}'.format(type(value), type(d[subkey])) 48 | d[subkey] = value 49 | 50 | 51 | def merge_new_config(config, new_config): 52 | if '_BASE_CONFIG_' in new_config: 53 | with open(new_config['_BASE_CONFIG_'], 'r') as f: 54 | try: 55 | yaml_config = yaml.safe_load(f, Loader=yaml.FullLoader) 56 | except: 57 | yaml_config = yaml.safe_load(f) 58 | config.update(EasyDict(yaml_config)) 59 | 60 | for key, val in new_config.items(): 61 | if not isinstance(val, dict): 62 | config[key] = val 63 | continue 64 | if key not in config: 65 | config[key] = EasyDict() 66 | merge_new_config(config[key], val) 67 | 68 | return config 69 | 70 | 71 | def cfg_from_yaml_file(cfg_file, config): 72 | with open(cfg_file, 'r') as f: 73 | try: 74 | new_config = yaml.safe_load(f, Loader=yaml.FullLoader) 75 | except: 76 | new_config = yaml.safe_load(f) 77 | 78 | merge_new_config(config=config, new_config=new_config) 79 | 80 | return config 81 | 82 | 83 | cfg = EasyDict() 84 | cfg.ROOT_DIR = (Path(__file__).resolve().parent / '../').resolve() 85 | cfg.LOCAL_RANK = 0 86 | -------------------------------------------------------------------------------- /openpcuct/pcdet/datasets/__init__.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from torch.utils.data import DataLoader 3 | from torch.utils.data import DistributedSampler as _DistributedSampler 4 | 5 | from pcdet.utils import common_utils 6 | 7 | from .dataset import DatasetTemplate 8 | from .kitti.kitti_dataset import KittiDataset 9 | from .nuscenes.nuscenes_dataset import NuScenesDataset 10 | from .waymo.waymo_dataset import WaymoDataset 11 | from .pandaset.pandaset_dataset import PandasetDataset 12 | from .lyft.lyft_dataset import LyftDataset 13 | 14 | __all__ = { 15 | 'DatasetTemplate': DatasetTemplate, 16 | 'KittiDataset': KittiDataset, 17 | 'NuScenesDataset': NuScenesDataset, 18 | 'WaymoDataset': WaymoDataset, 19 | 'PandasetDataset': PandasetDataset, 20 | 'LyftDataset': LyftDataset 21 | } 22 | 23 | 24 | class DistributedSampler(_DistributedSampler): 25 | 26 | def __init__(self, dataset, num_replicas=None, rank=None, shuffle=True): 27 | super().__init__(dataset, num_replicas=num_replicas, rank=rank) 28 | self.shuffle = shuffle 29 | 30 | def __iter__(self): 31 | if self.shuffle: 32 | g = torch.Generator() 33 | g.manual_seed(self.epoch) 34 | indices = torch.randperm(len(self.dataset), generator=g).tolist() 35 | else: 36 | indices = torch.arange(len(self.dataset)).tolist() 37 | 38 | indices += indices[:(self.total_size - len(indices))] 39 | assert len(indices) == self.total_size 40 | 41 | indices = indices[self.rank:self.total_size:self.num_replicas] 42 | assert len(indices) == self.num_samples 43 | 44 | return iter(indices) 45 | 46 | 47 | def build_dataloader(dataset_cfg, class_names, batch_size, dist, root_path=None, workers=4, 48 | logger=None, training=True, merge_all_iters_to_one_epoch=False, total_epochs=0): 49 | 50 | dataset = __all__[dataset_cfg.DATASET]( 51 | dataset_cfg=dataset_cfg, 52 | class_names=class_names, 53 | root_path=root_path, 54 | training=training, 55 | logger=logger, 56 | ) 57 | 58 | if merge_all_iters_to_one_epoch: 59 | assert hasattr(dataset, 'merge_all_iters_to_one_epoch') 60 | dataset.merge_all_iters_to_one_epoch(merge=True, epochs=total_epochs) 61 | 62 | if dist: 63 | if training: 64 | sampler = torch.utils.data.distributed.DistributedSampler(dataset) 65 | else: 66 | rank, world_size = common_utils.get_dist_info() 67 | sampler = DistributedSampler(dataset, world_size, rank, shuffle=False) 68 | else: 69 | sampler = None 70 | dataloader = DataLoader( 71 | dataset, batch_size=batch_size, pin_memory=True, num_workers=workers, 72 | shuffle=(sampler is None) and training, collate_fn=dataset.collate_batch, 73 | drop_last=False, sampler=sampler, timeout=0 74 | ) 75 | 76 | return dataset, dataloader, sampler 77 | -------------------------------------------------------------------------------- /openpcuct/pcdet/datasets/augmentor/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/datasets/augmentor/__init__.py -------------------------------------------------------------------------------- /openpcuct/pcdet/datasets/augmentor/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/datasets/augmentor/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/datasets/augmentor/__pycache__/augmentor_utils.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/datasets/augmentor/__pycache__/augmentor_utils.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/datasets/augmentor/__pycache__/data_augmentor.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/datasets/augmentor/__pycache__/data_augmentor.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/datasets/augmentor/__pycache__/database_sampler.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/datasets/augmentor/__pycache__/database_sampler.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/datasets/kitti/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/datasets/kitti/__init__.py -------------------------------------------------------------------------------- /openpcuct/pcdet/datasets/kitti/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/datasets/kitti/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/datasets/kitti/__pycache__/kitti_dataset.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/datasets/kitti/__pycache__/kitti_dataset.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/datasets/kitti/__pycache__/kitti_utils.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/datasets/kitti/__pycache__/kitti_utils.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/datasets/kitti/kitti_object_eval_python/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /openpcuct/pcdet/datasets/kitti/kitti_object_eval_python/README.md: -------------------------------------------------------------------------------- 1 | # kitti-object-eval-python 2 | **Note**: This is borrowed from [traveller59/kitti-object-eval-python](https://github.com/traveller59/kitti-object-eval-python) 3 | 4 | Fast kitti object detection eval in python(finish eval in less than 10 second), support 2d/bev/3d/aos. , support coco-style AP. If you use command line interface, numba need some time to compile jit functions. 5 | ## Dependencies 6 | Only support python 3.6+, need `numpy`, `skimage`, `numba`, `fire`. If you have Anaconda, just install `cudatoolkit` in anaconda. Otherwise, please reference to this [page](https://github.com/numba/numba#custom-python-environments) to set up llvm and cuda for numba. 7 | * Install by conda: 8 | ``` 9 | conda install -c numba cudatoolkit=x.x (8.0, 9.0, 9.1, depend on your environment) 10 | ``` 11 | ## Usage 12 | * commandline interface: 13 | ``` 14 | python evaluate.py evaluate --label_path=/path/to/your_gt_label_folder --result_path=/path/to/your_result_folder --label_split_file=/path/to/val.txt --current_class=0 --coco=False 15 | ``` 16 | * python interface: 17 | ```Python 18 | import kitti_common as kitti 19 | from eval import get_official_eval_result, get_coco_eval_result 20 | def _read_imageset_file(path): 21 | with open(path, 'r') as f: 22 | lines = f.readlines() 23 | return [int(line) for line in lines] 24 | det_path = "/path/to/your_result_folder" 25 | dt_annos = kitti.get_label_annos(det_path) 26 | gt_path = "/path/to/your_gt_label_folder" 27 | gt_split_file = "/path/to/val.txt" # from https://xiaozhichen.github.io/files/mv3d/imagesets.tar.gz 28 | val_image_ids = _read_imageset_file(gt_split_file) 29 | gt_annos = kitti.get_label_annos(gt_path, val_image_ids) 30 | print(get_official_eval_result(gt_annos, dt_annos, 0)) # 6s in my computer 31 | print(get_coco_eval_result(gt_annos, dt_annos, 0)) # 18s in my computer 32 | ``` 33 | -------------------------------------------------------------------------------- /openpcuct/pcdet/datasets/kitti/kitti_object_eval_python/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/datasets/kitti/kitti_object_eval_python/__init__.py -------------------------------------------------------------------------------- /openpcuct/pcdet/datasets/kitti/kitti_object_eval_python/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/datasets/kitti/kitti_object_eval_python/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/datasets/kitti/kitti_object_eval_python/__pycache__/eval.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/datasets/kitti/kitti_object_eval_python/__pycache__/eval.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/datasets/kitti/kitti_object_eval_python/__pycache__/evaluate.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/datasets/kitti/kitti_object_eval_python/__pycache__/evaluate.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/datasets/kitti/kitti_object_eval_python/__pycache__/kitti_common.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/datasets/kitti/kitti_object_eval_python/__pycache__/kitti_common.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/datasets/kitti/kitti_object_eval_python/__pycache__/rotate_iou.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/datasets/kitti/kitti_object_eval_python/__pycache__/rotate_iou.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/datasets/kitti/kitti_object_eval_python/evaluate.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | import fire 4 | 5 | import kitti_common as kitti 6 | from .eval import get_coco_eval_result, get_official_eval_result 7 | 8 | 9 | def _read_imageset_file(path): 10 | with open(path, 'r') as f: 11 | lines = f.readlines() 12 | return [int(line) for line in lines] 13 | 14 | 15 | def evaluate(label_path, 16 | result_path, 17 | label_split_file, 18 | current_class=0, 19 | coco=False, 20 | score_thresh=-1): 21 | dt_annos = kitti.get_label_annos(result_path) 22 | if score_thresh > 0: 23 | dt_annos = kitti.filter_annos_low_score(dt_annos, score_thresh) 24 | val_image_ids = _read_imageset_file(label_split_file) 25 | gt_annos = kitti.get_label_annos(label_path, val_image_ids) 26 | if coco: 27 | return get_coco_eval_result(gt_annos, dt_annos, current_class) 28 | else: 29 | return get_official_eval_result(gt_annos, dt_annos, current_class) 30 | 31 | 32 | if __name__ == '__main__': 33 | fire.Fire() 34 | -------------------------------------------------------------------------------- /openpcuct/pcdet/datasets/kitti/kitti_utils.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from ...utils import box_utils 3 | 4 | 5 | def transform_annotations_to_kitti_format(annos, map_name_to_kitti=None, info_with_fakelidar=False): 6 | """ 7 | Args: 8 | annos: 9 | map_name_to_kitti: dict, map name to KITTI names (Car, Pedestrian, Cyclist) 10 | info_with_fakelidar: 11 | Returns: 12 | 13 | """ 14 | for anno in annos: 15 | # For lyft and nuscenes, different anno key in info 16 | if 'name' not in anno: 17 | anno['name'] = anno['gt_names'] 18 | anno.pop('gt_names') 19 | 20 | for k in range(anno['name'].shape[0]): 21 | anno['name'][k] = map_name_to_kitti[anno['name'][k]] 22 | 23 | anno['bbox'] = np.zeros((len(anno['name']), 4)) 24 | anno['bbox'][:, 2:4] = 50 # [0, 0, 50, 50] 25 | anno['truncated'] = np.zeros(len(anno['name'])) 26 | anno['occluded'] = np.zeros(len(anno['name'])) 27 | if 'boxes_lidar' in anno: 28 | gt_boxes_lidar = anno['boxes_lidar'].copy() 29 | else: 30 | gt_boxes_lidar = anno['gt_boxes_lidar'].copy() 31 | 32 | if len(gt_boxes_lidar) > 0: 33 | if info_with_fakelidar: 34 | gt_boxes_lidar = box_utils.boxes3d_kitti_fakelidar_to_lidar(gt_boxes_lidar) 35 | 36 | gt_boxes_lidar[:, 2] -= gt_boxes_lidar[:, 5] / 2 37 | anno['location'] = np.zeros((gt_boxes_lidar.shape[0], 3)) 38 | anno['location'][:, 0] = -gt_boxes_lidar[:, 1] # x = -y_lidar 39 | anno['location'][:, 1] = -gt_boxes_lidar[:, 2] # y = -z_lidar 40 | anno['location'][:, 2] = gt_boxes_lidar[:, 0] # z = x_lidar 41 | dxdydz = gt_boxes_lidar[:, 3:6] 42 | anno['dimensions'] = dxdydz[:, [0, 2, 1]] # lwh ==> lhw 43 | anno['rotation_y'] = -gt_boxes_lidar[:, 6] - np.pi / 2.0 44 | anno['alpha'] = -np.arctan2(-gt_boxes_lidar[:, 1], gt_boxes_lidar[:, 0]) + anno['rotation_y'] 45 | else: 46 | anno['location'] = anno['dimensions'] = np.zeros((0, 3)) 47 | anno['rotation_y'] = anno['alpha'] = np.zeros(0) 48 | 49 | return annos 50 | 51 | 52 | def calib_to_matricies(calib): 53 | """ 54 | Converts calibration object to transformation matricies 55 | Args: 56 | calib: calibration.Calibration, Calibration object 57 | Returns 58 | V2R: (4, 4), Lidar to rectified camera transformation matrix 59 | P2: (3, 4), Camera projection matrix 60 | """ 61 | V2C = np.vstack((calib.V2C, np.array([0, 0, 0, 1], dtype=np.float32))) # (4, 4) 62 | R0 = np.hstack((calib.R0, np.zeros((3, 1), dtype=np.float32))) # (3, 4) 63 | R0 = np.vstack((R0, np.array([0, 0, 0, 1], dtype=np.float32))) # (4, 4) 64 | V2R = R0 @ V2C 65 | P2 = calib.P2 66 | return V2R, P2 -------------------------------------------------------------------------------- /openpcuct/pcdet/datasets/lyft/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/datasets/lyft/__init__.py -------------------------------------------------------------------------------- /openpcuct/pcdet/datasets/lyft/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/datasets/lyft/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/datasets/lyft/__pycache__/lyft_dataset.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/datasets/lyft/__pycache__/lyft_dataset.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/datasets/lyft/lyft_mAP_eval/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/datasets/lyft/lyft_mAP_eval/__init__.py -------------------------------------------------------------------------------- /openpcuct/pcdet/datasets/nuscenes/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/datasets/nuscenes/__init__.py -------------------------------------------------------------------------------- /openpcuct/pcdet/datasets/nuscenes/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/datasets/nuscenes/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/datasets/nuscenes/__pycache__/nuscenes_dataset.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/datasets/nuscenes/__pycache__/nuscenes_dataset.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/datasets/pandaset/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/datasets/pandaset/__init__.py -------------------------------------------------------------------------------- /openpcuct/pcdet/datasets/pandaset/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/datasets/pandaset/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/datasets/pandaset/__pycache__/pandaset_dataset.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/datasets/pandaset/__pycache__/pandaset_dataset.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/datasets/processor/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/datasets/processor/__init__.py -------------------------------------------------------------------------------- /openpcuct/pcdet/datasets/processor/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/datasets/processor/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/datasets/processor/__pycache__/data_processor.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/datasets/processor/__pycache__/data_processor.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/datasets/processor/__pycache__/point_feature_encoder.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/datasets/processor/__pycache__/point_feature_encoder.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/datasets/processor/point_feature_encoder.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | 4 | class PointFeatureEncoder(object): 5 | def __init__(self, config, point_cloud_range=None): 6 | super().__init__() 7 | self.point_encoding_config = config 8 | assert list(self.point_encoding_config.src_feature_list[0:3]) == ['x', 'y', 'z'] 9 | self.used_feature_list = self.point_encoding_config.used_feature_list 10 | self.src_feature_list = self.point_encoding_config.src_feature_list 11 | self.point_cloud_range = point_cloud_range 12 | 13 | @property 14 | def num_point_features(self): 15 | return getattr(self, self.point_encoding_config.encoding_type)(points=None) 16 | 17 | def forward(self, data_dict): 18 | """ 19 | Args: 20 | data_dict: 21 | points: (N, 3 + C_in) 22 | ... 23 | Returns: 24 | data_dict: 25 | points: (N, 3 + C_out), 26 | use_lead_xyz: whether to use xyz as point-wise features 27 | ... 28 | """ 29 | data_dict['points'], use_lead_xyz = getattr(self, self.point_encoding_config.encoding_type)( 30 | data_dict['points'] 31 | ) 32 | data_dict['use_lead_xyz'] = use_lead_xyz 33 | 34 | if self.point_encoding_config.get('filter_sweeps', False) and 'timestamp' in self.src_feature_list: 35 | max_sweeps = self.point_encoding_config.max_sweeps 36 | idx = self.src_feature_list.index('timestamp') 37 | dt = np.round(data_dict['points'][:, idx], 2) 38 | max_dt = sorted(np.unique(dt))[min(len(np.unique(dt))-1, max_sweeps-1)] 39 | data_dict['points'] = data_dict['points'][dt <= max_dt] 40 | 41 | return data_dict 42 | 43 | def absolute_coordinates_encoding(self, points=None): 44 | if points is None: 45 | num_output_features = len(self.used_feature_list) 46 | return num_output_features 47 | 48 | point_feature_list = [points[:, 0:3]] 49 | for x in self.used_feature_list: 50 | if x in ['x', 'y', 'z']: 51 | continue 52 | idx = self.src_feature_list.index(x) 53 | point_feature_list.append(points[:, idx:idx+1]) 54 | point_features = np.concatenate(point_feature_list, axis=1) 55 | 56 | return point_features, True 57 | -------------------------------------------------------------------------------- /openpcuct/pcdet/datasets/waymo/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/datasets/waymo/__init__.py -------------------------------------------------------------------------------- /openpcuct/pcdet/datasets/waymo/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/datasets/waymo/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/datasets/waymo/__pycache__/waymo_dataset.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/datasets/waymo/__pycache__/waymo_dataset.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/__init__.py: -------------------------------------------------------------------------------- 1 | from collections import namedtuple 2 | 3 | import numpy as np 4 | import torch 5 | 6 | from .detectors import build_detector 7 | 8 | try: 9 | import kornia 10 | except: 11 | pass 12 | # print('Warning: kornia is not installed. This package is only required by CaDDN') 13 | 14 | 15 | 16 | def build_network(model_cfg, num_class, dataset): 17 | model = build_detector( 18 | model_cfg=model_cfg, num_class=num_class, dataset=dataset 19 | ) 20 | return model 21 | 22 | 23 | def load_data_to_gpu(batch_dict): 24 | for key, val in batch_dict.items(): 25 | if not isinstance(val, np.ndarray): 26 | continue 27 | elif key in ['frame_id', 'metadata', 'calib']: 28 | continue 29 | elif key in ['images']: 30 | batch_dict[key] = kornia.image_to_tensor(val).float().cuda().contiguous() 31 | elif key in ['image_shape']: 32 | batch_dict[key] = torch.from_numpy(val).int().cuda() 33 | else: 34 | batch_dict[key] = torch.from_numpy(val).float().cuda() 35 | 36 | 37 | def model_fn_decorator(): 38 | ModelReturn = namedtuple('ModelReturn', ['loss', 'tb_dict', 'disp_dict']) 39 | 40 | def model_func(model, batch_dict): 41 | load_data_to_gpu(batch_dict) 42 | ret_dict, tb_dict, disp_dict = model(batch_dict) 43 | 44 | loss = ret_dict['loss'].mean() 45 | if hasattr(model, 'update_global_step'): 46 | model.update_global_step() 47 | else: 48 | model.module.update_global_step() 49 | 50 | return ModelReturn(loss, tb_dict, disp_dict) 51 | 52 | return model_func 53 | -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_2d/__init__.py: -------------------------------------------------------------------------------- 1 | from .base_bev_backbone import BaseBEVBackbone 2 | 3 | __all__ = { 4 | 'BaseBEVBackbone': BaseBEVBackbone 5 | } 6 | -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_2d/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/backbones_2d/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_2d/__pycache__/base_bev_backbone.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/backbones_2d/__pycache__/base_bev_backbone.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_2d/map_to_bev/__init__.py: -------------------------------------------------------------------------------- 1 | from .height_compression import HeightCompression 2 | from .pointpillar_scatter import PointPillarScatter 3 | from .conv2d_collapse import Conv2DCollapse 4 | 5 | __all__ = { 6 | 'HeightCompression': HeightCompression, 7 | 'PointPillarScatter': PointPillarScatter, 8 | 'Conv2DCollapse': Conv2DCollapse 9 | } 10 | -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_2d/map_to_bev/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/backbones_2d/map_to_bev/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_2d/map_to_bev/__pycache__/conv2d_collapse.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/backbones_2d/map_to_bev/__pycache__/conv2d_collapse.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_2d/map_to_bev/__pycache__/height_compression.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/backbones_2d/map_to_bev/__pycache__/height_compression.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_2d/map_to_bev/__pycache__/pointpillar_scatter.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/backbones_2d/map_to_bev/__pycache__/pointpillar_scatter.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_2d/map_to_bev/conv2d_collapse.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn as nn 3 | 4 | from pcdet.models.model_utils.basic_block_2d import BasicBlock2D 5 | 6 | 7 | class Conv2DCollapse(nn.Module): 8 | 9 | def __init__(self, model_cfg, grid_size): 10 | """ 11 | Initializes 2D convolution collapse module 12 | Args: 13 | model_cfg: EasyDict, Model configuration 14 | grid_size: (X, Y, Z) Voxel grid size 15 | """ 16 | super().__init__() 17 | self.model_cfg = model_cfg 18 | self.num_heights = grid_size[-1] 19 | self.num_bev_features = self.model_cfg.NUM_BEV_FEATURES 20 | self.block = BasicBlock2D(in_channels=self.num_bev_features * self.num_heights, 21 | out_channels=self.num_bev_features, 22 | **self.model_cfg.ARGS) 23 | 24 | def forward(self, batch_dict): 25 | """ 26 | Collapses voxel features to BEV via concatenation and channel reduction 27 | Args: 28 | batch_dict: 29 | voxel_features: (B, C, Z, Y, X), Voxel feature representation 30 | Returns: 31 | batch_dict: 32 | spatial_features: (B, C, Y, X), BEV feature representation 33 | """ 34 | voxel_features = batch_dict["voxel_features"] 35 | bev_features = voxel_features.flatten(start_dim=1, end_dim=2) # (B, C, Z, Y, X) -> (B, C*Z, Y, X) 36 | bev_features = self.block(bev_features) # (B, C*Z, Y, X) -> (B, C, Y, X) 37 | batch_dict["spatial_features"] = bev_features 38 | return batch_dict 39 | -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_2d/map_to_bev/height_compression.py: -------------------------------------------------------------------------------- 1 | import torch.nn as nn 2 | 3 | 4 | class HeightCompression(nn.Module): 5 | def __init__(self, model_cfg, **kwargs): 6 | super().__init__() 7 | self.model_cfg = model_cfg 8 | self.num_bev_features = self.model_cfg.NUM_BEV_FEATURES 9 | 10 | def forward(self, batch_dict): 11 | """ 12 | Args: 13 | batch_dict: 14 | encoded_spconv_tensor: sparse tensor 15 | Returns: 16 | batch_dict: 17 | spatial_features: 18 | 19 | """ 20 | encoded_spconv_tensor = batch_dict['encoded_spconv_tensor'] 21 | spatial_features = encoded_spconv_tensor.dense() 22 | N, C, D, H, W = spatial_features.shape 23 | spatial_features = spatial_features.view(N, C * D, H, W) 24 | batch_dict['spatial_features'] = spatial_features 25 | batch_dict['spatial_features_stride'] = batch_dict['encoded_spconv_tensor_stride'] 26 | return batch_dict 27 | -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_2d/map_to_bev/pointpillar_scatter.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn as nn 3 | 4 | 5 | class PointPillarScatter(nn.Module): 6 | def __init__(self, model_cfg, grid_size, **kwargs): 7 | super().__init__() 8 | 9 | self.model_cfg = model_cfg 10 | self.num_bev_features = self.model_cfg.NUM_BEV_FEATURES 11 | self.nx, self.ny, self.nz = grid_size 12 | assert self.nz == 1 13 | 14 | def forward(self, batch_dict, **kwargs): 15 | pillar_features, coords = batch_dict['pillar_features'], batch_dict['voxel_coords'] 16 | batch_spatial_features = [] 17 | batch_size = coords[:, 0].max().int().item() + 1 18 | for batch_idx in range(batch_size): 19 | spatial_feature = torch.zeros( 20 | self.num_bev_features, 21 | self.nz * self.nx * self.ny, 22 | dtype=pillar_features.dtype, 23 | device=pillar_features.device) 24 | 25 | batch_mask = coords[:, 0] == batch_idx 26 | this_coords = coords[batch_mask, :] 27 | indices = this_coords[:, 1] + this_coords[:, 2] * self.nx + this_coords[:, 3] 28 | indices = indices.type(torch.long) 29 | pillars = pillar_features[batch_mask, :] 30 | pillars = pillars.t() 31 | spatial_feature[:, indices] = pillars 32 | batch_spatial_features.append(spatial_feature) 33 | 34 | batch_spatial_features = torch.stack(batch_spatial_features, 0) 35 | batch_spatial_features = batch_spatial_features.view(batch_size, self.num_bev_features * self.nz, self.ny, self.nx) 36 | batch_dict['spatial_features'] = batch_spatial_features 37 | return batch_dict 38 | -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_3d/__init__.py: -------------------------------------------------------------------------------- 1 | from .pointnet2_backbone import PointNet2Backbone, PointNet2MSG 2 | from .spconv_backbone import VoxelBackBone8x, VoxelResBackBone8x 3 | from .spconv_unet import UNetV2 4 | 5 | __all__ = { 6 | 'VoxelBackBone8x': VoxelBackBone8x, 7 | 'UNetV2': UNetV2, 8 | 'PointNet2Backbone': PointNet2Backbone, 9 | 'PointNet2MSG': PointNet2MSG, 10 | 'VoxelResBackBone8x': VoxelResBackBone8x, 11 | } 12 | -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_3d/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/backbones_3d/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_3d/__pycache__/pointnet2_backbone.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/backbones_3d/__pycache__/pointnet2_backbone.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_3d/__pycache__/spconv_backbone.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/backbones_3d/__pycache__/spconv_backbone.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_3d/__pycache__/spconv_unet.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/backbones_3d/__pycache__/spconv_unet.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_3d/pfe/__init__.py: -------------------------------------------------------------------------------- 1 | from .voxel_set_abstraction import VoxelSetAbstraction 2 | 3 | __all__ = { 4 | 'VoxelSetAbstraction': VoxelSetAbstraction 5 | } 6 | -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_3d/pfe/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/backbones_3d/pfe/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_3d/pfe/__pycache__/voxel_set_abstraction.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/backbones_3d/pfe/__pycache__/voxel_set_abstraction.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_3d/vfe/__init__.py: -------------------------------------------------------------------------------- 1 | from .mean_vfe import MeanVFE 2 | from .pillar_vfe import PillarVFE 3 | from .dynamic_mean_vfe import DynamicMeanVFE 4 | from .dynamic_pillar_vfe import DynamicPillarVFE 5 | from .image_vfe import ImageVFE 6 | from .vfe_template import VFETemplate 7 | 8 | __all__ = { 9 | 'VFETemplate': VFETemplate, 10 | 'MeanVFE': MeanVFE, 11 | 'PillarVFE': PillarVFE, 12 | 'ImageVFE': ImageVFE, 13 | 'DynMeanVFE': DynamicMeanVFE, 14 | 'DynPillarVFE': DynamicPillarVFE, 15 | } 16 | -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_3d/vfe/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/backbones_3d/vfe/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_3d/vfe/__pycache__/dynamic_mean_vfe.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/backbones_3d/vfe/__pycache__/dynamic_mean_vfe.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_3d/vfe/__pycache__/dynamic_pillar_vfe.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/backbones_3d/vfe/__pycache__/dynamic_pillar_vfe.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_3d/vfe/__pycache__/image_vfe.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/backbones_3d/vfe/__pycache__/image_vfe.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_3d/vfe/__pycache__/mean_vfe.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/backbones_3d/vfe/__pycache__/mean_vfe.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_3d/vfe/__pycache__/pillar_vfe.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/backbones_3d/vfe/__pycache__/pillar_vfe.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_3d/vfe/__pycache__/vfe_template.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/backbones_3d/vfe/__pycache__/vfe_template.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_3d/vfe/dynamic_mean_vfe.py: -------------------------------------------------------------------------------- 1 | import torch 2 | 3 | from .vfe_template import VFETemplate 4 | 5 | try: 6 | import torch_scatter 7 | except Exception as e: 8 | # Incase someone doesn't want to use dynamic pillar vfe and hasn't installed torch_scatter 9 | pass 10 | 11 | from .vfe_template import VFETemplate 12 | 13 | 14 | class DynamicMeanVFE(VFETemplate): 15 | def __init__(self, model_cfg, num_point_features, voxel_size, grid_size, point_cloud_range, **kwargs): 16 | super().__init__(model_cfg=model_cfg) 17 | self.num_point_features = num_point_features 18 | 19 | self.grid_size = torch.tensor(grid_size).cuda() 20 | self.voxel_size = torch.tensor(voxel_size).cuda() 21 | self.point_cloud_range = torch.tensor(point_cloud_range).cuda() 22 | 23 | self.voxel_x = voxel_size[0] 24 | self.voxel_y = voxel_size[1] 25 | self.voxel_z = voxel_size[2] 26 | self.x_offset = self.voxel_x / 2 + point_cloud_range[0] 27 | self.y_offset = self.voxel_y / 2 + point_cloud_range[1] 28 | self.z_offset = self.voxel_z / 2 + point_cloud_range[2] 29 | 30 | self.scale_xyz = grid_size[0] * grid_size[1] * grid_size[2] 31 | self.scale_yz = grid_size[1] * grid_size[2] 32 | self.scale_z = grid_size[2] 33 | 34 | def get_output_feature_dim(self): 35 | return self.num_point_features 36 | 37 | @torch.no_grad() 38 | def forward(self, batch_dict, **kwargs): 39 | """ 40 | Args: 41 | batch_dict: 42 | voxels: (num_voxels, max_points_per_voxel, C) 43 | voxel_num_points: optional (num_voxels) 44 | **kwargs: 45 | 46 | Returns: 47 | vfe_features: (num_voxels, C) 48 | """ 49 | batch_size = batch_dict['batch_size'] 50 | points = batch_dict['points'] # (batch_idx, x, y, z, i, e) 51 | 52 | # # debug 53 | point_coords = torch.floor((points[:, 1:4] - self.point_cloud_range[0:3]) / self.voxel_size).int() 54 | mask = ((point_coords >= 0) & (point_coords < self.grid_size)).all(dim=1) 55 | points = points[mask] 56 | point_coords = point_coords[mask] 57 | merge_coords = points[:, 0].int() * self.scale_xyz + \ 58 | point_coords[:, 0] * self.scale_yz + \ 59 | point_coords[:, 1] * self.scale_z + \ 60 | point_coords[:, 2] 61 | points_data = points[:, 1:].contiguous() 62 | 63 | unq_coords, unq_inv, unq_cnt = torch.unique(merge_coords, return_inverse=True, return_counts=True) 64 | 65 | points_mean = torch_scatter.scatter_mean(points_data, unq_inv, dim=0) 66 | 67 | unq_coords = unq_coords.int() 68 | voxel_coords = torch.stack((unq_coords // self.scale_xyz, 69 | (unq_coords % self.scale_xyz) // self.scale_yz, 70 | (unq_coords % self.scale_yz) // self.scale_z, 71 | unq_coords % self.scale_z), dim=1) 72 | voxel_coords = voxel_coords[:, [0, 3, 2, 1]] 73 | 74 | batch_dict['voxel_features'] = points_mean.contiguous() 75 | batch_dict['voxel_coords'] = voxel_coords.contiguous() 76 | return batch_dict 77 | -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_3d/vfe/image_vfe.py: -------------------------------------------------------------------------------- 1 | import torch 2 | 3 | from .vfe_template import VFETemplate 4 | from .image_vfe_modules import ffn, f2v 5 | 6 | 7 | class ImageVFE(VFETemplate): 8 | def __init__(self, model_cfg, grid_size, point_cloud_range, depth_downsample_factor, **kwargs): 9 | super().__init__(model_cfg=model_cfg) 10 | self.grid_size = grid_size 11 | self.pc_range = point_cloud_range 12 | self.downsample_factor = depth_downsample_factor 13 | self.module_topology = [ 14 | 'ffn', 'f2v' 15 | ] 16 | self.build_modules() 17 | 18 | def build_modules(self): 19 | """ 20 | Builds modules 21 | """ 22 | for module_name in self.module_topology: 23 | module = getattr(self, 'build_%s' % module_name)() 24 | self.add_module(module_name, module) 25 | 26 | def build_ffn(self): 27 | """ 28 | Builds frustum feature network 29 | Returns: 30 | ffn_module: nn.Module, Frustum feature network 31 | """ 32 | ffn_module = ffn.__all__[self.model_cfg.FFN.NAME]( 33 | model_cfg=self.model_cfg.FFN, 34 | downsample_factor=self.downsample_factor 35 | ) 36 | self.disc_cfg = ffn_module.disc_cfg 37 | return ffn_module 38 | 39 | def build_f2v(self): 40 | """ 41 | Builds frustum to voxel transformation 42 | Returns: 43 | f2v_module: nn.Module, Frustum to voxel transformation 44 | """ 45 | f2v_module = f2v.__all__[self.model_cfg.F2V.NAME]( 46 | model_cfg=self.model_cfg.F2V, 47 | grid_size=self.grid_size, 48 | pc_range=self.pc_range, 49 | disc_cfg=self.disc_cfg 50 | ) 51 | return f2v_module 52 | 53 | def get_output_feature_dim(self): 54 | """ 55 | Gets number of output channels 56 | Returns: 57 | out_feature_dim: int, Number of output channels 58 | """ 59 | out_feature_dim = self.ffn.get_output_feature_dim() 60 | return out_feature_dim 61 | 62 | def forward(self, batch_dict, **kwargs): 63 | """ 64 | Args: 65 | batch_dict: 66 | images: (N, 3, H_in, W_in), Input images 67 | **kwargs: 68 | Returns: 69 | batch_dict: 70 | voxel_features: (B, C, Z, Y, X), Image voxel features 71 | """ 72 | batch_dict = self.ffn(batch_dict) 73 | batch_dict = self.f2v(batch_dict) 74 | return batch_dict 75 | 76 | def get_loss(self): 77 | """ 78 | Gets DDN loss 79 | Returns: 80 | loss: (1), Depth distribution network loss 81 | tb_dict: dict[float], All losses to log in tensorboard 82 | """ 83 | 84 | loss, tb_dict = self.ffn.get_loss() 85 | return loss, tb_dict 86 | -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_3d/vfe/image_vfe_modules/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/backbones_3d/vfe/image_vfe_modules/__init__.py -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_3d/vfe/image_vfe_modules/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/backbones_3d/vfe/image_vfe_modules/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_3d/vfe/image_vfe_modules/f2v/__init__.py: -------------------------------------------------------------------------------- 1 | from .frustum_to_voxel import FrustumToVoxel 2 | 3 | __all__ = { 4 | 'FrustumToVoxel': FrustumToVoxel 5 | } 6 | -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_3d/vfe/image_vfe_modules/f2v/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/backbones_3d/vfe/image_vfe_modules/f2v/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_3d/vfe/image_vfe_modules/f2v/__pycache__/frustum_grid_generator.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/backbones_3d/vfe/image_vfe_modules/f2v/__pycache__/frustum_grid_generator.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_3d/vfe/image_vfe_modules/f2v/__pycache__/frustum_to_voxel.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/backbones_3d/vfe/image_vfe_modules/f2v/__pycache__/frustum_to_voxel.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_3d/vfe/image_vfe_modules/f2v/__pycache__/sampler.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/backbones_3d/vfe/image_vfe_modules/f2v/__pycache__/sampler.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_3d/vfe/image_vfe_modules/f2v/frustum_to_voxel.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn as nn 3 | 4 | from .frustum_grid_generator import FrustumGridGenerator 5 | from .sampler import Sampler 6 | 7 | 8 | class FrustumToVoxel(nn.Module): 9 | 10 | def __init__(self, model_cfg, grid_size, pc_range, disc_cfg): 11 | """ 12 | Initializes module to transform frustum features to voxel features via 3D transformation and sampling 13 | Args: 14 | model_cfg: EasyDict, Module configuration 15 | grid_size: [X, Y, Z], Voxel grid size 16 | pc_range: [x_min, y_min, z_min, x_max, y_max, z_max], Voxelization point cloud range (m) 17 | disc_cfg: EasyDict, Depth discretiziation configuration 18 | """ 19 | super().__init__() 20 | self.model_cfg = model_cfg 21 | self.grid_size = grid_size 22 | self.pc_range = pc_range 23 | self.disc_cfg = disc_cfg 24 | self.grid_generator = FrustumGridGenerator(grid_size=grid_size, 25 | pc_range=pc_range, 26 | disc_cfg=disc_cfg) 27 | self.sampler = Sampler(**model_cfg.SAMPLER) 28 | 29 | def forward(self, batch_dict): 30 | """ 31 | Generates voxel features via 3D transformation and sampling 32 | Args: 33 | batch_dict: 34 | frustum_features: (B, C, D, H_image, W_image), Image frustum features 35 | lidar_to_cam: (B, 4, 4), LiDAR to camera frame transformation 36 | cam_to_img: (B, 3, 4), Camera projection matrix 37 | image_shape: (B, 2), Image shape [H, W] 38 | Returns: 39 | batch_dict: 40 | voxel_features: (B, C, Z, Y, X), Image voxel features 41 | """ 42 | # Generate sampling grid for frustum volume 43 | grid = self.grid_generator(lidar_to_cam=batch_dict["trans_lidar_to_cam"], 44 | cam_to_img=batch_dict["trans_cam_to_img"], 45 | image_shape=batch_dict["image_shape"]) # (B, X, Y, Z, 3) 46 | 47 | # Sample frustum volume to generate voxel volume 48 | voxel_features = self.sampler(input_features=batch_dict["frustum_features"], 49 | grid=grid) # (B, C, X, Y, Z) 50 | 51 | # (B, C, X, Y, Z) -> (B, C, Z, Y, X) 52 | voxel_features = voxel_features.permute(0, 1, 4, 3, 2) 53 | batch_dict["voxel_features"] = voxel_features 54 | return batch_dict 55 | -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_3d/vfe/image_vfe_modules/f2v/sampler.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn as nn 3 | import torch.nn.functional as F 4 | 5 | 6 | class Sampler(nn.Module): 7 | 8 | def __init__(self, mode="bilinear", padding_mode="zeros"): 9 | """ 10 | Initializes module 11 | Args: 12 | mode: string, Sampling mode [bilinear/nearest] 13 | padding_mode: string, Padding mode for outside grid values [zeros/border/reflection] 14 | """ 15 | super().__init__() 16 | self.mode = mode 17 | self.padding_mode = padding_mode 18 | 19 | def forward(self, input_features, grid): 20 | """ 21 | Samples input using sampling grid 22 | Args: 23 | input_features: (B, C, D, H, W), Input frustum features 24 | grid: (B, X, Y, Z, 3), Sampling grids for input features 25 | Returns 26 | output_features: (B, C, X, Y, Z) Output voxel features 27 | """ 28 | # Sample from grid 29 | output = F.grid_sample(input=input_features, grid=grid, mode=self.mode, padding_mode=self.padding_mode) 30 | return output 31 | -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_3d/vfe/image_vfe_modules/ffn/__init__.py: -------------------------------------------------------------------------------- 1 | from .depth_ffn import DepthFFN 2 | 3 | __all__ = { 4 | 'DepthFFN': DepthFFN 5 | } 6 | -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_3d/vfe/image_vfe_modules/ffn/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/backbones_3d/vfe/image_vfe_modules/ffn/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_3d/vfe/image_vfe_modules/ffn/__pycache__/depth_ffn.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/backbones_3d/vfe/image_vfe_modules/ffn/__pycache__/depth_ffn.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_3d/vfe/image_vfe_modules/ffn/ddn/__init__.py: -------------------------------------------------------------------------------- 1 | from .ddn_deeplabv3 import DDNDeepLabV3 2 | 3 | __all__ = { 4 | 'DDNDeepLabV3': DDNDeepLabV3 5 | } 6 | -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_3d/vfe/image_vfe_modules/ffn/ddn/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/backbones_3d/vfe/image_vfe_modules/ffn/ddn/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_3d/vfe/image_vfe_modules/ffn/ddn/__pycache__/ddn_deeplabv3.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/backbones_3d/vfe/image_vfe_modules/ffn/ddn/__pycache__/ddn_deeplabv3.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_3d/vfe/image_vfe_modules/ffn/ddn/__pycache__/ddn_template.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/backbones_3d/vfe/image_vfe_modules/ffn/ddn/__pycache__/ddn_template.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_3d/vfe/image_vfe_modules/ffn/ddn/ddn_deeplabv3.py: -------------------------------------------------------------------------------- 1 | from .ddn_template import DDNTemplate 2 | 3 | try: 4 | import torchvision 5 | except: 6 | pass 7 | 8 | 9 | class DDNDeepLabV3(DDNTemplate): 10 | 11 | def __init__(self, backbone_name, **kwargs): 12 | """ 13 | Initializes DDNDeepLabV3 model 14 | Args: 15 | backbone_name: string, ResNet Backbone Name [ResNet50/ResNet101] 16 | """ 17 | if backbone_name == "ResNet50": 18 | constructor = torchvision.models.segmentation.deeplabv3_resnet50 19 | elif backbone_name == "ResNet101": 20 | constructor = torchvision.models.segmentation.deeplabv3_resnet101 21 | else: 22 | raise NotImplementedError 23 | 24 | super().__init__(constructor=constructor, **kwargs) 25 | -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_3d/vfe/image_vfe_modules/ffn/ddn_loss/__init__.py: -------------------------------------------------------------------------------- 1 | from .ddn_loss import DDNLoss 2 | 3 | __all__ = { 4 | "DDNLoss": DDNLoss 5 | } 6 | -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_3d/vfe/image_vfe_modules/ffn/ddn_loss/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/backbones_3d/vfe/image_vfe_modules/ffn/ddn_loss/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_3d/vfe/image_vfe_modules/ffn/ddn_loss/__pycache__/balancer.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/backbones_3d/vfe/image_vfe_modules/ffn/ddn_loss/__pycache__/balancer.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_3d/vfe/image_vfe_modules/ffn/ddn_loss/__pycache__/ddn_loss.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/backbones_3d/vfe/image_vfe_modules/ffn/ddn_loss/__pycache__/ddn_loss.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_3d/vfe/image_vfe_modules/ffn/ddn_loss/balancer.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn as nn 3 | 4 | from pcdet.utils import loss_utils 5 | 6 | 7 | class Balancer(nn.Module): 8 | def __init__(self, fg_weight, bg_weight, downsample_factor=1): 9 | """ 10 | Initialize fixed foreground/background loss balancer 11 | Args: 12 | fg_weight: float, Foreground loss weight 13 | bg_weight: float, Background loss weight 14 | downsample_factor: int, Depth map downsample factor 15 | """ 16 | super().__init__() 17 | self.fg_weight = fg_weight 18 | self.bg_weight = bg_weight 19 | self.downsample_factor = downsample_factor 20 | 21 | def forward(self, loss, gt_boxes2d): 22 | """ 23 | Forward pass 24 | Args: 25 | loss: (B, H, W), Pixel-wise loss 26 | gt_boxes2d: (B, N, 4), 2D box labels for foreground/background balancing 27 | Returns: 28 | loss: (1), Total loss after foreground/background balancing 29 | tb_dict: dict[float], All losses to log in tensorboard 30 | """ 31 | # Compute masks 32 | fg_mask = loss_utils.compute_fg_mask(gt_boxes2d=gt_boxes2d, 33 | shape=loss.shape, 34 | downsample_factor=self.downsample_factor, 35 | device=loss.device) 36 | bg_mask = ~fg_mask 37 | 38 | # Compute balancing weights 39 | weights = self.fg_weight * fg_mask + self.bg_weight * bg_mask 40 | num_pixels = fg_mask.sum() + bg_mask.sum() 41 | 42 | # Compute losses 43 | loss *= weights 44 | fg_loss = loss[fg_mask].sum() / num_pixels 45 | bg_loss = loss[bg_mask].sum() / num_pixels 46 | 47 | # Get total loss 48 | loss = fg_loss + bg_loss 49 | tb_dict = {"balancer_loss": loss.item(), "fg_loss": fg_loss.item(), "bg_loss": bg_loss.item()} 50 | return loss, tb_dict 51 | -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_3d/vfe/image_vfe_modules/ffn/ddn_loss/ddn_loss.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn as nn 3 | 4 | 5 | from .balancer import Balancer 6 | from pcdet.utils import transform_utils 7 | 8 | try: 9 | from kornia.losses.focal import FocalLoss 10 | except: 11 | pass 12 | # print('Warning: kornia is not installed. This package is only required by CaDDN') 13 | 14 | 15 | class DDNLoss(nn.Module): 16 | 17 | def __init__(self, 18 | weight, 19 | alpha, 20 | gamma, 21 | disc_cfg, 22 | fg_weight, 23 | bg_weight, 24 | downsample_factor): 25 | """ 26 | Initializes DDNLoss module 27 | Args: 28 | weight: float, Loss function weight 29 | alpha: float, Alpha value for Focal Loss 30 | gamma: float, Gamma value for Focal Loss 31 | disc_cfg: dict, Depth discretiziation configuration 32 | fg_weight: float, Foreground loss weight 33 | bg_weight: float, Background loss weight 34 | downsample_factor: int, Depth map downsample factor 35 | """ 36 | super().__init__() 37 | self.device = torch.cuda.current_device() 38 | self.disc_cfg = disc_cfg 39 | self.balancer = Balancer(downsample_factor=downsample_factor, 40 | fg_weight=fg_weight, 41 | bg_weight=bg_weight) 42 | 43 | # Set loss function 44 | self.alpha = alpha 45 | self.gamma = gamma 46 | self.loss_func = FocalLoss(alpha=self.alpha, gamma=self.gamma, reduction="none") 47 | self.weight = weight 48 | 49 | def forward(self, depth_logits, depth_maps, gt_boxes2d): 50 | """ 51 | Gets DDN loss 52 | Args: 53 | depth_logits: (B, D+1, H, W), Predicted depth logits 54 | depth_maps: (B, H, W), Depth map [m] 55 | gt_boxes2d: torch.Tensor (B, N, 4), 2D box labels for foreground/background balancing 56 | Returns: 57 | loss: (1), Depth distribution network loss 58 | tb_dict: dict[float], All losses to log in tensorboard 59 | """ 60 | tb_dict = {} 61 | 62 | # Bin depth map to create target 63 | depth_target = transform_utils.bin_depths(depth_maps, **self.disc_cfg, target=True) 64 | 65 | # Compute loss 66 | loss = self.loss_func(depth_logits, depth_target) 67 | 68 | # Compute foreground/background balancing 69 | loss, tb_dict = self.balancer(loss=loss, gt_boxes2d=gt_boxes2d) 70 | 71 | # Final loss 72 | loss *= self.weight 73 | tb_dict.update({"ddn_loss": loss.item()}) 74 | 75 | return loss, tb_dict 76 | -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_3d/vfe/mean_vfe.py: -------------------------------------------------------------------------------- 1 | import torch 2 | 3 | from .vfe_template import VFETemplate 4 | 5 | 6 | class MeanVFE(VFETemplate): 7 | def __init__(self, model_cfg, num_point_features, **kwargs): 8 | super().__init__(model_cfg=model_cfg) 9 | self.num_point_features = num_point_features 10 | 11 | def get_output_feature_dim(self): 12 | return self.num_point_features 13 | 14 | def forward(self, batch_dict, **kwargs): 15 | """ 16 | Args: 17 | batch_dict: 18 | voxels: (num_voxels, max_points_per_voxel, C) 19 | voxel_num_points: optional (num_voxels) 20 | **kwargs: 21 | 22 | Returns: 23 | vfe_features: (num_voxels, C) 24 | """ 25 | voxel_features, voxel_num_points = batch_dict['voxels'], batch_dict['voxel_num_points'] 26 | points_mean = voxel_features[:, :, :].sum(dim=1, keepdim=False) 27 | normalizer = torch.clamp_min(voxel_num_points.view(-1, 1), min=1.0).type_as(voxel_features) 28 | points_mean = points_mean / normalizer 29 | batch_dict['voxel_features'] = points_mean.contiguous() 30 | 31 | return batch_dict 32 | -------------------------------------------------------------------------------- /openpcuct/pcdet/models/backbones_3d/vfe/vfe_template.py: -------------------------------------------------------------------------------- 1 | import torch.nn as nn 2 | 3 | 4 | class VFETemplate(nn.Module): 5 | def __init__(self, model_cfg, **kwargs): 6 | super().__init__() 7 | self.model_cfg = model_cfg 8 | 9 | def get_output_feature_dim(self): 10 | raise NotImplementedError 11 | 12 | def forward(self, **kwargs): 13 | """ 14 | Args: 15 | **kwargs: 16 | 17 | Returns: 18 | batch_dict: 19 | ... 20 | vfe_features: (num_voxels, C) 21 | """ 22 | raise NotImplementedError 23 | -------------------------------------------------------------------------------- /openpcuct/pcdet/models/dense_heads/__init__.py: -------------------------------------------------------------------------------- 1 | from .anchor_head_multi import AnchorHeadMulti 2 | from .anchor_head_single import AnchorHeadSingle 3 | from .anchor_head_template import AnchorHeadTemplate 4 | from .point_head_box import PointHeadBox 5 | from .point_head_simple import PointHeadSimple 6 | from .point_intra_part_head import PointIntraPartOffsetHead 7 | from .center_head import CenterHead 8 | 9 | __all__ = { 10 | 'AnchorHeadTemplate': AnchorHeadTemplate, 11 | 'AnchorHeadSingle': AnchorHeadSingle, 12 | 'PointIntraPartOffsetHead': PointIntraPartOffsetHead, 13 | 'PointHeadSimple': PointHeadSimple, 14 | 'PointHeadBox': PointHeadBox, 15 | 'AnchorHeadMulti': AnchorHeadMulti, 16 | 'CenterHead': CenterHead 17 | } 18 | -------------------------------------------------------------------------------- /openpcuct/pcdet/models/dense_heads/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/dense_heads/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/dense_heads/__pycache__/anchor_head_multi.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/dense_heads/__pycache__/anchor_head_multi.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/dense_heads/__pycache__/anchor_head_single.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/dense_heads/__pycache__/anchor_head_single.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/dense_heads/__pycache__/anchor_head_template.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/dense_heads/__pycache__/anchor_head_template.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/dense_heads/__pycache__/center_head.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/dense_heads/__pycache__/center_head.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/dense_heads/__pycache__/point_head_box.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/dense_heads/__pycache__/point_head_box.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/dense_heads/__pycache__/point_head_simple.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/dense_heads/__pycache__/point_head_simple.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/dense_heads/__pycache__/point_head_template.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/dense_heads/__pycache__/point_head_template.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/dense_heads/__pycache__/point_intra_part_head.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/dense_heads/__pycache__/point_intra_part_head.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/dense_heads/anchor_head_single.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import torch.nn as nn 3 | 4 | from .anchor_head_template import AnchorHeadTemplate 5 | 6 | 7 | class AnchorHeadSingle(AnchorHeadTemplate): 8 | def __init__(self, model_cfg, input_channels, num_class, class_names, grid_size, point_cloud_range, 9 | predict_boxes_when_training=True, **kwargs): 10 | super().__init__( 11 | model_cfg=model_cfg, num_class=num_class, class_names=class_names, grid_size=grid_size, point_cloud_range=point_cloud_range, 12 | predict_boxes_when_training=predict_boxes_when_training 13 | ) 14 | 15 | self.num_anchors_per_location = sum(self.num_anchors_per_location) 16 | 17 | self.conv_cls = nn.Conv2d( 18 | input_channels, self.num_anchors_per_location * self.num_class, 19 | kernel_size=1 20 | ) 21 | self.conv_box = nn.Conv2d( 22 | input_channels, self.num_anchors_per_location * self.box_coder.code_size, 23 | kernel_size=1 24 | ) 25 | 26 | if self.model_cfg.get('USE_DIRECTION_CLASSIFIER', None) is not None: 27 | self.conv_dir_cls = nn.Conv2d( 28 | input_channels, 29 | self.num_anchors_per_location * self.model_cfg.NUM_DIR_BINS, 30 | kernel_size=1 31 | ) 32 | else: 33 | self.conv_dir_cls = None 34 | self.init_weights() 35 | 36 | def init_weights(self): 37 | pi = 0.01 38 | nn.init.constant_(self.conv_cls.bias, -np.log((1 - pi) / pi)) 39 | nn.init.normal_(self.conv_box.weight, mean=0, std=0.001) 40 | 41 | def forward(self, data_dict): 42 | spatial_features_2d = data_dict['spatial_features_2d'] 43 | 44 | cls_preds = self.conv_cls(spatial_features_2d) 45 | box_preds = self.conv_box(spatial_features_2d) 46 | 47 | cls_preds = cls_preds.permute(0, 2, 3, 1).contiguous() # [N, H, W, C] 48 | box_preds = box_preds.permute(0, 2, 3, 1).contiguous() # [N, H, W, C] 49 | 50 | self.forward_ret_dict['cls_preds'] = cls_preds 51 | self.forward_ret_dict['box_preds'] = box_preds 52 | 53 | if self.conv_dir_cls is not None: 54 | dir_cls_preds = self.conv_dir_cls(spatial_features_2d) 55 | dir_cls_preds = dir_cls_preds.permute(0, 2, 3, 1).contiguous() 56 | self.forward_ret_dict['dir_cls_preds'] = dir_cls_preds 57 | else: 58 | dir_cls_preds = None 59 | 60 | if self.training: 61 | targets_dict = self.assign_targets( 62 | gt_boxes=data_dict['gt_boxes'] 63 | ) 64 | self.forward_ret_dict.update(targets_dict) 65 | 66 | if not self.training or self.predict_boxes_when_training: 67 | batch_cls_preds, batch_box_preds = self.generate_predicted_boxes( 68 | batch_size=data_dict['batch_size'], 69 | cls_preds=cls_preds, box_preds=box_preds, dir_cls_preds=dir_cls_preds 70 | ) 71 | data_dict['batch_cls_preds'] = batch_cls_preds 72 | data_dict['batch_box_preds'] = batch_box_preds 73 | data_dict['cls_preds_normalized'] = False 74 | 75 | return data_dict 76 | -------------------------------------------------------------------------------- /openpcuct/pcdet/models/dense_heads/target_assigner/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/dense_heads/target_assigner/__init__.py -------------------------------------------------------------------------------- /openpcuct/pcdet/models/dense_heads/target_assigner/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/dense_heads/target_assigner/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/dense_heads/target_assigner/__pycache__/anchor_generator.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/dense_heads/target_assigner/__pycache__/anchor_generator.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/dense_heads/target_assigner/__pycache__/atss_target_assigner.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/dense_heads/target_assigner/__pycache__/atss_target_assigner.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/dense_heads/target_assigner/__pycache__/axis_aligned_target_assigner.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/dense_heads/target_assigner/__pycache__/axis_aligned_target_assigner.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/detectors/PartA2_net.py: -------------------------------------------------------------------------------- 1 | from .detector3d_template import Detector3DTemplate 2 | 3 | 4 | class PartA2Net(Detector3DTemplate): 5 | def __init__(self, model_cfg, num_class, dataset): 6 | super().__init__(model_cfg=model_cfg, num_class=num_class, dataset=dataset) 7 | self.module_list = self.build_networks() 8 | 9 | def forward(self, batch_dict): 10 | for cur_module in self.module_list: 11 | batch_dict = cur_module(batch_dict) 12 | 13 | if self.training: 14 | loss, tb_dict, disp_dict = self.get_training_loss() 15 | 16 | ret_dict = { 17 | 'loss': loss 18 | } 19 | return ret_dict, tb_dict, disp_dict 20 | else: 21 | pred_dicts, recall_dicts = self.post_processing(batch_dict) 22 | return pred_dicts, recall_dicts 23 | 24 | def get_training_loss(self): 25 | disp_dict = {} 26 | loss_rpn, tb_dict = self.dense_head.get_loss() 27 | loss_point, tb_dict = self.point_head.get_loss(tb_dict) 28 | loss_rcnn, tb_dict = self.roi_head.get_loss(tb_dict) 29 | 30 | loss = loss_rpn + loss_point + loss_rcnn 31 | return loss, tb_dict, disp_dict 32 | -------------------------------------------------------------------------------- /openpcuct/pcdet/models/detectors/__init__.py: -------------------------------------------------------------------------------- 1 | from .detector3d_template import Detector3DTemplate 2 | from .PartA2_net import PartA2Net 3 | from .point_rcnn import PointRCNN 4 | from .pointpillar import PointPillar 5 | from .pv_rcnn import PVRCNN 6 | from .second_net import SECONDNet 7 | from .second_net_iou import SECONDNetIoU 8 | from .caddn import CaDDN 9 | from .voxel_rcnn import VoxelRCNN 10 | from .centerpoint import CenterPoint 11 | from .pv_rcnn_plusplus import PVRCNNPlusPlus 12 | 13 | __all__ = { 14 | 'Detector3DTemplate': Detector3DTemplate, 15 | 'SECONDNet': SECONDNet, 16 | 'PartA2Net': PartA2Net, 17 | 'PVRCNN': PVRCNN, 18 | 'PointPillar': PointPillar, 19 | 'PointRCNN': PointRCNN, 20 | 'SECONDNetIoU': SECONDNetIoU, 21 | 'CaDDN': CaDDN, 22 | 'VoxelRCNN': VoxelRCNN, 23 | 'CenterPoint': CenterPoint, 24 | 'PVRCNNPlusPlus': PVRCNNPlusPlus 25 | } 26 | 27 | 28 | def build_detector(model_cfg, num_class, dataset): 29 | model = __all__[model_cfg.NAME]( 30 | model_cfg=model_cfg, num_class=num_class, dataset=dataset 31 | ) 32 | 33 | return model 34 | -------------------------------------------------------------------------------- /openpcuct/pcdet/models/detectors/__pycache__/PartA2_net.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/detectors/__pycache__/PartA2_net.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/detectors/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/detectors/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/detectors/__pycache__/caddn.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/detectors/__pycache__/caddn.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/detectors/__pycache__/centerpoint.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/detectors/__pycache__/centerpoint.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/detectors/__pycache__/detector3d_template.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/detectors/__pycache__/detector3d_template.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/detectors/__pycache__/point_rcnn.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/detectors/__pycache__/point_rcnn.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/detectors/__pycache__/pointpillar.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/detectors/__pycache__/pointpillar.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/detectors/__pycache__/pv_rcnn.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/detectors/__pycache__/pv_rcnn.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/detectors/__pycache__/pv_rcnn_plusplus.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/detectors/__pycache__/pv_rcnn_plusplus.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/detectors/__pycache__/second_net.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/detectors/__pycache__/second_net.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/detectors/__pycache__/second_net_iou.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/detectors/__pycache__/second_net_iou.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/detectors/__pycache__/voxel_rcnn.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/detectors/__pycache__/voxel_rcnn.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/detectors/caddn.py: -------------------------------------------------------------------------------- 1 | from .detector3d_template import Detector3DTemplate 2 | 3 | 4 | class CaDDN(Detector3DTemplate): 5 | def __init__(self, model_cfg, num_class, dataset): 6 | super().__init__(model_cfg=model_cfg, num_class=num_class, dataset=dataset) 7 | self.module_list = self.build_networks() 8 | 9 | def forward(self, batch_dict): 10 | for cur_module in self.module_list: 11 | batch_dict = cur_module(batch_dict) 12 | 13 | if self.training: 14 | loss, tb_dict, disp_dict = self.get_training_loss() 15 | 16 | ret_dict = { 17 | 'loss': loss 18 | } 19 | return ret_dict, tb_dict, disp_dict 20 | else: 21 | pred_dicts, recall_dicts = self.post_processing(batch_dict) 22 | return pred_dicts, recall_dicts 23 | 24 | def get_training_loss(self): 25 | disp_dict = {} 26 | 27 | loss_rpn, tb_dict_rpn = self.dense_head.get_loss() 28 | loss_depth, tb_dict_depth = self.vfe.get_loss() 29 | 30 | tb_dict = { 31 | 'loss_rpn': loss_rpn.item(), 32 | 'loss_depth': loss_depth.item(), 33 | **tb_dict_rpn, 34 | **tb_dict_depth 35 | } 36 | 37 | loss = loss_rpn + loss_depth 38 | return loss, tb_dict, disp_dict 39 | -------------------------------------------------------------------------------- /openpcuct/pcdet/models/detectors/centerpoint.py: -------------------------------------------------------------------------------- 1 | from .detector3d_template import Detector3DTemplate 2 | 3 | 4 | class CenterPoint(Detector3DTemplate): 5 | def __init__(self, model_cfg, num_class, dataset): 6 | super().__init__(model_cfg=model_cfg, num_class=num_class, dataset=dataset) 7 | self.module_list = self.build_networks() 8 | 9 | def forward(self, batch_dict): 10 | for cur_module in self.module_list: 11 | batch_dict = cur_module(batch_dict) 12 | 13 | if self.training: 14 | loss, tb_dict, disp_dict = self.get_training_loss() 15 | 16 | ret_dict = { 17 | 'loss': loss 18 | } 19 | return ret_dict, tb_dict, disp_dict 20 | else: 21 | pred_dicts, recall_dicts = self.post_processing(batch_dict) 22 | return pred_dicts, recall_dicts 23 | 24 | def get_training_loss(self): 25 | disp_dict = {} 26 | 27 | loss_rpn, tb_dict = self.dense_head.get_loss() 28 | tb_dict = { 29 | 'loss_rpn': loss_rpn.item(), 30 | **tb_dict 31 | } 32 | 33 | loss = loss_rpn 34 | return loss, tb_dict, disp_dict 35 | 36 | def post_processing(self, batch_dict): 37 | post_process_cfg = self.model_cfg.POST_PROCESSING 38 | batch_size = batch_dict['batch_size'] 39 | final_pred_dict = batch_dict['final_box_dicts'] 40 | recall_dict = {} 41 | for index in range(batch_size): 42 | pred_boxes = final_pred_dict[index]['pred_boxes'] 43 | 44 | recall_dict = self.generate_recall_record( 45 | box_preds=pred_boxes, 46 | recall_dict=recall_dict, batch_index=index, data_dict=batch_dict, 47 | thresh_list=post_process_cfg.RECALL_THRESH_LIST 48 | ) 49 | 50 | return final_pred_dict, recall_dict 51 | -------------------------------------------------------------------------------- /openpcuct/pcdet/models/detectors/point_rcnn.py: -------------------------------------------------------------------------------- 1 | from .detector3d_template import Detector3DTemplate 2 | from pcuct.laplace_approx.bayesian_models import point_rcnn_bayesian_inference 3 | 4 | class PointRCNN(Detector3DTemplate): 5 | def __init__(self, model_cfg, num_class, dataset): 6 | super().__init__(model_cfg=model_cfg, num_class=num_class, dataset=dataset) 7 | self.module_list = self.build_networks() 8 | 9 | def bayesian_inference(self, batch_dict, wdist_dict, **kwargs): 10 | return point_rcnn_bayesian_inference( 11 | self, 12 | batch_dict, 13 | wdist_dict, **kwargs) 14 | 15 | def forward(self, batch_dict): 16 | for cur_module in self.module_list: 17 | batch_dict = cur_module(batch_dict) 18 | 19 | if self.training: 20 | loss, tb_dict, disp_dict = self.get_training_loss() 21 | 22 | ret_dict = { 23 | 'loss': loss 24 | } 25 | return ret_dict, tb_dict, disp_dict 26 | else: 27 | pred_dicts, recall_dicts = self.post_processing(batch_dict) 28 | return pred_dicts, recall_dicts 29 | 30 | def get_training_loss(self): 31 | disp_dict = {} 32 | loss_point, tb_dict = self.point_head.get_loss() 33 | loss_rcnn, tb_dict = self.roi_head.get_loss(tb_dict) 34 | 35 | loss = loss_point + loss_rcnn 36 | return loss, tb_dict, disp_dict 37 | -------------------------------------------------------------------------------- /openpcuct/pcdet/models/detectors/pointpillar.py: -------------------------------------------------------------------------------- 1 | from .detector3d_template import Detector3DTemplate 2 | from pcuct.laplace_approx.bayesian_models import pointpillar_bayesian_inference 3 | 4 | class PointPillar(Detector3DTemplate): 5 | def __init__(self, model_cfg, num_class, dataset): 6 | super().__init__(model_cfg=model_cfg, num_class=num_class, dataset=dataset) 7 | self.module_list = self.build_networks() 8 | 9 | def bayesian_inference(self, batch_dict, wdist_dict, **kwargs): 10 | return pointpillar_bayesian_inference( 11 | self, 12 | batch_dict, 13 | wdist_dict, **kwargs) 14 | 15 | def forward(self, batch_dict): 16 | for cur_module in self.module_list: 17 | batch_dict = cur_module(batch_dict) 18 | 19 | if self.training: 20 | loss, tb_dict, disp_dict = self.get_training_loss() 21 | 22 | ret_dict = { 23 | 'loss': loss 24 | } 25 | return ret_dict, tb_dict, disp_dict 26 | else: 27 | pred_dicts, recall_dicts = self.post_processing(batch_dict) 28 | return pred_dicts, recall_dicts 29 | 30 | def get_training_loss(self): 31 | disp_dict = {} 32 | 33 | loss_rpn, tb_dict = self.dense_head.get_loss() 34 | tb_dict = { 35 | 'loss_rpn': loss_rpn.item(), 36 | **tb_dict 37 | } 38 | 39 | loss = loss_rpn 40 | return loss, tb_dict, disp_dict 41 | -------------------------------------------------------------------------------- /openpcuct/pcdet/models/detectors/pv_rcnn.py: -------------------------------------------------------------------------------- 1 | from .detector3d_template import Detector3DTemplate 2 | from pcuct.laplace_approx.bayesian_models import pv_rcnn_bayesian_inference 3 | 4 | class PVRCNN(Detector3DTemplate): 5 | def __init__(self, model_cfg, num_class, dataset): 6 | super().__init__(model_cfg=model_cfg, num_class=num_class, dataset=dataset) 7 | self.module_list = self.build_networks() 8 | 9 | def bayesian_inference(self, batch_dict, wdist_dict, **kwargs): 10 | return pv_rcnn_bayesian_inference( 11 | self, 12 | batch_dict, 13 | wdist_dict, **kwargs) 14 | 15 | def forward(self, batch_dict): 16 | for cur_module in self.module_list: 17 | batch_dict = cur_module(batch_dict) 18 | 19 | if self.training: 20 | loss, tb_dict, disp_dict = self.get_training_loss() 21 | 22 | ret_dict = { 23 | 'loss': loss 24 | } 25 | return ret_dict, tb_dict, disp_dict 26 | else: 27 | pred_dicts, recall_dicts = self.post_processing(batch_dict) 28 | return pred_dicts, recall_dicts 29 | 30 | def get_training_loss(self): 31 | disp_dict = {} 32 | loss_rpn, tb_dict = self.dense_head.get_loss() 33 | loss_point, tb_dict = self.point_head.get_loss(tb_dict) 34 | loss_rcnn, tb_dict = self.roi_head.get_loss(tb_dict) 35 | 36 | loss = loss_rpn + loss_point + loss_rcnn 37 | return loss, tb_dict, disp_dict 38 | -------------------------------------------------------------------------------- /openpcuct/pcdet/models/detectors/pv_rcnn_plusplus.py: -------------------------------------------------------------------------------- 1 | from .detector3d_template import Detector3DTemplate 2 | 3 | 4 | class PVRCNNPlusPlus(Detector3DTemplate): 5 | def __init__(self, model_cfg, num_class, dataset): 6 | super().__init__(model_cfg=model_cfg, num_class=num_class, dataset=dataset) 7 | self.module_list = self.build_networks() 8 | 9 | def forward(self, batch_dict): 10 | batch_dict = self.vfe(batch_dict) 11 | batch_dict = self.backbone_3d(batch_dict) 12 | batch_dict = self.map_to_bev_module(batch_dict) 13 | batch_dict = self.backbone_2d(batch_dict) 14 | batch_dict = self.dense_head(batch_dict) 15 | 16 | batch_dict = self.roi_head.proposal_layer( 17 | batch_dict, nms_config=self.roi_head.model_cfg.NMS_CONFIG['TRAIN' if self.training else 'TEST'] 18 | ) 19 | if self.training: 20 | targets_dict = self.roi_head.assign_targets(batch_dict) 21 | batch_dict['rois'] = targets_dict['rois'] 22 | batch_dict['roi_labels'] = targets_dict['roi_labels'] 23 | batch_dict['roi_targets_dict'] = targets_dict 24 | num_rois_per_scene = targets_dict['rois'].shape[1] 25 | if 'roi_valid_num' in batch_dict: 26 | batch_dict['roi_valid_num'] = [num_rois_per_scene for _ in range(batch_dict['batch_size'])] 27 | 28 | batch_dict = self.pfe(batch_dict) 29 | batch_dict = self.point_head(batch_dict) 30 | batch_dict = self.roi_head(batch_dict) 31 | 32 | if self.training: 33 | loss, tb_dict, disp_dict = self.get_training_loss() 34 | 35 | ret_dict = { 36 | 'loss': loss 37 | } 38 | return ret_dict, tb_dict, disp_dict 39 | else: 40 | pred_dicts, recall_dicts = self.post_processing(batch_dict) 41 | return pred_dicts, recall_dicts 42 | 43 | def get_training_loss(self): 44 | disp_dict = {} 45 | loss_rpn, tb_dict = self.dense_head.get_loss() 46 | if self.point_head is not None: 47 | loss_point, tb_dict = self.point_head.get_loss(tb_dict) 48 | else: 49 | loss_point = 0 50 | loss_rcnn, tb_dict = self.roi_head.get_loss(tb_dict) 51 | 52 | loss = loss_rpn + loss_point + loss_rcnn 53 | return loss, tb_dict, disp_dict 54 | -------------------------------------------------------------------------------- /openpcuct/pcdet/models/detectors/second_net.py: -------------------------------------------------------------------------------- 1 | from .detector3d_template import Detector3DTemplate 2 | from pcuct.laplace_approx.bayesian_models import second_net_bayesian_inference 3 | 4 | class SECONDNet(Detector3DTemplate): 5 | def __init__(self, model_cfg, num_class, dataset): 6 | super().__init__(model_cfg=model_cfg, num_class=num_class, dataset=dataset) 7 | self.module_list = self.build_networks() 8 | 9 | def bayesian_inference(self, batch_dict, wdist_dict, **kwargs): 10 | return second_net_bayesian_inference( 11 | self, 12 | batch_dict, 13 | wdist_dict, **kwargs) 14 | 15 | def forward(self, batch_dict): 16 | for cur_module in self.module_list: 17 | batch_dict = cur_module(batch_dict) 18 | 19 | if self.training: 20 | loss, tb_dict, disp_dict = self.get_training_loss() 21 | 22 | ret_dict = { 23 | 'loss': loss 24 | } 25 | return ret_dict, tb_dict, disp_dict 26 | else: 27 | pred_dicts, recall_dicts = self.post_processing(batch_dict) 28 | return pred_dicts, recall_dicts 29 | 30 | def get_training_loss(self): 31 | disp_dict = {} 32 | 33 | loss_rpn, tb_dict = self.dense_head.get_loss() 34 | tb_dict = { 35 | 'loss_rpn': loss_rpn.item(), 36 | **tb_dict 37 | } 38 | 39 | loss = loss_rpn 40 | return loss, tb_dict, disp_dict 41 | -------------------------------------------------------------------------------- /openpcuct/pcdet/models/detectors/voxel_rcnn.py: -------------------------------------------------------------------------------- 1 | from .detector3d_template import Detector3DTemplate 2 | 3 | 4 | class VoxelRCNN(Detector3DTemplate): 5 | def __init__(self, model_cfg, num_class, dataset): 6 | super().__init__(model_cfg=model_cfg, num_class=num_class, dataset=dataset) 7 | self.module_list = self.build_networks() 8 | 9 | def forward(self, batch_dict): 10 | for cur_module in self.module_list: 11 | batch_dict = cur_module(batch_dict) 12 | 13 | if self.training: 14 | loss, tb_dict, disp_dict = self.get_training_loss() 15 | 16 | ret_dict = { 17 | 'loss': loss 18 | } 19 | return ret_dict, tb_dict, disp_dict 20 | else: 21 | pred_dicts, recall_dicts = self.post_processing(batch_dict) 22 | return pred_dicts, recall_dicts 23 | 24 | def get_training_loss(self): 25 | disp_dict = {} 26 | loss = 0 27 | 28 | loss_rpn, tb_dict = self.dense_head.get_loss() 29 | loss_rcnn, tb_dict = self.roi_head.get_loss(tb_dict) 30 | 31 | loss = loss + loss_rpn + loss_rcnn 32 | return loss, tb_dict, disp_dict 33 | -------------------------------------------------------------------------------- /openpcuct/pcdet/models/model_utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/model_utils/__init__.py -------------------------------------------------------------------------------- /openpcuct/pcdet/models/model_utils/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/model_utils/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/model_utils/__pycache__/basic_block_2d.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/model_utils/__pycache__/basic_block_2d.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/model_utils/__pycache__/centernet_utils.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/model_utils/__pycache__/centernet_utils.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/model_utils/__pycache__/model_nms_utils.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/model_utils/__pycache__/model_nms_utils.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/model_utils/basic_block_2d.py: -------------------------------------------------------------------------------- 1 | import torch.nn as nn 2 | 3 | 4 | class BasicBlock2D(nn.Module): 5 | 6 | def __init__(self, in_channels, out_channels, **kwargs): 7 | """ 8 | Initializes convolutional block 9 | Args: 10 | in_channels: int, Number of input channels 11 | out_channels: int, Number of output channels 12 | **kwargs: Dict, Extra arguments for nn.Conv2d 13 | """ 14 | super().__init__() 15 | self.in_channels = in_channels 16 | self.out_channels = out_channels 17 | self.conv = nn.Conv2d(in_channels=in_channels, 18 | out_channels=out_channels, 19 | **kwargs) 20 | self.bn = nn.BatchNorm2d(out_channels) 21 | self.relu = nn.ReLU(inplace=True) 22 | 23 | def forward(self, features): 24 | """ 25 | Applies convolutional block 26 | Args: 27 | features: (B, C_in, H, W), Input features 28 | Returns: 29 | x: (B, C_out, H, W), Output features 30 | """ 31 | x = self.conv(features) 32 | x = self.bn(x) 33 | x = self.relu(x) 34 | return x 35 | -------------------------------------------------------------------------------- /openpcuct/pcdet/models/model_utils/model_nms_utils.py: -------------------------------------------------------------------------------- 1 | import torch 2 | 3 | from ...ops.iou3d_nms import iou3d_nms_utils 4 | 5 | 6 | def class_agnostic_nms(box_scores, box_preds, nms_config, score_thresh=None): 7 | src_box_scores = box_scores 8 | if score_thresh is not None: 9 | scores_mask = (box_scores >= score_thresh) 10 | box_scores = box_scores[scores_mask] 11 | box_preds = box_preds[scores_mask] 12 | 13 | selected = [] 14 | if box_scores.shape[0] > 0: 15 | box_scores_nms, indices = torch.topk(box_scores, k=min(nms_config.NMS_PRE_MAXSIZE, box_scores.shape[0])) 16 | boxes_for_nms = box_preds[indices] 17 | keep_idx, selected_scores = getattr(iou3d_nms_utils, nms_config.NMS_TYPE)( 18 | boxes_for_nms[:, 0:7], box_scores_nms, nms_config.NMS_THRESH, **nms_config 19 | ) 20 | selected = indices[keep_idx[:nms_config.NMS_POST_MAXSIZE]] 21 | 22 | if score_thresh is not None: 23 | original_idxs = scores_mask.nonzero().view(-1) 24 | selected = original_idxs[selected] 25 | return selected, src_box_scores[selected] 26 | 27 | 28 | def multi_classes_nms(cls_scores, box_preds, nms_config, score_thresh=None): 29 | """ 30 | Args: 31 | cls_scores: (N, num_class) 32 | box_preds: (N, 7 + C) 33 | nms_config: 34 | score_thresh: 35 | 36 | Returns: 37 | 38 | """ 39 | pred_scores, pred_labels, pred_boxes = [], [], [] 40 | for k in range(cls_scores.shape[1]): 41 | if score_thresh is not None: 42 | scores_mask = (cls_scores[:, k] >= score_thresh) 43 | box_scores = cls_scores[scores_mask, k] 44 | cur_box_preds = box_preds[scores_mask] 45 | else: 46 | box_scores = cls_scores[:, k] 47 | cur_box_preds = box_preds 48 | 49 | selected = [] 50 | if box_scores.shape[0] > 0: 51 | box_scores_nms, indices = torch.topk(box_scores, k=min(nms_config.NMS_PRE_MAXSIZE, box_scores.shape[0])) 52 | boxes_for_nms = cur_box_preds[indices] 53 | keep_idx, selected_scores = getattr(iou3d_nms_utils, nms_config.NMS_TYPE)( 54 | boxes_for_nms[:, 0:7], box_scores_nms, nms_config.NMS_THRESH, **nms_config 55 | ) 56 | selected = indices[keep_idx[:nms_config.NMS_POST_MAXSIZE]] 57 | 58 | pred_scores.append(box_scores[selected]) 59 | pred_labels.append(box_scores.new_ones(len(selected)).long() * k) 60 | pred_boxes.append(cur_box_preds[selected]) 61 | 62 | pred_scores = torch.cat(pred_scores, dim=0) 63 | pred_labels = torch.cat(pred_labels, dim=0) 64 | pred_boxes = torch.cat(pred_boxes, dim=0) 65 | 66 | return pred_scores, pred_labels, pred_boxes 67 | -------------------------------------------------------------------------------- /openpcuct/pcdet/models/roi_heads/__init__.py: -------------------------------------------------------------------------------- 1 | from .partA2_head import PartA2FCHead 2 | from .pointrcnn_head import PointRCNNHead 3 | from .pvrcnn_head import PVRCNNHead 4 | from .second_head import SECONDHead 5 | from .voxelrcnn_head import VoxelRCNNHead 6 | from .roi_head_template import RoIHeadTemplate 7 | 8 | 9 | __all__ = { 10 | 'RoIHeadTemplate': RoIHeadTemplate, 11 | 'PartA2FCHead': PartA2FCHead, 12 | 'PVRCNNHead': PVRCNNHead, 13 | 'SECONDHead': SECONDHead, 14 | 'PointRCNNHead': PointRCNNHead, 15 | 'VoxelRCNNHead': VoxelRCNNHead 16 | } 17 | -------------------------------------------------------------------------------- /openpcuct/pcdet/models/roi_heads/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/roi_heads/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/roi_heads/__pycache__/partA2_head.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/roi_heads/__pycache__/partA2_head.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/roi_heads/__pycache__/pointrcnn_head.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/roi_heads/__pycache__/pointrcnn_head.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/roi_heads/__pycache__/pvrcnn_head.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/roi_heads/__pycache__/pvrcnn_head.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/roi_heads/__pycache__/roi_head_template.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/roi_heads/__pycache__/roi_head_template.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/roi_heads/__pycache__/second_head.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/roi_heads/__pycache__/second_head.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/roi_heads/__pycache__/voxelrcnn_head.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/roi_heads/__pycache__/voxelrcnn_head.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/roi_heads/target_assigner/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/roi_heads/target_assigner/__init__.py -------------------------------------------------------------------------------- /openpcuct/pcdet/models/roi_heads/target_assigner/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/roi_heads/target_assigner/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/models/roi_heads/target_assigner/__pycache__/proposal_target_layer.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/models/roi_heads/target_assigner/__pycache__/proposal_target_layer.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/ops/__init__.py -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/iou3d_nms/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/ops/iou3d_nms/__init__.py -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/iou3d_nms/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/ops/iou3d_nms/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/iou3d_nms/__pycache__/iou3d_nms_utils.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/ops/iou3d_nms/__pycache__/iou3d_nms_utils.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/iou3d_nms/src/iou3d_cpu.h: -------------------------------------------------------------------------------- 1 | #ifndef IOU3D_CPU_H 2 | #define IOU3D_CPU_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | int boxes_iou_bev_cpu(at::Tensor boxes_a_tensor, at::Tensor boxes_b_tensor, at::Tensor ans_iou_tensor); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/iou3d_nms/src/iou3d_nms.h: -------------------------------------------------------------------------------- 1 | #ifndef IOU3D_NMS_H 2 | #define IOU3D_NMS_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | int boxes_overlap_bev_gpu(at::Tensor boxes_a, at::Tensor boxes_b, at::Tensor ans_overlap); 10 | int boxes_iou_bev_gpu(at::Tensor boxes_a, at::Tensor boxes_b, at::Tensor ans_iou); 11 | int nms_gpu(at::Tensor boxes, at::Tensor keep, float nms_overlap_thresh); 12 | int nms_normal_gpu(at::Tensor boxes, at::Tensor keep, float nms_overlap_thresh); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/iou3d_nms/src/iou3d_nms_api.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "iou3d_cpu.h" 8 | #include "iou3d_nms.h" 9 | 10 | 11 | PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) { 12 | m.def("boxes_overlap_bev_gpu", &boxes_overlap_bev_gpu, "oriented boxes overlap"); 13 | m.def("boxes_iou_bev_gpu", &boxes_iou_bev_gpu, "oriented boxes iou"); 14 | m.def("nms_gpu", &nms_gpu, "oriented nms gpu"); 15 | m.def("nms_normal_gpu", &nms_normal_gpu, "nms gpu"); 16 | m.def("boxes_iou_bev_cpu", &boxes_iou_bev_cpu, "oriented boxes iou"); 17 | } 18 | -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/pointnet2/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/ops/pointnet2/__init__.py -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/pointnet2/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/ops/pointnet2/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/pointnet2/pointnet2_batch/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/ops/pointnet2/pointnet2_batch/__init__.py -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/pointnet2/pointnet2_batch/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/ops/pointnet2/pointnet2_batch/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/pointnet2/pointnet2_batch/__pycache__/pointnet2_modules.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/ops/pointnet2/pointnet2_batch/__pycache__/pointnet2_modules.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/pointnet2/pointnet2_batch/__pycache__/pointnet2_utils.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/ops/pointnet2/pointnet2_batch/__pycache__/pointnet2_utils.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/pointnet2/pointnet2_batch/src/ball_query.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | batch version of ball query, modified from the original implementation of official PointNet++ codes. 3 | Written by Shaoshuai Shi 4 | All Rights Reserved 2018. 5 | */ 6 | 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "ball_query_gpu.h" 14 | 15 | extern THCState *state; 16 | 17 | #define CHECK_CUDA(x) do { \ 18 | if (!x.type().is_cuda()) { \ 19 | fprintf(stderr, "%s must be CUDA tensor at %s:%d\n", #x, __FILE__, __LINE__); \ 20 | exit(-1); \ 21 | } \ 22 | } while (0) 23 | #define CHECK_CONTIGUOUS(x) do { \ 24 | if (!x.is_contiguous()) { \ 25 | fprintf(stderr, "%s must be contiguous tensor at %s:%d\n", #x, __FILE__, __LINE__); \ 26 | exit(-1); \ 27 | } \ 28 | } while (0) 29 | #define CHECK_INPUT(x) CHECK_CUDA(x);CHECK_CONTIGUOUS(x) 30 | 31 | 32 | int ball_query_wrapper_fast(int b, int n, int m, float radius, int nsample, 33 | at::Tensor new_xyz_tensor, at::Tensor xyz_tensor, at::Tensor idx_tensor) { 34 | CHECK_INPUT(new_xyz_tensor); 35 | CHECK_INPUT(xyz_tensor); 36 | const float *new_xyz = new_xyz_tensor.data(); 37 | const float *xyz = xyz_tensor.data(); 38 | int *idx = idx_tensor.data(); 39 | 40 | ball_query_kernel_launcher_fast(b, n, m, radius, nsample, new_xyz, xyz, idx); 41 | return 1; 42 | } 43 | -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/pointnet2/pointnet2_batch/src/ball_query_gpu.cu: -------------------------------------------------------------------------------- 1 | /* 2 | batch version of ball query, modified from the original implementation of official PointNet++ codes. 3 | Written by Shaoshuai Shi 4 | All Rights Reserved 2018. 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include "ball_query_gpu.h" 12 | #include "cuda_utils.h" 13 | 14 | 15 | __global__ void ball_query_kernel_fast(int b, int n, int m, float radius, int nsample, 16 | const float *__restrict__ new_xyz, const float *__restrict__ xyz, int *__restrict__ idx) { 17 | // new_xyz: (B, M, 3) 18 | // xyz: (B, N, 3) 19 | // output: 20 | // idx: (B, M, nsample) 21 | int bs_idx = blockIdx.y; 22 | int pt_idx = blockIdx.x * blockDim.x + threadIdx.x; 23 | if (bs_idx >= b || pt_idx >= m) return; 24 | 25 | new_xyz += bs_idx * m * 3 + pt_idx * 3; 26 | xyz += bs_idx * n * 3; 27 | idx += bs_idx * m * nsample + pt_idx * nsample; 28 | 29 | float radius2 = radius * radius; 30 | float new_x = new_xyz[0]; 31 | float new_y = new_xyz[1]; 32 | float new_z = new_xyz[2]; 33 | 34 | int cnt = 0; 35 | for (int k = 0; k < n; ++k) { 36 | float x = xyz[k * 3 + 0]; 37 | float y = xyz[k * 3 + 1]; 38 | float z = xyz[k * 3 + 2]; 39 | float d2 = (new_x - x) * (new_x - x) + (new_y - y) * (new_y - y) + (new_z - z) * (new_z - z); 40 | if (d2 < radius2){ 41 | if (cnt == 0){ 42 | for (int l = 0; l < nsample; ++l) { 43 | idx[l] = k; 44 | } 45 | } 46 | idx[cnt] = k; 47 | ++cnt; 48 | if (cnt >= nsample) break; 49 | } 50 | } 51 | } 52 | 53 | 54 | void ball_query_kernel_launcher_fast(int b, int n, int m, float radius, int nsample, \ 55 | const float *new_xyz, const float *xyz, int *idx) { 56 | // new_xyz: (B, M, 3) 57 | // xyz: (B, N, 3) 58 | // output: 59 | // idx: (B, M, nsample) 60 | 61 | cudaError_t err; 62 | 63 | dim3 blocks(DIVUP(m, THREADS_PER_BLOCK), b); // blockIdx.x(col), blockIdx.y(row) 64 | dim3 threads(THREADS_PER_BLOCK); 65 | 66 | ball_query_kernel_fast<<>>(b, n, m, radius, nsample, new_xyz, xyz, idx); 67 | // cudaDeviceSynchronize(); // for using printf in kernel function 68 | err = cudaGetLastError(); 69 | if (cudaSuccess != err) { 70 | fprintf(stderr, "CUDA kernel failed : %s\n", cudaGetErrorString(err)); 71 | exit(-1); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/pointnet2/pointnet2_batch/src/ball_query_gpu.h: -------------------------------------------------------------------------------- 1 | #ifndef _BALL_QUERY_GPU_H 2 | #define _BALL_QUERY_GPU_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | int ball_query_wrapper_fast(int b, int n, int m, float radius, int nsample, 10 | at::Tensor new_xyz_tensor, at::Tensor xyz_tensor, at::Tensor idx_tensor); 11 | 12 | void ball_query_kernel_launcher_fast(int b, int n, int m, float radius, int nsample, 13 | const float *xyz, const float *new_xyz, int *idx); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/pointnet2/pointnet2_batch/src/cuda_utils.h: -------------------------------------------------------------------------------- 1 | #ifndef _CUDA_UTILS_H 2 | #define _CUDA_UTILS_H 3 | 4 | #include 5 | 6 | #define TOTAL_THREADS 1024 7 | #define THREADS_PER_BLOCK 256 8 | #define DIVUP(m,n) ((m) / (n) + ((m) % (n) > 0)) 9 | 10 | inline int opt_n_threads(int work_size) { 11 | const int pow_2 = std::log(static_cast(work_size)) / std::log(2.0); 12 | 13 | return max(min(1 << pow_2, TOTAL_THREADS), 1); 14 | } 15 | #endif 16 | -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/pointnet2/pointnet2_batch/src/group_points.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | batch version of point grouping, modified from the original implementation of official PointNet++ codes. 3 | Written by Shaoshuai Shi 4 | All Rights Reserved 2018. 5 | */ 6 | 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "group_points_gpu.h" 14 | 15 | extern THCState *state; 16 | 17 | 18 | int group_points_grad_wrapper_fast(int b, int c, int n, int npoints, int nsample, 19 | at::Tensor grad_out_tensor, at::Tensor idx_tensor, at::Tensor grad_points_tensor) { 20 | 21 | float *grad_points = grad_points_tensor.data(); 22 | const int *idx = idx_tensor.data(); 23 | const float *grad_out = grad_out_tensor.data(); 24 | 25 | group_points_grad_kernel_launcher_fast(b, c, n, npoints, nsample, grad_out, idx, grad_points); 26 | return 1; 27 | } 28 | 29 | 30 | int group_points_wrapper_fast(int b, int c, int n, int npoints, int nsample, 31 | at::Tensor points_tensor, at::Tensor idx_tensor, at::Tensor out_tensor) { 32 | 33 | const float *points = points_tensor.data(); 34 | const int *idx = idx_tensor.data(); 35 | float *out = out_tensor.data(); 36 | 37 | group_points_kernel_launcher_fast(b, c, n, npoints, nsample, points, idx, out); 38 | return 1; 39 | } 40 | -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/pointnet2/pointnet2_batch/src/group_points_gpu.h: -------------------------------------------------------------------------------- 1 | #ifndef _GROUP_POINTS_GPU_H 2 | #define _GROUP_POINTS_GPU_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | 10 | int group_points_wrapper_fast(int b, int c, int n, int npoints, int nsample, 11 | at::Tensor points_tensor, at::Tensor idx_tensor, at::Tensor out_tensor); 12 | 13 | void group_points_kernel_launcher_fast(int b, int c, int n, int npoints, int nsample, 14 | const float *points, const int *idx, float *out); 15 | 16 | int group_points_grad_wrapper_fast(int b, int c, int n, int npoints, int nsample, 17 | at::Tensor grad_out_tensor, at::Tensor idx_tensor, at::Tensor grad_points_tensor); 18 | 19 | void group_points_grad_kernel_launcher_fast(int b, int c, int n, int npoints, int nsample, 20 | const float *grad_out, const int *idx, float *grad_points); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/pointnet2/pointnet2_batch/src/interpolate.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | batch version of point interpolation, modified from the original implementation of official PointNet++ codes. 3 | Written by Shaoshuai Shi 4 | All Rights Reserved 2018. 5 | */ 6 | 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include "interpolate_gpu.h" 17 | 18 | extern THCState *state; 19 | 20 | 21 | void three_nn_wrapper_fast(int b, int n, int m, at::Tensor unknown_tensor, 22 | at::Tensor known_tensor, at::Tensor dist2_tensor, at::Tensor idx_tensor) { 23 | const float *unknown = unknown_tensor.data(); 24 | const float *known = known_tensor.data(); 25 | float *dist2 = dist2_tensor.data(); 26 | int *idx = idx_tensor.data(); 27 | 28 | three_nn_kernel_launcher_fast(b, n, m, unknown, known, dist2, idx); 29 | } 30 | 31 | 32 | void three_interpolate_wrapper_fast(int b, int c, int m, int n, 33 | at::Tensor points_tensor, 34 | at::Tensor idx_tensor, 35 | at::Tensor weight_tensor, 36 | at::Tensor out_tensor) { 37 | 38 | const float *points = points_tensor.data(); 39 | const float *weight = weight_tensor.data(); 40 | float *out = out_tensor.data(); 41 | const int *idx = idx_tensor.data(); 42 | 43 | three_interpolate_kernel_launcher_fast(b, c, m, n, points, idx, weight, out); 44 | } 45 | 46 | void three_interpolate_grad_wrapper_fast(int b, int c, int n, int m, 47 | at::Tensor grad_out_tensor, 48 | at::Tensor idx_tensor, 49 | at::Tensor weight_tensor, 50 | at::Tensor grad_points_tensor) { 51 | 52 | const float *grad_out = grad_out_tensor.data(); 53 | const float *weight = weight_tensor.data(); 54 | float *grad_points = grad_points_tensor.data(); 55 | const int *idx = idx_tensor.data(); 56 | 57 | three_interpolate_grad_kernel_launcher_fast(b, c, n, m, grad_out, idx, weight, grad_points); 58 | } 59 | -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/pointnet2/pointnet2_batch/src/interpolate_gpu.h: -------------------------------------------------------------------------------- 1 | #ifndef _INTERPOLATE_GPU_H 2 | #define _INTERPOLATE_GPU_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | 10 | void three_nn_wrapper_fast(int b, int n, int m, at::Tensor unknown_tensor, 11 | at::Tensor known_tensor, at::Tensor dist2_tensor, at::Tensor idx_tensor); 12 | 13 | void three_nn_kernel_launcher_fast(int b, int n, int m, const float *unknown, 14 | const float *known, float *dist2, int *idx); 15 | 16 | 17 | void three_interpolate_wrapper_fast(int b, int c, int m, int n, at::Tensor points_tensor, 18 | at::Tensor idx_tensor, at::Tensor weight_tensor, at::Tensor out_tensor); 19 | 20 | void three_interpolate_kernel_launcher_fast(int b, int c, int m, int n, 21 | const float *points, const int *idx, const float *weight, float *out); 22 | 23 | 24 | void three_interpolate_grad_wrapper_fast(int b, int c, int n, int m, at::Tensor grad_out_tensor, 25 | at::Tensor idx_tensor, at::Tensor weight_tensor, at::Tensor grad_points_tensor); 26 | 27 | void three_interpolate_grad_kernel_launcher_fast(int b, int c, int n, int m, const float *grad_out, 28 | const int *idx, const float *weight, float *grad_points); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/pointnet2/pointnet2_batch/src/pointnet2_api.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "ball_query_gpu.h" 5 | #include "group_points_gpu.h" 6 | #include "sampling_gpu.h" 7 | #include "interpolate_gpu.h" 8 | 9 | 10 | PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) { 11 | m.def("ball_query_wrapper", &ball_query_wrapper_fast, "ball_query_wrapper_fast"); 12 | 13 | m.def("group_points_wrapper", &group_points_wrapper_fast, "group_points_wrapper_fast"); 14 | m.def("group_points_grad_wrapper", &group_points_grad_wrapper_fast, "group_points_grad_wrapper_fast"); 15 | 16 | m.def("gather_points_wrapper", &gather_points_wrapper_fast, "gather_points_wrapper_fast"); 17 | m.def("gather_points_grad_wrapper", &gather_points_grad_wrapper_fast, "gather_points_grad_wrapper_fast"); 18 | 19 | m.def("farthest_point_sampling_wrapper", &farthest_point_sampling_wrapper, "farthest_point_sampling_wrapper"); 20 | 21 | m.def("three_nn_wrapper", &three_nn_wrapper_fast, "three_nn_wrapper_fast"); 22 | m.def("three_interpolate_wrapper", &three_interpolate_wrapper_fast, "three_interpolate_wrapper_fast"); 23 | m.def("three_interpolate_grad_wrapper", &three_interpolate_grad_wrapper_fast, "three_interpolate_grad_wrapper_fast"); 24 | } 25 | -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/pointnet2/pointnet2_batch/src/sampling.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | batch version of point sampling and gathering, modified from the original implementation of official PointNet++ codes. 3 | Written by Shaoshuai Shi 4 | All Rights Reserved 2018. 5 | */ 6 | 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "sampling_gpu.h" 14 | 15 | extern THCState *state; 16 | 17 | 18 | int gather_points_wrapper_fast(int b, int c, int n, int npoints, 19 | at::Tensor points_tensor, at::Tensor idx_tensor, at::Tensor out_tensor){ 20 | const float *points = points_tensor.data(); 21 | const int *idx = idx_tensor.data(); 22 | float *out = out_tensor.data(); 23 | 24 | gather_points_kernel_launcher_fast(b, c, n, npoints, points, idx, out); 25 | return 1; 26 | } 27 | 28 | 29 | int gather_points_grad_wrapper_fast(int b, int c, int n, int npoints, 30 | at::Tensor grad_out_tensor, at::Tensor idx_tensor, at::Tensor grad_points_tensor) { 31 | 32 | const float *grad_out = grad_out_tensor.data(); 33 | const int *idx = idx_tensor.data(); 34 | float *grad_points = grad_points_tensor.data(); 35 | 36 | gather_points_grad_kernel_launcher_fast(b, c, n, npoints, grad_out, idx, grad_points); 37 | return 1; 38 | } 39 | 40 | 41 | int farthest_point_sampling_wrapper(int b, int n, int m, 42 | at::Tensor points_tensor, at::Tensor temp_tensor, at::Tensor idx_tensor) { 43 | 44 | const float *points = points_tensor.data(); 45 | float *temp = temp_tensor.data(); 46 | int *idx = idx_tensor.data(); 47 | 48 | farthest_point_sampling_kernel_launcher(b, n, m, points, temp, idx); 49 | return 1; 50 | } 51 | -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/pointnet2/pointnet2_batch/src/sampling_gpu.h: -------------------------------------------------------------------------------- 1 | #ifndef _SAMPLING_GPU_H 2 | #define _SAMPLING_GPU_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | int gather_points_wrapper_fast(int b, int c, int n, int npoints, 10 | at::Tensor points_tensor, at::Tensor idx_tensor, at::Tensor out_tensor); 11 | 12 | void gather_points_kernel_launcher_fast(int b, int c, int n, int npoints, 13 | const float *points, const int *idx, float *out); 14 | 15 | 16 | int gather_points_grad_wrapper_fast(int b, int c, int n, int npoints, 17 | at::Tensor grad_out_tensor, at::Tensor idx_tensor, at::Tensor grad_points_tensor); 18 | 19 | void gather_points_grad_kernel_launcher_fast(int b, int c, int n, int npoints, 20 | const float *grad_out, const int *idx, float *grad_points); 21 | 22 | 23 | int farthest_point_sampling_wrapper(int b, int n, int m, 24 | at::Tensor points_tensor, at::Tensor temp_tensor, at::Tensor idx_tensor); 25 | 26 | void farthest_point_sampling_kernel_launcher(int b, int n, int m, 27 | const float *dataset, float *temp, int *idxs); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/pointnet2/pointnet2_stack/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/ops/pointnet2/pointnet2_stack/__init__.py -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/pointnet2/pointnet2_stack/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/ops/pointnet2/pointnet2_stack/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/pointnet2/pointnet2_stack/__pycache__/pointnet2_modules.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/ops/pointnet2/pointnet2_stack/__pycache__/pointnet2_modules.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/pointnet2/pointnet2_stack/__pycache__/pointnet2_utils.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/ops/pointnet2/pointnet2_stack/__pycache__/pointnet2_utils.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/pointnet2/pointnet2_stack/__pycache__/voxel_pool_modules.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/ops/pointnet2/pointnet2_stack/__pycache__/voxel_pool_modules.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/pointnet2/pointnet2_stack/__pycache__/voxel_query_utils.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/ops/pointnet2/pointnet2_stack/__pycache__/voxel_query_utils.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/pointnet2/pointnet2_stack/src/ball_query.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Stacked-batch-data version of ball query, modified from the original implementation of official PointNet++ codes. 3 | Written by Shaoshuai Shi 4 | All Rights Reserved 2019-2020. 5 | */ 6 | 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "ball_query_gpu.h" 14 | 15 | extern THCState *state; 16 | 17 | #define CHECK_CUDA(x) do { \ 18 | if (!x.type().is_cuda()) { \ 19 | fprintf(stderr, "%s must be CUDA tensor at %s:%d\n", #x, __FILE__, __LINE__); \ 20 | exit(-1); \ 21 | } \ 22 | } while (0) 23 | #define CHECK_CONTIGUOUS(x) do { \ 24 | if (!x.is_contiguous()) { \ 25 | fprintf(stderr, "%s must be contiguous tensor at %s:%d\n", #x, __FILE__, __LINE__); \ 26 | exit(-1); \ 27 | } \ 28 | } while (0) 29 | #define CHECK_INPUT(x) CHECK_CUDA(x);CHECK_CONTIGUOUS(x) 30 | 31 | int ball_query_wrapper_stack(int B, int M, float radius, int nsample, 32 | at::Tensor new_xyz_tensor, at::Tensor new_xyz_batch_cnt_tensor, 33 | at::Tensor xyz_tensor, at::Tensor xyz_batch_cnt_tensor, at::Tensor idx_tensor) { 34 | CHECK_INPUT(new_xyz_tensor); 35 | CHECK_INPUT(xyz_tensor); 36 | CHECK_INPUT(new_xyz_batch_cnt_tensor); 37 | CHECK_INPUT(xyz_batch_cnt_tensor); 38 | 39 | const float *new_xyz = new_xyz_tensor.data(); 40 | const float *xyz = xyz_tensor.data(); 41 | const int *new_xyz_batch_cnt = new_xyz_batch_cnt_tensor.data(); 42 | const int *xyz_batch_cnt = xyz_batch_cnt_tensor.data(); 43 | int *idx = idx_tensor.data(); 44 | 45 | ball_query_kernel_launcher_stack(B, M, radius, nsample, new_xyz, new_xyz_batch_cnt, xyz, xyz_batch_cnt, idx); 46 | return 1; 47 | } 48 | -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/pointnet2/pointnet2_stack/src/ball_query_gpu.cu: -------------------------------------------------------------------------------- 1 | /* 2 | Stacked-batch-data version of ball query, modified from the original implementation of official PointNet++ codes. 3 | Written by Shaoshuai Shi 4 | All Rights Reserved 2019-2020. 5 | */ 6 | 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "ball_query_gpu.h" 13 | #include "cuda_utils.h" 14 | 15 | 16 | __global__ void ball_query_kernel_stack(int B, int M, float radius, int nsample, \ 17 | const float *new_xyz, const int *new_xyz_batch_cnt, const float *xyz, const int *xyz_batch_cnt, int *idx) { 18 | // :param xyz: (N1 + N2 ..., 3) xyz coordinates of the features 19 | // :param xyz_batch_cnt: (batch_size), [N1, N2, ...] 20 | // :param new_xyz: (M1 + M2 ..., 3) centers of the ball query 21 | // :param new_xyz_batch_cnt: (batch_size), [M1, M2, ...] 22 | // output: 23 | // idx: (M, nsample) 24 | int pt_idx = blockIdx.x * blockDim.x + threadIdx.x; 25 | if (pt_idx >= M) return; 26 | 27 | int bs_idx = 0, pt_cnt = new_xyz_batch_cnt[0]; 28 | for (int k = 1; k < B; k++){ 29 | if (pt_idx < pt_cnt) break; 30 | pt_cnt += new_xyz_batch_cnt[k]; 31 | bs_idx = k; 32 | } 33 | 34 | int xyz_batch_start_idx = 0; 35 | for (int k = 0; k < bs_idx; k++) xyz_batch_start_idx += xyz_batch_cnt[k]; 36 | // for (int k = 0; k < bs_idx; k++) new_xyz_batch_start_idx += new_xyz_batch_cnt[k]; 37 | 38 | new_xyz += pt_idx * 3; 39 | xyz += xyz_batch_start_idx * 3; 40 | idx += pt_idx * nsample; 41 | 42 | float radius2 = radius * radius; 43 | float new_x = new_xyz[0]; 44 | float new_y = new_xyz[1]; 45 | float new_z = new_xyz[2]; 46 | int n = xyz_batch_cnt[bs_idx]; 47 | 48 | int cnt = 0; 49 | for (int k = 0; k < n; ++k) { 50 | float x = xyz[k * 3 + 0]; 51 | float y = xyz[k * 3 + 1]; 52 | float z = xyz[k * 3 + 2]; 53 | float d2 = (new_x - x) * (new_x - x) + (new_y - y) * (new_y - y) + (new_z - z) * (new_z - z); 54 | if (d2 < radius2){ 55 | if (cnt == 0){ 56 | for (int l = 0; l < nsample; ++l) { 57 | idx[l] = k; 58 | } 59 | } 60 | idx[cnt] = k; 61 | ++cnt; 62 | if (cnt >= nsample) break; 63 | } 64 | } 65 | if (cnt == 0) idx[0] = -1; 66 | } 67 | 68 | 69 | void ball_query_kernel_launcher_stack(int B, int M, float radius, int nsample, 70 | const float *new_xyz, const int *new_xyz_batch_cnt, const float *xyz, const int *xyz_batch_cnt, int *idx){ 71 | // :param xyz: (N1 + N2 ..., 3) xyz coordinates of the features 72 | // :param xyz_batch_cnt: (batch_size), [N1, N2, ...] 73 | // :param new_xyz: (M1 + M2 ..., 3) centers of the ball query 74 | // :param new_xyz_batch_cnt: (batch_size), [M1, M2, ...] 75 | // output: 76 | // idx: (M, nsample) 77 | 78 | cudaError_t err; 79 | 80 | dim3 blocks(DIVUP(M, THREADS_PER_BLOCK)); // blockIdx.x(col), blockIdx.y(row) 81 | dim3 threads(THREADS_PER_BLOCK); 82 | 83 | ball_query_kernel_stack<<>>(B, M, radius, nsample, new_xyz, new_xyz_batch_cnt, xyz, xyz_batch_cnt, idx); 84 | // cudaDeviceSynchronize(); // for using printf in kernel function 85 | err = cudaGetLastError(); 86 | if (cudaSuccess != err) { 87 | fprintf(stderr, "CUDA kernel failed : %s\n", cudaGetErrorString(err)); 88 | exit(-1); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/pointnet2/pointnet2_stack/src/ball_query_gpu.h: -------------------------------------------------------------------------------- 1 | /* 2 | Stacked-batch-data version of ball query, modified from the original implementation of official PointNet++ codes. 3 | Written by Shaoshuai Shi 4 | All Rights Reserved 2019-2020. 5 | */ 6 | 7 | 8 | #ifndef _STACK_BALL_QUERY_GPU_H 9 | #define _STACK_BALL_QUERY_GPU_H 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | int ball_query_wrapper_stack(int B, int M, float radius, int nsample, 17 | at::Tensor new_xyz_tensor, at::Tensor new_xyz_batch_cnt_tensor, 18 | at::Tensor xyz_tensor, at::Tensor xyz_batch_cnt_tensor, at::Tensor idx_tensor); 19 | 20 | 21 | void ball_query_kernel_launcher_stack(int B, int M, float radius, int nsample, 22 | const float *new_xyz, const int *new_xyz_batch_cnt, const float *xyz, const int *xyz_batch_cnt, int *idx); 23 | 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/pointnet2/pointnet2_stack/src/cuda_utils.h: -------------------------------------------------------------------------------- 1 | #ifndef _STACK_CUDA_UTILS_H 2 | #define _STACK_CUDA_UTILS_H 3 | 4 | #include 5 | 6 | #define THREADS_PER_BLOCK 256 7 | #define DIVUP(m,n) ((m) / (n) + ((m) % (n) > 0)) 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/pointnet2/pointnet2_stack/src/group_points.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Stacked-batch-data version of point grouping, modified from the original implementation of official PointNet++ codes. 3 | Written by Shaoshuai Shi 4 | All Rights Reserved 2019-2020. 5 | */ 6 | 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "group_points_gpu.h" 14 | 15 | extern THCState *state; 16 | #define CHECK_CUDA(x) do { \ 17 | if (!x.type().is_cuda()) { \ 18 | fprintf(stderr, "%s must be CUDA tensor at %s:%d\n", #x, __FILE__, __LINE__); \ 19 | exit(-1); \ 20 | } \ 21 | } while (0) 22 | #define CHECK_CONTIGUOUS(x) do { \ 23 | if (!x.is_contiguous()) { \ 24 | fprintf(stderr, "%s must be contiguous tensor at %s:%d\n", #x, __FILE__, __LINE__); \ 25 | exit(-1); \ 26 | } \ 27 | } while (0) 28 | #define CHECK_INPUT(x) CHECK_CUDA(x);CHECK_CONTIGUOUS(x) 29 | 30 | 31 | int group_points_grad_wrapper_stack(int B, int M, int C, int N, int nsample, 32 | at::Tensor grad_out_tensor, at::Tensor idx_tensor, at::Tensor idx_batch_cnt_tensor, 33 | at::Tensor features_batch_cnt_tensor, at::Tensor grad_features_tensor) { 34 | 35 | CHECK_INPUT(grad_out_tensor); 36 | CHECK_INPUT(idx_tensor); 37 | CHECK_INPUT(idx_batch_cnt_tensor); 38 | CHECK_INPUT(features_batch_cnt_tensor); 39 | CHECK_INPUT(grad_features_tensor); 40 | 41 | const float *grad_out = grad_out_tensor.data(); 42 | const int *idx = idx_tensor.data(); 43 | const int *idx_batch_cnt = idx_batch_cnt_tensor.data(); 44 | const int *features_batch_cnt = features_batch_cnt_tensor.data(); 45 | float *grad_features = grad_features_tensor.data(); 46 | 47 | group_points_grad_kernel_launcher_stack(B, M, C, N, nsample, grad_out, idx, idx_batch_cnt, features_batch_cnt, grad_features); 48 | return 1; 49 | } 50 | 51 | 52 | int group_points_wrapper_stack(int B, int M, int C, int nsample, 53 | at::Tensor features_tensor, at::Tensor features_batch_cnt_tensor, 54 | at::Tensor idx_tensor, at::Tensor idx_batch_cnt_tensor, at::Tensor out_tensor) { 55 | 56 | CHECK_INPUT(features_tensor); 57 | CHECK_INPUT(features_batch_cnt_tensor); 58 | CHECK_INPUT(idx_tensor); 59 | CHECK_INPUT(idx_batch_cnt_tensor); 60 | CHECK_INPUT(out_tensor); 61 | 62 | const float *features = features_tensor.data(); 63 | const int *idx = idx_tensor.data(); 64 | const int *features_batch_cnt = features_batch_cnt_tensor.data(); 65 | const int *idx_batch_cnt = idx_batch_cnt_tensor.data(); 66 | float *out = out_tensor.data(); 67 | 68 | group_points_kernel_launcher_stack(B, M, C, nsample, features, features_batch_cnt, idx, idx_batch_cnt, out); 69 | return 1; 70 | } -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/pointnet2/pointnet2_stack/src/group_points_gpu.h: -------------------------------------------------------------------------------- 1 | /* 2 | Stacked-batch-data version of point grouping, modified from the original implementation of official PointNet++ codes. 3 | Written by Shaoshuai Shi 4 | All Rights Reserved 2019-2020. 5 | */ 6 | 7 | 8 | #ifndef _STACK_GROUP_POINTS_GPU_H 9 | #define _STACK_GROUP_POINTS_GPU_H 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | int group_points_wrapper_stack(int B, int M, int C, int nsample, 18 | at::Tensor features_tensor, at::Tensor features_batch_cnt_tensor, 19 | at::Tensor idx_tensor, at::Tensor idx_batch_cnt_tensor, at::Tensor out_tensor); 20 | 21 | void group_points_kernel_launcher_stack(int B, int M, int C, int nsample, 22 | const float *features, const int *features_batch_cnt, const int *idx, const int *idx_batch_cnt, float *out); 23 | 24 | int group_points_grad_wrapper_stack(int B, int M, int C, int N, int nsample, 25 | at::Tensor grad_out_tensor, at::Tensor idx_tensor, at::Tensor idx_batch_cnt_tensor, 26 | at::Tensor features_batch_cnt_tensor, at::Tensor grad_features_tensor); 27 | 28 | void group_points_grad_kernel_launcher_stack(int B, int M, int C, int N, int nsample, 29 | const float *grad_out, const int *idx, const int *idx_batch_cnt, const int *features_batch_cnt, float *grad_features); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/pointnet2/pointnet2_stack/src/interpolate_gpu.h: -------------------------------------------------------------------------------- 1 | #ifndef _INTERPOLATE_GPU_H 2 | #define _INTERPOLATE_GPU_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | 10 | void three_nn_wrapper_stack(at::Tensor unknown_tensor, 11 | at::Tensor unknown_batch_cnt_tensor, at::Tensor known_tensor, 12 | at::Tensor known_batch_cnt_tensor, at::Tensor dist2_tensor, at::Tensor idx_tensor); 13 | 14 | 15 | void three_interpolate_wrapper_stack(at::Tensor features_tensor, 16 | at::Tensor idx_tensor, at::Tensor weight_tensor, at::Tensor out_tensor); 17 | 18 | 19 | 20 | void three_interpolate_grad_wrapper_stack(at::Tensor grad_out_tensor, at::Tensor idx_tensor, 21 | at::Tensor weight_tensor, at::Tensor grad_features_tensor); 22 | 23 | 24 | void three_nn_kernel_launcher_stack(int batch_size, int N, int M, const float *unknown, 25 | const int *unknown_batch_cnt, const float *known, const int *known_batch_cnt, 26 | float *dist2, int *idx); 27 | 28 | 29 | void three_interpolate_kernel_launcher_stack(int N, int channels, 30 | const float *features, const int *idx, const float *weight, float *out); 31 | 32 | 33 | 34 | void three_interpolate_grad_kernel_launcher_stack(int N, int channels, const float *grad_out, 35 | const int *idx, const float *weight, float *grad_features); 36 | 37 | 38 | 39 | #endif -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/pointnet2/pointnet2_stack/src/pointnet2_api.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "ball_query_gpu.h" 5 | #include "group_points_gpu.h" 6 | #include "sampling_gpu.h" 7 | #include "interpolate_gpu.h" 8 | #include "voxel_query_gpu.h" 9 | #include "vector_pool_gpu.h" 10 | 11 | 12 | PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) { 13 | m.def("ball_query_wrapper", &ball_query_wrapper_stack, "ball_query_wrapper_stack"); 14 | m.def("voxel_query_wrapper", &voxel_query_wrapper_stack, "voxel_query_wrapper_stack"); 15 | 16 | m.def("farthest_point_sampling_wrapper", &farthest_point_sampling_wrapper, "farthest_point_sampling_wrapper"); 17 | m.def("stack_farthest_point_sampling_wrapper", &stack_farthest_point_sampling_wrapper, "stack_farthest_point_sampling_wrapper"); 18 | 19 | m.def("group_points_wrapper", &group_points_wrapper_stack, "group_points_wrapper_stack"); 20 | m.def("group_points_grad_wrapper", &group_points_grad_wrapper_stack, "group_points_grad_wrapper_stack"); 21 | 22 | m.def("three_nn_wrapper", &three_nn_wrapper_stack, "three_nn_wrapper_stack"); 23 | m.def("three_interpolate_wrapper", &three_interpolate_wrapper_stack, "three_interpolate_wrapper_stack"); 24 | m.def("three_interpolate_grad_wrapper", &three_interpolate_grad_wrapper_stack, "three_interpolate_grad_wrapper_stack"); 25 | 26 | m.def("query_stacked_local_neighbor_idxs_wrapper_stack", &query_stacked_local_neighbor_idxs_wrapper_stack, "query_stacked_local_neighbor_idxs_wrapper_stack"); 27 | m.def("query_three_nn_by_stacked_local_idxs_wrapper_stack", &query_three_nn_by_stacked_local_idxs_wrapper_stack, "query_three_nn_by_stacked_local_idxs_wrapper_stack"); 28 | 29 | m.def("vector_pool_wrapper", &vector_pool_wrapper_stack, "vector_pool_grad_wrapper_stack"); 30 | m.def("vector_pool_grad_wrapper", &vector_pool_grad_wrapper_stack, "vector_pool_grad_wrapper_stack"); 31 | } 32 | -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/pointnet2/pointnet2_stack/src/sampling.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "sampling_gpu.h" 7 | 8 | extern THCState *state; 9 | #define CHECK_CUDA(x) do { \ 10 | if (!x.type().is_cuda()) { \ 11 | fprintf(stderr, "%s must be CUDA tensor at %s:%d\n", #x, __FILE__, __LINE__); \ 12 | exit(-1); \ 13 | } \ 14 | } while (0) 15 | #define CHECK_CONTIGUOUS(x) do { \ 16 | if (!x.is_contiguous()) { \ 17 | fprintf(stderr, "%s must be contiguous tensor at %s:%d\n", #x, __FILE__, __LINE__); \ 18 | exit(-1); \ 19 | } \ 20 | } while (0) 21 | #define CHECK_INPUT(x) CHECK_CUDA(x);CHECK_CONTIGUOUS(x) 22 | 23 | 24 | int farthest_point_sampling_wrapper(int b, int n, int m, 25 | at::Tensor points_tensor, at::Tensor temp_tensor, at::Tensor idx_tensor) { 26 | 27 | CHECK_INPUT(points_tensor); 28 | CHECK_INPUT(temp_tensor); 29 | CHECK_INPUT(idx_tensor); 30 | 31 | const float *points = points_tensor.data(); 32 | float *temp = temp_tensor.data(); 33 | int *idx = idx_tensor.data(); 34 | 35 | farthest_point_sampling_kernel_launcher(b, n, m, points, temp, idx); 36 | return 1; 37 | } 38 | 39 | 40 | int stack_farthest_point_sampling_wrapper(at::Tensor points_tensor, 41 | at::Tensor temp_tensor, at::Tensor xyz_batch_cnt_tensor, at::Tensor idx_tensor, 42 | at::Tensor num_sampled_points_tensor) { 43 | 44 | CHECK_INPUT(points_tensor); 45 | CHECK_INPUT(temp_tensor); 46 | CHECK_INPUT(idx_tensor); 47 | CHECK_INPUT(xyz_batch_cnt_tensor); 48 | CHECK_INPUT(num_sampled_points_tensor); 49 | 50 | int batch_size = xyz_batch_cnt_tensor.size(0); 51 | int N = points_tensor.size(0); 52 | const float *points = points_tensor.data(); 53 | float *temp = temp_tensor.data(); 54 | int *xyz_batch_cnt = xyz_batch_cnt_tensor.data(); 55 | int *idx = idx_tensor.data(); 56 | int *num_sampled_points = num_sampled_points_tensor.data(); 57 | 58 | stack_farthest_point_sampling_kernel_launcher(N, batch_size, points, temp, xyz_batch_cnt, idx, num_sampled_points); 59 | return 1; 60 | } -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/pointnet2/pointnet2_stack/src/sampling_gpu.h: -------------------------------------------------------------------------------- 1 | #ifndef _SAMPLING_GPU_H 2 | #define _SAMPLING_GPU_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | int farthest_point_sampling_wrapper(int b, int n, int m, 10 | at::Tensor points_tensor, at::Tensor temp_tensor, at::Tensor idx_tensor); 11 | 12 | void farthest_point_sampling_kernel_launcher(int b, int n, int m, 13 | const float *dataset, float *temp, int *idxs); 14 | 15 | int stack_farthest_point_sampling_wrapper( 16 | at::Tensor points_tensor, at::Tensor temp_tensor, at::Tensor xyz_batch_cnt_tensor, 17 | at::Tensor idx_tensor, at::Tensor num_sampled_points_tensor); 18 | 19 | 20 | void stack_farthest_point_sampling_kernel_launcher(int N, int batch_size, 21 | const float *dataset, float *temp, int *xyz_batch_cnt, int *idxs, int *num_sampled_points); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/pointnet2/pointnet2_stack/src/vector_pool_gpu.h: -------------------------------------------------------------------------------- 1 | /* 2 | Vector-pool aggregation based local feature aggregation for point cloud. 3 | PV-RCNN++: Point-Voxel Feature Set Abstraction With Local Vector Representation for 3D Object Detection 4 | https://arxiv.org/abs/2102.00463 5 | 6 | Written by Shaoshuai Shi 7 | All Rights Reserved 2020. 8 | */ 9 | 10 | 11 | #ifndef _STACK_VECTOR_POOL_GPU_H 12 | #define _STACK_VECTOR_POOL_GPU_H 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | 20 | int query_stacked_local_neighbor_idxs_kernel_launcher_stack( 21 | const float *support_xyz, const int *xyz_batch_cnt, const float *new_xyz, const int *new_xyz_batch_cnt, 22 | int *stack_neighbor_idxs, int *start_len, int *cumsum, int avg_length_of_neighbor_idxs, 23 | float max_neighbour_distance, int batch_size, int M, int nsample, int neighbor_type); 24 | 25 | int query_stacked_local_neighbor_idxs_wrapper_stack(at::Tensor support_xyz_tensor, at::Tensor xyz_batch_cnt_tensor, 26 | at::Tensor new_xyz_tensor, at::Tensor new_xyz_batch_cnt_tensor, 27 | at::Tensor stack_neighbor_idxs_tensor, at::Tensor start_len_tensor, at::Tensor cumsum_tensor, 28 | int avg_length_of_neighbor_idxs, float max_neighbour_distance, int nsample, int neighbor_type); 29 | 30 | 31 | int query_three_nn_by_stacked_local_idxs_kernel_launcher_stack( 32 | const float *support_xyz, const float *new_xyz, const float *new_xyz_grid_centers, 33 | int *new_xyz_grid_idxs, float *new_xyz_grid_dist2, 34 | const int *stack_neighbor_idxs, const int *start_len, 35 | int M, int num_total_grids); 36 | 37 | int query_three_nn_by_stacked_local_idxs_wrapper_stack(at::Tensor support_xyz_tensor, 38 | at::Tensor new_xyz_tensor, at::Tensor new_xyz_grid_centers_tensor, 39 | at::Tensor new_xyz_grid_idxs_tensor, at::Tensor new_xyz_grid_dist2_tensor, 40 | at::Tensor stack_neighbor_idxs_tensor, at::Tensor start_len_tensor, 41 | int M, int num_total_grids); 42 | 43 | 44 | int vector_pool_wrapper_stack(at::Tensor support_xyz_tensor, at::Tensor xyz_batch_cnt_tensor, 45 | at::Tensor support_features_tensor, at::Tensor new_xyz_tensor, at::Tensor new_xyz_batch_cnt_tensor, 46 | at::Tensor new_features_tensor, at::Tensor new_local_xyz, 47 | at::Tensor point_cnt_of_grid_tensor, at::Tensor grouped_idxs_tensor, 48 | int num_grid_x, int num_grid_y, int num_grid_z, float max_neighbour_distance, int use_xyz, 49 | int num_max_sum_points, int nsample, int neighbor_type, int pooling_type); 50 | 51 | 52 | int vector_pool_kernel_launcher_stack( 53 | const float *support_xyz, const float *support_features, const int *xyz_batch_cnt, 54 | const float *new_xyz, float *new_features, float * new_local_xyz, const int *new_xyz_batch_cnt, 55 | int *point_cnt_of_grid, int *grouped_idxs, 56 | int num_grid_x, int num_grid_y, int num_grid_z, float max_neighbour_distance, 57 | int batch_size, int N, int M, int num_c_in, int num_c_out, int num_total_grids, int use_xyz, 58 | int num_max_sum_points, int nsample, int neighbor_type, int pooling_type); 59 | 60 | 61 | int vector_pool_grad_wrapper_stack(at::Tensor grad_new_features_tensor, 62 | at::Tensor point_cnt_of_grid_tensor, at::Tensor grouped_idxs_tensor, 63 | at::Tensor grad_support_features_tensor); 64 | 65 | 66 | void vector_pool_grad_kernel_launcher_stack( 67 | const float *grad_new_features, const int *point_cnt_of_grid, const int *grouped_idxs, 68 | float *grad_support_features, int N, int M, int num_c_out, int num_c_in, int num_total_grids, 69 | int num_max_sum_points); 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/pointnet2/pointnet2_stack/src/voxel_query.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "voxel_query_gpu.h" 10 | 11 | extern THCState *state; 12 | 13 | #define CHECK_CUDA(x) do { \ 14 | if (!x.type().is_cuda()) { \ 15 | fprintf(stderr, "%s must be CUDA tensor at %s:%d\n", #x, __FILE__, __LINE__); \ 16 | exit(-1); \ 17 | } \ 18 | } while (0) 19 | #define CHECK_CONTIGUOUS(x) do { \ 20 | if (!x.is_contiguous()) { \ 21 | fprintf(stderr, "%s must be contiguous tensor at %s:%d\n", #x, __FILE__, __LINE__); \ 22 | exit(-1); \ 23 | } \ 24 | } while (0) 25 | #define CHECK_INPUT(x) CHECK_CUDA(x);CHECK_CONTIGUOUS(x) 26 | 27 | 28 | int voxel_query_wrapper_stack(int M, int R1, int R2, int R3, int nsample, float radius, 29 | int z_range, int y_range, int x_range, at::Tensor new_xyz_tensor, at::Tensor xyz_tensor, 30 | at::Tensor new_coords_tensor, at::Tensor point_indices_tensor, at::Tensor idx_tensor) { 31 | CHECK_INPUT(new_coords_tensor); 32 | CHECK_INPUT(point_indices_tensor); 33 | CHECK_INPUT(new_xyz_tensor); 34 | CHECK_INPUT(xyz_tensor); 35 | 36 | const float *new_xyz = new_xyz_tensor.data(); 37 | const float *xyz = xyz_tensor.data(); 38 | const int *new_coords = new_coords_tensor.data(); 39 | const int *point_indices = point_indices_tensor.data(); 40 | int *idx = idx_tensor.data(); 41 | 42 | voxel_query_kernel_launcher_stack(M, R1, R2, R3, nsample, radius, z_range, y_range, x_range, new_xyz, xyz, new_coords, point_indices, idx); 43 | return 1; 44 | } 45 | -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/pointnet2/pointnet2_stack/src/voxel_query_gpu.h: -------------------------------------------------------------------------------- 1 | #ifndef _STACK_VOXEL_QUERY_GPU_H 2 | #define _STACK_VOXEL_QUERY_GPU_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | int voxel_query_wrapper_stack(int M, int R1, int R2, int R3, int nsample, float radius, 10 | int z_range, int y_range, int x_range, at::Tensor new_xyz_tensor, at::Tensor xyz_tensor, 11 | at::Tensor new_coords_tensor, at::Tensor point_indices_tensor, at::Tensor idx_tensor); 12 | 13 | 14 | void voxel_query_kernel_launcher_stack(int M, int R1, int R2, int R3, int nsample, 15 | float radius, int z_range, int y_range, int x_range, const float *new_xyz, 16 | const float *xyz, const int *new_coords, const int *point_indices, int *idx); 17 | 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/roiaware_pool3d/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/ops/roiaware_pool3d/__init__.py -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/roiaware_pool3d/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/ops/roiaware_pool3d/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/roiaware_pool3d/__pycache__/roiaware_pool3d_utils.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/ops/roiaware_pool3d/__pycache__/roiaware_pool3d_utils.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/roipoint_pool3d/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/ops/roipoint_pool3d/__init__.py -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/roipoint_pool3d/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/ops/roipoint_pool3d/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/roipoint_pool3d/__pycache__/roipoint_pool3d_utils.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/ops/roipoint_pool3d/__pycache__/roipoint_pool3d_utils.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/roipoint_pool3d/roipoint_pool3d_utils.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn as nn 3 | from torch.autograd import Function 4 | 5 | from ...utils import box_utils 6 | from . import roipoint_pool3d_cuda 7 | 8 | 9 | class RoIPointPool3d(nn.Module): 10 | def __init__(self, num_sampled_points=512, pool_extra_width=1.0): 11 | super().__init__() 12 | self.num_sampled_points = num_sampled_points 13 | self.pool_extra_width = pool_extra_width 14 | 15 | def forward(self, points, point_features, boxes3d): 16 | """ 17 | Args: 18 | points: (B, N, 3) 19 | point_features: (B, N, C) 20 | boxes3d: (B, M, 7), [x, y, z, dx, dy, dz, heading] 21 | 22 | Returns: 23 | pooled_features: (B, M, 512, 3 + C) 24 | pooled_empty_flag: (B, M) 25 | """ 26 | return RoIPointPool3dFunction.apply( 27 | points, point_features, boxes3d, self.pool_extra_width, self.num_sampled_points 28 | ) 29 | 30 | 31 | class RoIPointPool3dFunction(Function): 32 | @staticmethod 33 | def forward(ctx, points, point_features, boxes3d, pool_extra_width, num_sampled_points=512): 34 | """ 35 | Args: 36 | ctx: 37 | points: (B, N, 3) 38 | point_features: (B, N, C) 39 | boxes3d: (B, num_boxes, 7), [x, y, z, dx, dy, dz, heading] 40 | pool_extra_width: 41 | num_sampled_points: 42 | 43 | Returns: 44 | pooled_features: (B, num_boxes, 512, 3 + C) 45 | pooled_empty_flag: (B, num_boxes) 46 | """ 47 | assert points.shape.__len__() == 3 and points.shape[2] == 3 48 | batch_size, boxes_num, feature_len = points.shape[0], boxes3d.shape[1], point_features.shape[2] 49 | pooled_boxes3d = box_utils.enlarge_box3d(boxes3d.view(-1, 7), pool_extra_width).view(batch_size, -1, 7) 50 | 51 | pooled_features = point_features.new_zeros((batch_size, boxes_num, num_sampled_points, 3 + feature_len)) 52 | pooled_empty_flag = point_features.new_zeros((batch_size, boxes_num)).int() 53 | 54 | roipoint_pool3d_cuda.forward( 55 | points.contiguous(), pooled_boxes3d.contiguous(), 56 | point_features.contiguous(), pooled_features, pooled_empty_flag 57 | ) 58 | 59 | return pooled_features, pooled_empty_flag 60 | 61 | @staticmethod 62 | def backward(ctx, grad_out): 63 | raise NotImplementedError 64 | 65 | 66 | if __name__ == '__main__': 67 | pass 68 | -------------------------------------------------------------------------------- /openpcuct/pcdet/ops/roipoint_pool3d/src/roipoint_pool3d.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define CHECK_CUDA(x) do { \ 5 | if (!x.type().is_cuda()) { \ 6 | fprintf(stderr, "%s must be CUDA tensor at %s:%d\n", #x, __FILE__, __LINE__); \ 7 | exit(-1); \ 8 | } \ 9 | } while (0) 10 | #define CHECK_CONTIGUOUS(x) do { \ 11 | if (!x.is_contiguous()) { \ 12 | fprintf(stderr, "%s must be contiguous tensor at %s:%d\n", #x, __FILE__, __LINE__); \ 13 | exit(-1); \ 14 | } \ 15 | } while (0) 16 | #define CHECK_INPUT(x) CHECK_CUDA(x);CHECK_CONTIGUOUS(x) 17 | 18 | 19 | void roipool3dLauncher(int batch_size, int pts_num, int boxes_num, int feature_in_len, int sampled_pts_num, 20 | const float *xyz, const float *boxes3d, const float *pts_feature, float *pooled_features, int *pooled_empty_flag); 21 | 22 | 23 | int roipool3d_gpu(at::Tensor xyz, at::Tensor boxes3d, at::Tensor pts_feature, at::Tensor pooled_features, at::Tensor pooled_empty_flag){ 24 | // params xyz: (B, N, 3) 25 | // params boxes3d: (B, M, 7) 26 | // params pts_feature: (B, N, C) 27 | // params pooled_features: (B, M, 512, 3+C) 28 | // params pooled_empty_flag: (B, M) 29 | CHECK_INPUT(xyz); 30 | CHECK_INPUT(boxes3d); 31 | CHECK_INPUT(pts_feature); 32 | CHECK_INPUT(pooled_features); 33 | CHECK_INPUT(pooled_empty_flag); 34 | 35 | int batch_size = xyz.size(0); 36 | int pts_num = xyz.size(1); 37 | int boxes_num = boxes3d.size(1); 38 | int feature_in_len = pts_feature.size(2); 39 | int sampled_pts_num = pooled_features.size(2); 40 | 41 | 42 | const float * xyz_data = xyz.data(); 43 | const float * boxes3d_data = boxes3d.data(); 44 | const float * pts_feature_data = pts_feature.data(); 45 | float * pooled_features_data = pooled_features.data(); 46 | int * pooled_empty_flag_data = pooled_empty_flag.data(); 47 | 48 | roipool3dLauncher(batch_size, pts_num, boxes_num, feature_in_len, sampled_pts_num, 49 | xyz_data, boxes3d_data, pts_feature_data, pooled_features_data, pooled_empty_flag_data); 50 | 51 | 52 | 53 | return 1; 54 | } 55 | 56 | 57 | PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) { 58 | m.def("forward", &roipool3d_gpu, "roipool3d forward (CUDA)"); 59 | } 60 | 61 | -------------------------------------------------------------------------------- /openpcuct/pcdet/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcdet/utils/__init__.py -------------------------------------------------------------------------------- /openpcuct/pcdet/utils/spconv_utils.py: -------------------------------------------------------------------------------- 1 | from typing import Set 2 | 3 | try: 4 | import spconv.pytorch as spconv 5 | except: 6 | import spconv as spconv 7 | 8 | import torch.nn as nn 9 | 10 | 11 | def find_all_spconv_keys(model: nn.Module, prefix="") -> Set[str]: 12 | """ 13 | Finds all spconv keys that need to have weight's transposed 14 | """ 15 | found_keys: Set[str] = set() 16 | for name, child in model.named_children(): 17 | new_prefix = f"{prefix}.{name}" if prefix != "" else name 18 | 19 | if isinstance(child, spconv.conv.SparseConvolution): 20 | new_prefix = f"{new_prefix}.weight" 21 | found_keys.add(new_prefix) 22 | 23 | found_keys.update(find_all_spconv_keys(child, prefix=new_prefix)) 24 | 25 | return found_keys 26 | 27 | 28 | def replace_feature(out, new_features): 29 | if "replace_feature" in out.__dir__(): 30 | # spconv 2.x behaviour 31 | return out.replace_feature(new_features) 32 | else: 33 | out.features = new_features 34 | return out 35 | -------------------------------------------------------------------------------- /openpcuct/pcdet/utils/transform_utils.py: -------------------------------------------------------------------------------- 1 | import math 2 | import torch 3 | 4 | try: 5 | from kornia.geometry.conversions import ( 6 | convert_points_to_homogeneous, 7 | convert_points_from_homogeneous, 8 | ) 9 | except: 10 | pass 11 | # print('Warning: kornia is not installed. This package is only required by CaDDN') 12 | 13 | 14 | def project_to_image(project, points): 15 | """ 16 | Project points to image 17 | Args: 18 | project [torch.tensor(..., 3, 4)]: Projection matrix 19 | points [torch.Tensor(..., 3)]: 3D points 20 | Returns: 21 | points_img [torch.Tensor(..., 2)]: Points in image 22 | points_depth [torch.Tensor(...)]: Depth of each point 23 | """ 24 | # Reshape tensors to expected shape 25 | points = convert_points_to_homogeneous(points) 26 | points = points.unsqueeze(dim=-1) 27 | project = project.unsqueeze(dim=1) 28 | 29 | # Transform points to image and get depths 30 | points_t = project @ points 31 | points_t = points_t.squeeze(dim=-1) 32 | points_img = convert_points_from_homogeneous(points_t) 33 | points_depth = points_t[..., -1] - project[..., 2, 3] 34 | 35 | return points_img, points_depth 36 | 37 | 38 | def normalize_coords(coords, shape): 39 | """ 40 | Normalize coordinates of a grid between [-1, 1] 41 | Args: 42 | coords: (..., 3), Coordinates in grid 43 | shape: (3), Grid shape 44 | Returns: 45 | norm_coords: (.., 3), Normalized coordinates in grid 46 | """ 47 | min_n = -1 48 | max_n = 1 49 | shape = torch.flip(shape, dims=[0]) # Reverse ordering of shape 50 | 51 | # Subtract 1 since pixel indexing from [0, shape - 1] 52 | norm_coords = coords / (shape - 1) * (max_n - min_n) + min_n 53 | return norm_coords 54 | 55 | 56 | def bin_depths(depth_map, mode, depth_min, depth_max, num_bins, target=False): 57 | """ 58 | Converts depth map into bin indices 59 | Args: 60 | depth_map: (H, W), Depth Map 61 | mode: string, Discretiziation mode (See https://arxiv.org/pdf/2005.13423.pdf for more details) 62 | UD: Uniform discretiziation 63 | LID: Linear increasing discretiziation 64 | SID: Spacing increasing discretiziation 65 | depth_min: float, Minimum depth value 66 | depth_max: float, Maximum depth value 67 | num_bins: int, Number of depth bins 68 | target: bool, Whether the depth bins indices will be used for a target tensor in loss comparison 69 | Returns: 70 | indices: (H, W), Depth bin indices 71 | """ 72 | if mode == "UD": 73 | bin_size = (depth_max - depth_min) / num_bins 74 | indices = ((depth_map - depth_min) / bin_size) 75 | elif mode == "LID": 76 | bin_size = 2 * (depth_max - depth_min) / (num_bins * (1 + num_bins)) 77 | indices = -0.5 + 0.5 * torch.sqrt(1 + 8 * (depth_map - depth_min) / bin_size) 78 | elif mode == "SID": 79 | indices = num_bins * (torch.log(1 + depth_map) - math.log(1 + depth_min)) / \ 80 | (math.log(1 + depth_max) - math.log(1 + depth_min)) 81 | else: 82 | raise NotImplementedError 83 | 84 | if target: 85 | # Remove indicies outside of bounds 86 | mask = (indices < 0) | (indices > num_bins) | (~torch.isfinite(indices)) 87 | indices[mask] = num_bins 88 | 89 | # Convert to integer 90 | indices = indices.type(torch.int64) 91 | return indices 92 | -------------------------------------------------------------------------------- /openpcuct/pcdet/version.py: -------------------------------------------------------------------------------- 1 | __version__ = "0.5.2+5e47ee0" 2 | -------------------------------------------------------------------------------- /openpcuct/pcuct/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcuct/__init__.py -------------------------------------------------------------------------------- /openpcuct/pcuct/datasets/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcuct/datasets/__init__.py -------------------------------------------------------------------------------- /openpcuct/pcuct/datasets/kitti/__init__.py: -------------------------------------------------------------------------------- 1 | from .kitti_dataset import generate_predictive_distribution_kitti -------------------------------------------------------------------------------- /openpcuct/pcuct/datasets/kitti/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcuct/datasets/kitti/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcuct/datasets/kitti/__pycache__/kitti_dataset.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcuct/datasets/kitti/__pycache__/kitti_dataset.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcuct/datasets/kitti/kitti_dataset.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from pathlib import Path 3 | from det3.ops import write_pkl 4 | 5 | def is_cov_vec(covs): 6 | ''' 7 | Return True, if is in vector format. 8 | Args 9 | covs: (Tensor) 10 | ''' 11 | return len(covs.shape) == 2 12 | 13 | def is_cov_mat(covs): 14 | ''' 15 | Return True, if is in matrix format. 16 | Args 17 | covs: (Tensor) 18 | ''' 19 | return len(covs.shape) == 3 20 | 21 | def generate_predictive_distribution_kitti( 22 | batch_dict, 23 | pred_dicts, 24 | class_names, 25 | output_path=None): 26 | ''' 27 | Generate predictive distributions for the KITTI dataset. 28 | Args: 29 | batch_dict: 30 | frame_id: 31 | pred_dicts: list of pred_dicts 32 | pred_boxes: (N, 7), Tensor 33 | pred_scores: (N), Tensor 34 | pred_labels: (N), Tensor 35 | pdist_boxes_mean: (N, 7), pdist_boxes_mean, 36 | pdist_boxes_cov: (N, 7)/ (N, 7, 7), pdist_boxes_cov, 37 | class_names: 38 | output_path: 39 | Returns: 40 | pdist (List[Dict]) 41 | TODO: The pred_boxes are expected the same as the pred_boxes_mean 42 | (check by assertion). 43 | ''' 44 | for index, pred_dict in enumerate(pred_dicts): 45 | frame_id = batch_dict['frame_id'][index] 46 | d3_means = pred_dict['pdist_boxes_mean'].cpu().numpy().reshape(-1, 7) 47 | d3_covs = pred_dict['pdist_boxes_cov'].cpu().numpy() 48 | N = d3_means.shape[0] 49 | if is_cov_vec(d3_covs): 50 | d3_covs = d3_covs.reshape(-1, 7) 51 | assert d3_covs.shape[0] == N 52 | pdist = [] 53 | for d3_mean, d3_cov in zip(d3_means, d3_covs): 54 | bev_mean = d3_mean.reshape(-1)[[0,1,3,4,6]] 55 | bev_cov = d3_cov.reshape(-1)[[0,1,3,4,6]] 56 | pdist_ = { 57 | "post_mean_bev": bev_mean.reshape(-1, 5), 58 | "post_cov_bev": np.diag(bev_cov).reshape(5,5), 59 | "post_mean_3d": d3_mean.reshape(-1, 7), 60 | "post_cov_3d": np.diag(d3_cov).reshape(7,7), 61 | } 62 | pdist.append(pdist_) 63 | elif is_cov_mat(d3_covs): 64 | d3_covs = d3_covs.reshape(-1, 7, 7) 65 | assert d3_covs.shape[0] == N 66 | pdist = [] 67 | for d3_mean, d3_cov in zip(d3_means, d3_covs): 68 | bev_mean = d3_mean.reshape(-1)[[0,1,3,4,6]] 69 | bev_cov = np.concatenate( 70 | [d3_cov[i, [0,1,3,4,6]].reshape(1, 5) 71 | for i in [0,1,3,4,6]], axis=0) 72 | pdist_ = { 73 | "post_mean_bev": bev_mean.reshape(-1, 5), 74 | "post_cov_bev": bev_cov.reshape(5,5), 75 | "post_mean_3d": d3_mean.reshape(-1, 7), 76 | "post_cov_3d": d3_cov.reshape(7,7), 77 | } 78 | pdist.append(pdist_) 79 | else: 80 | raise NotImplementedError 81 | if output_path is not None: 82 | write_pkl(pdist, Path(output_path)/f"{frame_id}.pkl") 83 | return pdist 84 | -------------------------------------------------------------------------------- /openpcuct/pcuct/datasets/kitti/kitti_object_eval_python/__pycache__/eval.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcuct/datasets/kitti/kitti_object_eval_python/__pycache__/eval.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcuct/datasets/kitti/kitti_object_eval_python/__pycache__/kitti_common.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcuct/datasets/kitti/kitti_object_eval_python/__pycache__/kitti_common.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcuct/datasets/kitti/kitti_object_eval_python/evaluate.py: -------------------------------------------------------------------------------- 1 | import fire 2 | from pcdet.datasets.kitti.kitti_object_eval_python.evaluate \ 3 | import _read_imageset_file 4 | 5 | import kitti_common as kitti 6 | from eval import get_official_eval_result 7 | 8 | def evaluate_uct( 9 | label_path, 10 | label_uct_path, 11 | result_path, 12 | result_uct_path, 13 | calib_path, 14 | label_split_file, 15 | current_class=0, 16 | coco=False, 17 | score_thresh=-1): 18 | dt_annos = kitti.get_label_annos(result_path) 19 | dt_annos = kitti.get_uncertainty_annos(result_uct_path, dt_annos) 20 | dt_annos = kitti.get_calibs(calib_path, dt_annos, label_folder=result_path) 21 | if score_thresh > 0: 22 | dt_annos = kitti.filter_annos_low_score(dt_annos, score_thresh) 23 | val_image_ids = _read_imageset_file(label_split_file) 24 | gt_annos = kitti.get_label_annos(label_path, val_image_ids) 25 | gt_annos = kitti.get_uncertainty_annos(label_uct_path, gt_annos, val_image_ids) 26 | gt_annos = kitti.get_calibs(calib_path, gt_annos, image_ids=val_image_ids) 27 | if coco: 28 | err_msg = "COCO is not supported in evaluate_uct." 29 | raise NotImplementedError(err_msg) 30 | else: 31 | rtn = get_official_eval_result(gt_annos, dt_annos, current_class, bool_uct=True) 32 | kitti.save_eval_result(rtn, result_path) 33 | return rtn 34 | 35 | if __name__ == '__main__': 36 | fire.Fire() -------------------------------------------------------------------------------- /openpcuct/pcuct/gen_model/__init__.py: -------------------------------------------------------------------------------- 1 | from .vis import vis_spatial_uncertainty_bev, \ 2 | vis_spatial_uncertainty_3d 3 | from .label import uncertain_label_BEV, uncertain_label_3D 4 | from .jiou import label_uncertainty_IoU, label_uncertainty_IoU_3D 5 | from .infer import label_inference_BEV, label_inference_3D 6 | -------------------------------------------------------------------------------- /openpcuct/pcuct/gen_model/jiou.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Adapted from 3 | https://github.com/ZiningWang/Inferring-Spatial-Uncertainty-in-Object-Detection 4 | ''' 5 | import numpy as np 6 | import numba 7 | from .vis import generate_sample_points_3d, generate_sample_points_bev 8 | 9 | class label_uncertainty_IoU: 10 | ''' 11 | This class is for calculating the BEV JIoUs. 12 | ''' 13 | def __init__(self, grid_size=0.1, range=3.0): 14 | self.grid_size = grid_size 15 | self.range = range # sample upto how many times of the size of the car 16 | 17 | def calc_IoU(self, uncertain_label, pred_boxBEVs, sample_grid=0.1): 18 | from pcuct.ops.jiou.jiou_utils import Jaccard_discrete 19 | sample_points, _ = self.get_sample_points(uncertain_label) 20 | px = uncertain_label.sample_prob(sample_points, sample_grid=sample_grid) 21 | JIoUs = [] 22 | for i in range(len(pred_boxBEVs)): 23 | py = pred_boxBEVs[i].sample_prob(sample_points, sample_grid=sample_grid) 24 | if np.sum(py) > 0 and np.sum(px) > 0: 25 | JIoUs.append(Jaccard_discrete(px, py)) 26 | else: 27 | JIoUs.append(0) 28 | return JIoUs 29 | 30 | def get_sample_points(self, uncertain_label): 31 | return generate_sample_points_bev( 32 | self.range, self.grid_size, uncertain_label) 33 | 34 | class label_uncertainty_IoU_3D(label_uncertainty_IoU): 35 | ''' 36 | This class is for calculating the 3D JIoUs. 37 | ''' 38 | def calc_IoU(self, uncertain_label, pred_box3Ds, sample_grid=0.1): 39 | return super().calc_IoU(uncertain_label, pred_box3Ds, sample_grid) 40 | 41 | def get_sample_points(self, uncertain_label): 42 | return generate_sample_points_3d( 43 | self.range, self.grid_size, uncertain_label) 44 | 45 | -------------------------------------------------------------------------------- /openpcuct/pcuct/laplace_approx/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcuct/laplace_approx/__init__.py -------------------------------------------------------------------------------- /openpcuct/pcuct/laplace_approx/bayesian_models/__init__.py: -------------------------------------------------------------------------------- 1 | from .pointpillar import pointpillar_bayesian_inference 2 | from .second_net import second_net_bayesian_inference 3 | from .point_rcnn import point_rcnn_bayesian_inference 4 | from .pv_rcnn import pv_rcnn_bayesian_inference -------------------------------------------------------------------------------- /openpcuct/pcuct/laplace_approx/bayesian_models/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcuct/laplace_approx/bayesian_models/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcuct/laplace_approx/bayesian_models/__pycache__/point_rcnn.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcuct/laplace_approx/bayesian_models/__pycache__/point_rcnn.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcuct/laplace_approx/bayesian_models/__pycache__/pointpillar.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcuct/laplace_approx/bayesian_models/__pycache__/pointpillar.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcuct/laplace_approx/bayesian_models/__pycache__/pv_rcnn.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcuct/laplace_approx/bayesian_models/__pycache__/pv_rcnn.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcuct/laplace_approx/bayesian_models/__pycache__/second_net.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcuct/laplace_approx/bayesian_models/__pycache__/second_net.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcuct/laplace_approx/bayesian_models/pv_rcnn.py: -------------------------------------------------------------------------------- 1 | from .point_rcnn import point_rcnn_bayesian_inference 2 | 3 | def pv_rcnn_bayesian_inference( 4 | model, 5 | batch_dict, 6 | wdist_dict, 7 | num_MC_samples, 8 | pdist_prior): 9 | ''' 10 | Bayesian inference for PVRCNN. 11 | It adopts Monte-Carlo estimator to approximate 12 | the predictive distribution. and return it in 13 | . 14 | Args: 15 | model: nn.Module 16 | batch_dict: Dict 17 | wdist_dict: Dict 18 | num_MC_samples: int 19 | pdist_prior: Dict: prior predictive distribution. 20 | The covariance matrix of the predictive distribution is 21 | # cov = 2nd-moment(mean2) + prior - mean * mean 22 | e.g.{"batch_cls_preds": 1e-4, "batch_box_preds": 1e-4} 23 | Returns: 24 | pred_dicts, recall_dicts 25 | ''' 26 | # Its implementation is the same as point_rcnn. 27 | return point_rcnn_bayesian_inference(model, batch_dict, wdist_dict, num_MC_samples, pdist_prior) 28 | -------------------------------------------------------------------------------- /openpcuct/pcuct/laplace_approx/bayesian_models/second_net.py: -------------------------------------------------------------------------------- 1 | from .pointpillar import pointpillar_bayesian_inference 2 | 3 | def second_net_bayesian_inference( 4 | model, 5 | batch_dict, 6 | wdist_dict, 7 | num_MC_samples, 8 | pdist_prior, 9 | mode="full-net", 10 | dropout_rate=None): 11 | ''' 12 | Bayesian inference for SECONDNet. 13 | Args: 14 | model: nn.Module 15 | batch_dict: Dict 16 | wdist_dict: Dict 17 | num_MC_samples: int 18 | pdist_prior: Dict: prior predictive distribution. 19 | The covariance matrix of the predictive distribution is 20 | # cov = 2nd-moment(mean2) + prior - mean * mean 21 | e.g.{"batch_cls_preds": 1e-4, "batch_box_preds": 1e-4} 22 | mode: str: "full-net"/"last-layer"/"last-module"/"mcdropout" 23 | dropout_rate: float: dropout rate for MCDropout baseline (set as 1.0 will zero-out all elements). 24 | Returns: 25 | pred_dicts, recall_dicts 26 | ''' 27 | # Its implementation is the same as pointpillar. 28 | return pointpillar_bayesian_inference( 29 | model, batch_dict, wdist_dict, 30 | num_MC_samples, pdist_prior, mode, 31 | dropout_rate) 32 | -------------------------------------------------------------------------------- /openpcuct/pcuct/laplace_approx/fisher/__init__.py: -------------------------------------------------------------------------------- 1 | from .fisher import * -------------------------------------------------------------------------------- /openpcuct/pcuct/laplace_approx/fisher/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcuct/laplace_approx/fisher/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcuct/laplace_approx/fisher/__pycache__/fisher.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcuct/laplace_approx/fisher/__pycache__/fisher.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/pcuct/ops/jiou/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/pcuct/ops/jiou/__init__.py -------------------------------------------------------------------------------- /openpcuct/pcuct/ops/jiou/src/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef JIOU_UTILS_H 2 | #define JIOU_UTILS_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #define PI 3.1415926 12 | #define MAX_NUM_SP 30*30*30 13 | #define MAX_NUM_SP_BEV 30*30 14 | #define MAX_NUM_ZNORMED_BEV 10*10 15 | #define BEV_DIM 2 16 | #define MAX_NUM_SP_3D 30*30*30 17 | #define MAX_NUM_ZNORMED_3D 10*10*10 18 | #define D3_DIM 3 19 | 20 | namespace py = pybind11; 21 | using namespace std; 22 | 23 | template 24 | void argsort(scalar_t* arr, int* ids, const int N); 25 | 26 | template 27 | scalar_t matget( 28 | scalar_t* m, 29 | const int r, 30 | const int c, 31 | const int numr, 32 | const int numc, 33 | bool rtn_idx=false); 34 | 35 | template 36 | void gen_meshgrid_2d( 37 | scalar_t* sp, 38 | const int num_sp, 39 | const float grid_size, 40 | const float range); 41 | 42 | template 43 | void gen_meshgrid_3d( 44 | scalar_t* sp, 45 | const int num_sp, 46 | const float grid_size, 47 | const float range); 48 | 49 | template 50 | void add_mat_vec( 51 | scalar_t* m1, 52 | const int numr1, 53 | const int numc1, 54 | scalar_t* v, 55 | const int numrv, 56 | const int numcv, 57 | scalar_t* m, 58 | const int numr, 59 | const int numc); 60 | 61 | template 62 | void transpose( 63 | scalar_t* m, 64 | const int numr, 65 | const int numc, 66 | scalar_t* m_T); 67 | 68 | template 69 | void matmul( 70 | scalar_t* m1, 71 | const int numr1, 72 | const int numc1, 73 | scalar_t* m2, 74 | const int numr2, 75 | const int numc2, 76 | scalar_t* m); 77 | 78 | template 79 | scalar_t jaccard_discrete( 80 | scalar_t* px1, 81 | scalar_t* px2, 82 | const int num_sp); 83 | 84 | template 85 | scalar_t calc_multivariate_normal_pdf_bev( 86 | const int D, 87 | scalar_t* point, 88 | scalar_t* mean, 89 | scalar_t* cov); 90 | 91 | float calc_multivariate_normal_pdf_3d( 92 | const int D, 93 | Eigen::Vector3f& point, 94 | Eigen::Vector3f& mean, 95 | float cov_det, 96 | Eigen::Matrix3f& icov); 97 | 98 | #endif -------------------------------------------------------------------------------- /openpcuct/pcuct/utils/__init__.py: -------------------------------------------------------------------------------- 1 | from .debug_utils import * -------------------------------------------------------------------------------- /openpcuct/pcuct/utils/bayesian_utils.py: -------------------------------------------------------------------------------- 1 | from torch import distributions as dists 2 | 3 | def sample_from_weight_distribution( 4 | model, 5 | mean_dict, 6 | var_dict, 7 | modify_key_fn=lambda k: k): 8 | ''' 9 | Sample a point from the weight distribution, 10 | which is defined by and . 11 | Args: 12 | mean_dict 13 | var_dict 14 | modify_key_fn(lambda fn) 15 | Returns: 16 | model 17 | ''' 18 | return sample_with_diagonal_cov( 19 | model, mean_dict, var_dict, modify_key_fn) 20 | 21 | def sample_with_diagonal_cov( 22 | model, 23 | mean_dict, 24 | var_dict, 25 | modify_key_fn=lambda k: k): 26 | ''' 27 | Sample a point from the diagonal Normal posterior distribution, 28 | which is defined by and . 29 | Args: 30 | mean_dict 31 | var_dict 32 | modify_key_fn(lambda fn) 33 | Returns: 34 | model 35 | ''' 36 | std_dict = {k: v**0.5 for k, v in var_dict.items()} 37 | state_dict = model.state_dict() 38 | for name, _ in model.named_parameters(): 39 | mean = mean_dict[modify_key_fn(name)] 40 | std = std_dict[modify_key_fn(name)] 41 | # only sample those parameters with positive std 42 | sample_mask = std > 0 43 | state_dict[name] = mean.clone() 44 | state_dict[name][sample_mask] = dists.normal.Normal(mean[sample_mask], std[sample_mask]).sample() 45 | model.load_state_dict(state_dict) 46 | return model 47 | -------------------------------------------------------------------------------- /openpcuct/pcuct/utils/debug_utils.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import time 3 | import sys 4 | import numpy as np 5 | 6 | def printr(obj, pref=""): 7 | if isinstance(obj, dict): 8 | for k, v in obj.items(): 9 | printr(v, pref=f"{pref}{k}:") 10 | return 11 | elif isinstance(obj, list): 12 | for i, itm in enumerate(obj): 13 | printr(itm, pref=f"{pref}{i}-") 14 | return 15 | elif type(obj) in [int, float, str, bool, type(None), tuple]: 16 | print(f"{pref} {obj}") 17 | elif isinstance(obj, np.ndarray): 18 | print(f"{pref} {obj.shape}") 19 | elif isinstance(obj, torch.Tensor): 20 | print(f"{pref} {obj.shape}") 21 | else: 22 | try: 23 | print(f"{pref} {obj.shape}") 24 | except: 25 | wrn_msg = f"Unrecognized type: {type(obj)}" 26 | print(wrn_msg) 27 | print(obj) 28 | 29 | class Debug: 30 | def __init__(self, exit=True, s='Debug'): 31 | self.s = s 32 | self.exit = exit 33 | 34 | def __enter__(self): 35 | print(f"========= {self.s} START =========") 36 | 37 | def __exit__(self, type, value, traceback): 38 | if traceback is not None: 39 | print(f"========= {self.s} END =========") 40 | return 41 | if self.exit: 42 | sys.exit(f"========= {self.s} END =========") 43 | else: 44 | print(f"========= {self.s} END =========") 45 | 46 | class Timer: 47 | def __init__(self, s='Timer'): 48 | self.s = s 49 | self.start_time = None 50 | 51 | def __enter__(self): 52 | self.start_time = time.time() 53 | 54 | def __exit__(self, type, value, traceback): 55 | print(f"========= {self.s} {time.time()-self.start_time:.3f} =========") -------------------------------------------------------------------------------- /openpcuct/setup_pcuct.py: -------------------------------------------------------------------------------- 1 | import os 2 | import subprocess 3 | 4 | from setuptools import find_packages, setup 5 | from torch.utils.cpp_extension import BuildExtension, CUDAExtension 6 | 7 | 8 | def get_git_commit_number(): 9 | if not os.path.exists('.git'): 10 | return '0000000' 11 | 12 | cmd_out = subprocess.run(['git', 'rev-parse', 'HEAD'], stdout=subprocess.PIPE) 13 | git_commit_number = cmd_out.stdout.decode('utf-8')[:7] 14 | return git_commit_number 15 | 16 | 17 | def make_cuda_ext(name, module, sources, **kwargs): 18 | root_dir = os.path.abspath(__file__) 19 | root_dir = os.path.dirname(root_dir) 20 | include_dirs = kwargs.get("include_dirs", []) 21 | include_dirs = [os.path.join(root_dir, *module.split('.'), inc) for inc in include_dirs] 22 | kwargs.pop("include_dirs") 23 | cuda_ext = CUDAExtension( 24 | name='%s.%s' % (module, name), 25 | sources=[os.path.join(*module.split('.'), src) for src in sources], 26 | include_dirs=include_dirs, 27 | **kwargs 28 | ) 29 | return cuda_ext 30 | 31 | 32 | def write_version_to_file(version, target_file): 33 | with open(target_file, 'w') as f: 34 | print('__version__ = "%s"' % version, file=f) 35 | 36 | 37 | if __name__ == '__main__': 38 | version = '0.1+%s' % get_git_commit_number() 39 | 40 | setup( 41 | name='pcuct', 42 | version=version, 43 | packages=find_packages(exclude=['tools', 'data', 'output']), 44 | cmdclass={ 45 | 'build_ext': BuildExtension, 46 | }, 47 | ext_modules=[ 48 | make_cuda_ext( 49 | name='jiou_3d_cpp', 50 | module='pcuct.ops.jiou', 51 | sources=[ 52 | 'src/jiou_3d.cpp', 53 | ], 54 | include_dirs=["include/eigen/"], 55 | extra_compile_args=['-fopenmp'] 56 | ), 57 | make_cuda_ext( 58 | name='jiou_bev_cpp', 59 | module='pcuct.ops.jiou', 60 | sources=[ 61 | 'src/jiou_bev.cpp', 62 | ], 63 | include_dirs=["include/eigen/"], 64 | extra_compile_args=['-fopenmp'] 65 | ), 66 | ], 67 | ) 68 | -------------------------------------------------------------------------------- /openpcuct/tools/_init_path.py: -------------------------------------------------------------------------------- 1 | import sys 2 | sys.path.insert(0, '../') -------------------------------------------------------------------------------- /openpcuct/tools/cfgs/dataset_configs/kitti_dataset.yaml: -------------------------------------------------------------------------------- 1 | DATASET: 'KittiDataset' 2 | DATA_PATH: '../data/kitti' 3 | 4 | POINT_CLOUD_RANGE: [0, -40, -3, 70.4, 40, 1] 5 | 6 | DATA_SPLIT: { 7 | 'train': train, 8 | 'test': val 9 | } 10 | 11 | INFO_PATH: { 12 | 'train': [kitti_infos_train.pkl], 13 | 'test': [kitti_infos_val.pkl], 14 | } 15 | 16 | GET_ITEM_LIST: ["points"] 17 | FOV_POINTS_ONLY: True 18 | 19 | DATA_AUGMENTOR: 20 | DISABLE_AUG_LIST: ['placeholder'] 21 | AUG_CONFIG_LIST: 22 | - NAME: gt_sampling 23 | USE_ROAD_PLANE: True 24 | DB_INFO_PATH: 25 | - kitti_dbinfos_train.pkl 26 | PREPARE: { 27 | filter_by_min_points: ['Car:5', 'Pedestrian:5', 'Cyclist:5'], 28 | filter_by_difficulty: [-1], 29 | } 30 | 31 | SAMPLE_GROUPS: ['Car:20','Pedestrian:15', 'Cyclist:15'] 32 | NUM_POINT_FEATURES: 4 33 | DATABASE_WITH_FAKELIDAR: False 34 | REMOVE_EXTRA_WIDTH: [0.0, 0.0, 0.0] 35 | LIMIT_WHOLE_SCENE: True 36 | 37 | - NAME: random_world_flip 38 | ALONG_AXIS_LIST: ['x'] 39 | 40 | - NAME: random_world_rotation 41 | WORLD_ROT_ANGLE: [-0.78539816, 0.78539816] 42 | 43 | - NAME: random_world_scaling 44 | WORLD_SCALE_RANGE: [0.95, 1.05] 45 | 46 | 47 | POINT_FEATURE_ENCODING: { 48 | encoding_type: absolute_coordinates_encoding, 49 | used_feature_list: ['x', 'y', 'z', 'intensity'], 50 | src_feature_list: ['x', 'y', 'z', 'intensity'], 51 | } 52 | 53 | 54 | DATA_PROCESSOR: 55 | - NAME: mask_points_and_boxes_outside_range 56 | REMOVE_OUTSIDE_BOXES: True 57 | 58 | - NAME: shuffle_points 59 | SHUFFLE_ENABLED: { 60 | 'train': True, 61 | 'test': False 62 | } 63 | 64 | - NAME: transform_points_to_voxels 65 | VOXEL_SIZE: [0.05, 0.05, 0.1] 66 | MAX_POINTS_PER_VOXEL: 5 67 | MAX_NUMBER_OF_VOXELS: { 68 | 'train': 16000, 69 | 'test': 40000 70 | } 71 | -------------------------------------------------------------------------------- /openpcuct/tools/cfgs/dataset_configs/lyft_dataset.yaml: -------------------------------------------------------------------------------- 1 | DATASET: 'LyftDataset' 2 | DATA_PATH: '../data/lyft' 3 | 4 | VERSION: 'trainval' 5 | SET_NAN_VELOCITY_TO_ZEROS: True 6 | FILTER_MIN_POINTS_IN_GT: 1 7 | MAX_SWEEPS: 5 8 | EVAL_LYFT_IOU_LIST: [0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95] 9 | 10 | DATA_SPLIT: { 11 | 'train': train, 12 | 'test': val 13 | } 14 | 15 | INFO_PATH: { 16 | 'train': [lyft_infos_train.pkl], 17 | 'test': [lyft_infos_val.pkl], 18 | } 19 | 20 | POINT_CLOUD_RANGE: [-80.0, -80.0, -5.0, 80.0, 80.0, 3.0] 21 | 22 | DATA_AUGMENTOR: 23 | DISABLE_AUG_LIST: ['placeholder'] 24 | AUG_CONFIG_LIST: 25 | - NAME: gt_sampling 26 | DB_INFO_PATH: 27 | - lyft_dbinfos_10sweeps.pkl 28 | PREPARE: { 29 | filter_by_min_points: [ 30 | 'car:5','pedestrian:5', 'motorcycle:5', 'bicycle:5', 'other_vehicle:5', 31 | 'bus:5', 'truck:5', 'emergency_vehicle:5', 'animal:5' 32 | ], 33 | } 34 | 35 | SAMPLE_GROUPS: [ 36 | 'car:3','pedestrian:3', 'motorcycle:6', 'bicycle:6', 'other_vehicle:4', 37 | 'bus:4', 'truck:3', 'emergency_vehicle:7', 'animal:3' 38 | ] 39 | 40 | NUM_POINT_FEATURES: 5 41 | DATABASE_WITH_FAKELIDAR: False 42 | REMOVE_EXTRA_WIDTH: [0.0, 0.0, 0.0] 43 | LIMIT_WHOLE_SCENE: True 44 | 45 | - NAME: random_world_flip 46 | ALONG_AXIS_LIST: ['x', 'y'] 47 | 48 | - NAME: random_world_rotation 49 | WORLD_ROT_ANGLE: [-0.3925, 0.3925] 50 | 51 | - NAME: random_world_scaling 52 | WORLD_SCALE_RANGE: [0.95, 1.05] 53 | 54 | 55 | POINT_FEATURE_ENCODING: { 56 | encoding_type: absolute_coordinates_encoding, 57 | used_feature_list: ['x', 'y', 'z', 'intensity', 'timestamp'], 58 | src_feature_list: ['x', 'y', 'z', 'intensity', 'timestamp'], 59 | } 60 | 61 | 62 | DATA_PROCESSOR: 63 | - NAME: mask_points_and_boxes_outside_range 64 | REMOVE_OUTSIDE_BOXES: True 65 | 66 | - NAME: shuffle_points 67 | SHUFFLE_ENABLED: { 68 | 'train': True, 69 | 'test': True 70 | } 71 | 72 | - NAME: transform_points_to_voxels 73 | VOXEL_SIZE: [0.1, 0.1, 0.2] 74 | MAX_POINTS_PER_VOXEL: 10 75 | MAX_NUMBER_OF_VOXELS: { 76 | 'train': 80000, 77 | 'test': 80000 78 | } -------------------------------------------------------------------------------- /openpcuct/tools/cfgs/dataset_configs/nuscenes_dataset.yaml: -------------------------------------------------------------------------------- 1 | DATASET: 'NuScenesDataset' 2 | DATA_PATH: '../data/nuscenes' 3 | 4 | VERSION: 'v1.0-trainval' 5 | MAX_SWEEPS: 10 6 | PRED_VELOCITY: True 7 | SET_NAN_VELOCITY_TO_ZEROS: True 8 | FILTER_MIN_POINTS_IN_GT: 1 9 | 10 | DATA_SPLIT: { 11 | 'train': train, 12 | 'test': val 13 | } 14 | 15 | INFO_PATH: { 16 | 'train': [nuscenes_infos_10sweeps_train.pkl], 17 | 'test': [nuscenes_infos_10sweeps_val.pkl], 18 | } 19 | 20 | POINT_CLOUD_RANGE: [-51.2, -51.2, -5.0, 51.2, 51.2, 3.0] 21 | 22 | BALANCED_RESAMPLING: True 23 | 24 | DATA_AUGMENTOR: 25 | DISABLE_AUG_LIST: ['placeholder'] 26 | AUG_CONFIG_LIST: 27 | - NAME: gt_sampling 28 | DB_INFO_PATH: 29 | - nuscenes_dbinfos_10sweeps_withvelo.pkl 30 | PREPARE: { 31 | filter_by_min_points: [ 32 | 'car:5','truck:5', 'construction_vehicle:5', 'bus:5', 'trailer:5', 33 | 'barrier:5', 'motorcycle:5', 'bicycle:5', 'pedestrian:5', 'traffic_cone:5' 34 | ], 35 | } 36 | 37 | SAMPLE_GROUPS: [ 38 | 'car:2','truck:3', 'construction_vehicle:7', 'bus:4', 'trailer:6', 39 | 'barrier:2', 'motorcycle:6', 'bicycle:6', 'pedestrian:2', 'traffic_cone:2' 40 | ] 41 | 42 | NUM_POINT_FEATURES: 5 43 | DATABASE_WITH_FAKELIDAR: False 44 | REMOVE_EXTRA_WIDTH: [0.0, 0.0, 0.0] 45 | LIMIT_WHOLE_SCENE: True 46 | 47 | - NAME: random_world_flip 48 | ALONG_AXIS_LIST: ['x', 'y'] 49 | 50 | - NAME: random_world_rotation 51 | WORLD_ROT_ANGLE: [-0.3925, 0.3925] 52 | 53 | - NAME: random_world_scaling 54 | WORLD_SCALE_RANGE: [0.95, 1.05] 55 | 56 | 57 | POINT_FEATURE_ENCODING: { 58 | encoding_type: absolute_coordinates_encoding, 59 | used_feature_list: ['x', 'y', 'z', 'intensity', 'timestamp'], 60 | src_feature_list: ['x', 'y', 'z', 'intensity', 'timestamp'], 61 | } 62 | 63 | 64 | DATA_PROCESSOR: 65 | - NAME: mask_points_and_boxes_outside_range 66 | REMOVE_OUTSIDE_BOXES: True 67 | 68 | - NAME: shuffle_points 69 | SHUFFLE_ENABLED: { 70 | 'train': True, 71 | 'test': True 72 | } 73 | 74 | - NAME: transform_points_to_voxels 75 | VOXEL_SIZE: [0.1, 0.1, 0.2] 76 | MAX_POINTS_PER_VOXEL: 10 77 | MAX_NUMBER_OF_VOXELS: { 78 | 'train': 60000, 79 | 'test': 60000 80 | } 81 | -------------------------------------------------------------------------------- /openpcuct/tools/cfgs/dataset_configs/waymo_dataset.yaml: -------------------------------------------------------------------------------- 1 | DATASET: 'WaymoDataset' 2 | DATA_PATH: '../data/waymo' 3 | PROCESSED_DATA_TAG: 'waymo_processed_data_v0_5_0' 4 | 5 | POINT_CLOUD_RANGE: [-75.2, -75.2, -2, 75.2, 75.2, 4] 6 | 7 | DATA_SPLIT: { 8 | 'train': train, 9 | 'test': val 10 | } 11 | 12 | SAMPLED_INTERVAL: { 13 | 'train': 5, 14 | 'test': 1 15 | } 16 | 17 | FILTER_EMPTY_BOXES_FOR_TRAIN: True 18 | DISABLE_NLZ_FLAG_ON_POINTS: True 19 | 20 | USE_SHARED_MEMORY: False # it will load the data to shared memory to speed up (DO NOT USE IT IF YOU DO NOT FULLY UNDERSTAND WHAT WILL HAPPEN) 21 | SHARED_MEMORY_FILE_LIMIT: 35000 # set it based on the size of your shared memory 22 | 23 | DATA_AUGMENTOR: 24 | DISABLE_AUG_LIST: ['placeholder'] 25 | AUG_CONFIG_LIST: 26 | - NAME: gt_sampling 27 | USE_ROAD_PLANE: False 28 | DB_INFO_PATH: 29 | - waymo_processed_data_v0_5_0_waymo_dbinfos_train_sampled_1.pkl 30 | 31 | USE_SHARED_MEMORY: False # set it to True to speed up (it costs about 15GB shared memory) 32 | DB_DATA_PATH: 33 | - waymo_processed_data_v0_5_0_gt_database_train_sampled_1_global.npy 34 | 35 | PREPARE: { 36 | filter_by_min_points: ['Vehicle:5', 'Pedestrian:5', 'Cyclist:5'], 37 | filter_by_difficulty: [-1], 38 | } 39 | 40 | SAMPLE_GROUPS: ['Vehicle:15', 'Pedestrian:10', 'Cyclist:10'] 41 | NUM_POINT_FEATURES: 5 42 | REMOVE_EXTRA_WIDTH: [0.0, 0.0, 0.0] 43 | LIMIT_WHOLE_SCENE: True 44 | 45 | - NAME: random_world_flip 46 | ALONG_AXIS_LIST: ['x', 'y'] 47 | 48 | - NAME: random_world_rotation 49 | WORLD_ROT_ANGLE: [-0.78539816, 0.78539816] 50 | 51 | - NAME: random_world_scaling 52 | WORLD_SCALE_RANGE: [0.95, 1.05] 53 | 54 | 55 | POINT_FEATURE_ENCODING: { 56 | encoding_type: absolute_coordinates_encoding, 57 | used_feature_list: ['x', 'y', 'z', 'intensity', 'elongation'], 58 | src_feature_list: ['x', 'y', 'z', 'intensity', 'elongation'], 59 | } 60 | 61 | 62 | DATA_PROCESSOR: 63 | - NAME: mask_points_and_boxes_outside_range 64 | REMOVE_OUTSIDE_BOXES: True 65 | 66 | - NAME: shuffle_points 67 | SHUFFLE_ENABLED: { 68 | 'train': True, 69 | 'test': True 70 | } 71 | 72 | - NAME: transform_points_to_voxels 73 | VOXEL_SIZE: [0.1, 0.1, 0.15] 74 | MAX_POINTS_PER_VOXEL: 5 75 | MAX_NUMBER_OF_VOXELS: { 76 | 'train': 150000, 77 | 'test': 150000 78 | } 79 | -------------------------------------------------------------------------------- /openpcuct/tools/eval_utils/__pycache__/eval_utils.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/openpcuct/tools/eval_utils/__pycache__/eval_utils.cpython-37.pyc -------------------------------------------------------------------------------- /openpcuct/tools/scripts/clear_gpus.sh: -------------------------------------------------------------------------------- 1 | kill -9 $(pgrep python3) $(pgrep python) 2 | -------------------------------------------------------------------------------- /openpcuct/tools/scripts/setup.sh: -------------------------------------------------------------------------------- 1 | ROOT_DIR=$1 2 | 3 | cd $ROOT_DIR/../det3/ops/src/ 4 | python3 setup.py build && python3 setup.py install 5 | echo "export PYTHONPATH=${PYTHONPATH}:/usr/app/" >> ~/.bashrc 6 | 7 | cd $ROOT_DIR/pcuct/ops/jiou/ 8 | mkdir include 9 | cd include/ 10 | git clone https://gitlab.com/libeigen/eigen.git -b 3.4 11 | cd $ROOT_DIR 12 | python setup_pcuct.py develop 13 | cd $ROOT_DIR 14 | python setup.py develop 15 | 16 | pip install matplotlib pandas xlsxwriter 17 | -------------------------------------------------------------------------------- /openpcuct/tools/train_utils/optimization/__init__.py: -------------------------------------------------------------------------------- 1 | from functools import partial 2 | 3 | import torch.nn as nn 4 | import torch.optim as optim 5 | import torch.optim.lr_scheduler as lr_sched 6 | 7 | from .fastai_optim import OptimWrapper 8 | from .learning_schedules_fastai import CosineWarmupLR, OneCycle 9 | 10 | 11 | def build_optimizer(model, optim_cfg): 12 | if optim_cfg.OPTIMIZER == 'adam': 13 | optimizer = optim.Adam(model.parameters(), lr=optim_cfg.LR, weight_decay=optim_cfg.WEIGHT_DECAY) 14 | elif optim_cfg.OPTIMIZER == 'sgd': 15 | optimizer = optim.SGD( 16 | model.parameters(), lr=optim_cfg.LR, weight_decay=optim_cfg.WEIGHT_DECAY, 17 | momentum=optim_cfg.MOMENTUM 18 | ) 19 | elif optim_cfg.OPTIMIZER == 'adam_onecycle': 20 | def children(m: nn.Module): 21 | return list(m.children()) 22 | 23 | def num_children(m: nn.Module) -> int: 24 | return len(children(m)) 25 | 26 | flatten_model = lambda m: sum(map(flatten_model, m.children()), []) if num_children(m) else [m] 27 | get_layer_groups = lambda m: [nn.Sequential(*flatten_model(m))] 28 | 29 | optimizer_func = partial(optim.Adam, betas=(0.9, 0.99)) 30 | optimizer = OptimWrapper.create( 31 | optimizer_func, 3e-3, get_layer_groups(model), wd=optim_cfg.WEIGHT_DECAY, true_wd=True, bn_wd=True 32 | ) 33 | else: 34 | raise NotImplementedError 35 | 36 | return optimizer 37 | 38 | 39 | def build_scheduler(optimizer, total_iters_each_epoch, total_epochs, last_epoch, optim_cfg): 40 | decay_steps = [x * total_iters_each_epoch for x in optim_cfg.DECAY_STEP_LIST] 41 | def lr_lbmd(cur_epoch): 42 | cur_decay = 1 43 | for decay_step in decay_steps: 44 | if cur_epoch >= decay_step: 45 | cur_decay = cur_decay * optim_cfg.LR_DECAY 46 | return max(cur_decay, optim_cfg.LR_CLIP / optim_cfg.LR) 47 | 48 | lr_warmup_scheduler = None 49 | total_steps = total_iters_each_epoch * total_epochs 50 | if optim_cfg.OPTIMIZER == 'adam_onecycle': 51 | lr_scheduler = OneCycle( 52 | optimizer, total_steps, optim_cfg.LR, list(optim_cfg.MOMS), optim_cfg.DIV_FACTOR, optim_cfg.PCT_START 53 | ) 54 | else: 55 | lr_scheduler = lr_sched.LambdaLR(optimizer, lr_lbmd, last_epoch=last_epoch) 56 | 57 | if optim_cfg.LR_WARMUP: 58 | lr_warmup_scheduler = CosineWarmupLR( 59 | optimizer, T_max=optim_cfg.WARMUP_EPOCH * len(total_iters_each_epoch), 60 | eta_min=optim_cfg.LR / optim_cfg.DIV_FACTOR 61 | ) 62 | 63 | return lr_scheduler, lr_warmup_scheduler 64 | -------------------------------------------------------------------------------- /validate_data/experiment_data/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/validate_data/experiment_data/.gitignore -------------------------------------------------------------------------------- /validate_data/result_data/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyun-ram/OpenPCUCT/b0371754da279017708ac90c3434f67f2b8b5835/validate_data/result_data/.gitignore --------------------------------------------------------------------------------