Skip to content

Commit

Permalink
Demo
Browse files Browse the repository at this point in the history
  • Loading branch information
xavierwu95 authored and ZwwWayne committed Jun 29, 2020
1 parent 4eebf2c commit aee606f
Show file tree
Hide file tree
Showing 18 changed files with 341 additions and 84 deletions.
11 changes: 8 additions & 3 deletions configs/_base_/datasets/kitti-3d-3class.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@
pipeline=train_pipeline,
modality=input_modality,
classes=class_names,
test_mode=False)),
test_mode=False,
# we use box_type_3d='LiDAR' in kitti and nuscenes dataset
# and box_type_3d='Depth' in sunrgbd and scannet dataset.
box_type_3d='LiDAR')),
val=dict(
type=dataset_type,
data_root=data_root,
Expand All @@ -103,7 +106,8 @@
pipeline=test_pipeline,
modality=input_modality,
classes=class_names,
test_mode=True),
test_mode=True,
box_type_3d='LiDAR'),
test=dict(
type=dataset_type,
data_root=data_root,
Expand All @@ -113,6 +117,7 @@
pipeline=test_pipeline,
modality=input_modality,
classes=class_names,
test_mode=True))
test_mode=True,
box_type_3d='LiDAR'))

evaluation = dict(interval=1)
11 changes: 8 additions & 3 deletions configs/_base_/datasets/kitti-3d-car.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@
pipeline=train_pipeline,
modality=input_modality,
classes=class_names,
test_mode=False)),
test_mode=False,
# we use box_type_3d='LiDAR' in kitti and nuscenes dataset
# and box_type_3d='Depth' in sunrgbd and scannet dataset.
box_type_3d='LiDAR')),
val=dict(
type=dataset_type,
data_root=data_root,
Expand All @@ -101,7 +104,8 @@
pipeline=test_pipeline,
modality=input_modality,
classes=class_names,
test_mode=True),
test_mode=True,
box_type_3d='LiDAR'),
test=dict(
type=dataset_type,
data_root=data_root,
Expand All @@ -111,6 +115,7 @@
pipeline=test_pipeline,
modality=input_modality,
classes=class_names,
test_mode=True))
test_mode=True,
box_type_3d='LiDAR'))

evaluation = dict(interval=1)
11 changes: 8 additions & 3 deletions configs/_base_/datasets/nus-3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,23 +92,28 @@
pipeline=train_pipeline,
classes=class_names,
modality=input_modality,
test_mode=False),
test_mode=False,
# we use box_type_3d='LiDAR' in kitti and nuscenes dataset
# and box_type_3d='Depth' in sunrgbd and scannet dataset.
box_type_3d='LiDAR'),
val=dict(
type=dataset_type,
data_root=data_root,
ann_file=data_root + 'nuscenes_infos_val.pkl',
pipeline=test_pipeline,
classes=class_names,
modality=input_modality,
test_mode=True),
test_mode=True,
box_type_3d='LiDAR'),
test=dict(
type=dataset_type,
data_root=data_root,
ann_file=data_root + 'nuscenes_infos_val.pkl',
pipeline=test_pipeline,
classes=class_names,
modality=input_modality,
test_mode=True))
test_mode=True,
box_type_3d='LiDAR'))
# For nuScenes dataset, we usually evaluate the model at the end of training.
# Since the models are trained by 24 epochs by default, we set evaluation
# interval to be 24. Please change the interval accordingly if you do not
Expand Down
11 changes: 8 additions & 3 deletions configs/_base_/datasets/scannet-3d-18class.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,23 @@
ann_file=data_root + 'scannet_infos_train.pkl',
pipeline=train_pipeline,
filter_empty_gt=False,
classes=class_names)),
classes=class_names,
# we use box_type_3d='LiDAR' in kitti and nuscenes dataset
# and box_type_3d='Depth' in sunrgbd and scannet dataset.
box_type_3d='Depth')),
val=dict(
type=dataset_type,
data_root=data_root,
ann_file=data_root + 'scannet_infos_val.pkl',
pipeline=test_pipeline,
classes=class_names,
test_mode=True),
test_mode=True,
box_type_3d='Depth'),
test=dict(
type=dataset_type,
data_root=data_root,
ann_file=data_root + 'scannet_infos_val.pkl',
pipeline=test_pipeline,
classes=class_names,
test_mode=True))
test_mode=True,
box_type_3d='Depth'))
11 changes: 8 additions & 3 deletions configs/_base_/datasets/sunrgbd-3d-10class.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,23 @@
ann_file=data_root + 'sunrgbd_infos_train.pkl',
pipeline=train_pipeline,
classes=class_names,
filter_empty_gt=False)),
filter_empty_gt=False,
# we use box_type_3d='LiDAR' in kitti and nuscenes dataset
# and box_type_3d='Depth' in sunrgbd and scannet dataset.
box_type_3d='Depth')),
val=dict(
type=dataset_type,
data_root=data_root,
ann_file=data_root + 'sunrgbd_infos_val.pkl',
pipeline=test_pipeline,
classes=class_names,
test_mode=True),
test_mode=True,
box_type_3d='Depth'),
test=dict(
type=dataset_type,
data_root=data_root,
ann_file=data_root + 'sunrgbd_infos_val.pkl',
pipeline=test_pipeline,
classes=class_names,
test_mode=True))
test_mode=True,
box_type_3d='Depth'))
106 changes: 106 additions & 0 deletions demo/inference_demo.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"pycharm": {
"is_executing": false
}
},
"outputs": [],
"source": [
"from mmdet3d.apis import init_detector, inference_detector, show_result_meshlab"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"pycharm": {
"is_executing": false
}
},
"outputs": [],
"source": [
"config_file = '../configs/second/hv_second_secfpn_6x8_80e_kitti-3d-car.py'\n",
"# download the checkpoint from model zoo and put it in `checkpoints/`\n",
"checkpoint_file = '../work_dirs/second/epoch_40.pth'"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"pycharm": {
"is_executing": false
}
},
"outputs": [],
"source": [
"# build the model from a config file and a checkpoint file\n",
"model = init_detector(config_file, checkpoint_file, device='cuda:0')"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"pycharm": {
"is_executing": false
}
},
"outputs": [],
"source": [
"# test a single sample\n",
"pcd = 'kitti_000008.bin'\n",
"result, data = inference_detector(model, pcd)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"pycharm": {
"is_executing": false
}
},
"outputs": [],
"source": [
"# show the results\n",
"out_dir = './'\n",
"show_result_meshlab(data, result, out_dir)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.7"
},
"pycharm": {
"stem_cell": {
"cell_type": "raw",
"source": [],
"metadata": {
"collapsed": false
}
}
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Binary file added demo/kitti_000008.bin
Binary file not shown.
28 changes: 28 additions & 0 deletions demo/pcd_demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from argparse import ArgumentParser

from mmdet3d.apis import inference_detector, init_detector, show_result_meshlab


def main():
parser = ArgumentParser()
parser.add_argument('pcd', help='Point cloud file')
parser.add_argument('config', help='Config file')
parser.add_argument('checkpoint', help='Checkpoint file')
parser.add_argument(
'--device', default='cuda:0', help='Device used for inference')
parser.add_argument(
'--score-thr', type=float, default=0.6, help='bbox score threshold')
parser.add_argument(
'--out-dir', type=str, default='demo', help='dir to save results')
args = parser.parse_args()

# build the model from a config file and a checkpoint file
model = init_detector(args.config, args.checkpoint, device=args.device)
# test a single image
result, data = inference_detector(model, args.pcd)
# show the results
show_result_meshlab(data, result, args.out_dir)


if __name__ == '__main__':
main()
Binary file added demo/sunrgbd_000017.bin
Binary file not shown.
27 changes: 6 additions & 21 deletions docs/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Optional arguments:
- `RESULT_FILE`: Filename of the output results in pickle format. If not specified, the results will not be saved to a file.
- `EVAL_METRICS`: Items to be evaluated on the results. Allowed values depend on the dataset, e.g., `proposal_fast`, `proposal`, `bbox`, `segm` are available for COCO, `mAP`, `recall` for PASCAL VOC. Cityscapes could be evaluated by `cityscapes` as well as all COCO metrics.
- `--show`: If specified, detection results will be plotted in the silient mode. It is only applicable to single GPU testing and used for debugging and visualization. This should be used with `--show-dir`.
- `--show-dir`: If specified, detection results will be plotted on the `***_points.obj` and `***_pred.ply` files in the specified directory. It is only applicable to single GPU testing and used for debugging and visualization. You do NOT need a GUI available in your environment for using this option.
- `--show-dir`: If specified, detection results will be plotted on the `***_points.obj` and `***_pred.ply` files in the specified directory. It is only applicable to single GPU testing and used for debugging and visualization. You do NOT need a GUI available in your environment for using this option.


Examples:
Expand Down Expand Up @@ -176,34 +176,19 @@ You can use 3D visualization software such as the [MeshLab](http://www.meshlab.n

**Notice**: The visualization API is a little unstable since we plan to refactor these parts together with MMDetection in the future.

### Image demo
### Point cloud demo

We provide a demo script to test a single image.
We provide a demo script to test a single sample.

```shell
python demo/image_demo.py ${IMAGE_FILE} ${CONFIG_FILE} ${CHECKPOINT_FILE} [--device ${GPU_ID}] [--score-thr ${SCORE_THR}]
python demo/pcd_demo.py ${PCD_FILE} ${CONFIG_FILE} ${CHECKPOINT_FILE} [--device ${GPU_ID}] [--score-thr ${SCORE_THR}] [--out-dir ${OUT_DIR}]
```

Examples:

```shell
python demo/image_demo.py demo/demo.jpg configs/faster_rcnn_r50_fpn_1x_coco.py \
checkpoints/faster_rcnn_r50_fpn_1x_20181010-3d1b3351.pth --device cpu
```

### Webcam demo

We provide a webcam demo to illustrate the results.

```shell
python demo/webcam_demo.py ${CONFIG_FILE} ${CHECKPOINT_FILE} [--device ${GPU_ID}] [--camera-id ${CAMERA-ID}] [--score-thr ${SCORE_THR}]
```

Examples:

```shell
python demo/webcam_demo.py configs/faster_rcnn_r50_fpn_1x_coco.py \
checkpoints/faster_rcnn_r50_fpn_1x_20181010-3d1b3351.pth
python demo/pcd_demo.py demo/kitti_000008.bin configs/second/hv_second_secfpn_6x8_80e_kitti-3d-car.py \
checkpoints/epoch_40.pth
```


Expand Down
6 changes: 5 additions & 1 deletion mmdet3d/apis/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from .inference import inference_detector, init_detector, show_result_meshlab
from .test import single_gpu_test

__all__ = ['single_gpu_test']
__all__ = [
'inference_detector', 'init_detector', 'single_gpu_test',
'show_result_meshlab'
]
Loading

0 comments on commit aee606f

Please sign in to comment.