Skip to content

Commit 42b02af

Browse files
committed
1. add fp16 and multi-gpu support
2. fix some bugs of nuscenes dataset.
1 parent e26732b commit 42b02af

40 files changed

+1057
-468
lines changed

README.md

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ONLY support python 3.6+, pytorch 1.0.0+. Tested in Ubuntu 16.04/18.04/Windows 1
55

66
## News
77

8-
2019-4-1: SECOND V1.6.0alpha released: New Data API, [NuScenes](https://www.nuscenes.org) support, [PointPillars](https://github.com/nutonomy/second.pytorch) support.
8+
2019-4-1: SECOND V1.6.0alpha released: New Data API, [NuScenes](https://www.nuscenes.org) support, [PointPillars](https://github.com/nutonomy/second.pytorch) support, fp16 and multi-gpu support.
99

1010
2019-3-21: SECOND V1.5.1 (minor improvement and bug fix) released!
1111

@@ -73,9 +73,11 @@ pip install numba scikit-image scipy pillow
7373

7474
Follow instructions in [spconv](https://github.com/traveller59/spconv) to install spconv.
7575

76+
If you want to train with fp16 mixed precision (train faster in RTX series, Titan V/RTX and Tesla V100, but I only have 1080Ti), you need to install [apex](https://github.com/NVIDIA/apex).
77+
7678
If you want to use NuScenes dataset, you need to install [nuscenes-devkit](https://github.com/nutonomy/nuscenes-devkit), I recommend to copy nuscenes in python-sdk to second/.. folder (equalivent to add it to PYTHONPATH) and manually install its dependencies, use pip to install devkit will install many fixed-version library.
7779

78-
### 3. Setup cuda for numba
80+
### 3. Setup cuda for numba (will be removed in 1.6.0 release)
7981

8082
you need to add following environment variable for numba.cuda, you can add them to ~/.bashrc:
8183

@@ -128,12 +130,11 @@ Download NuScenes dataset:
128130
├── maps <-- unused
129131
└── v1.0-test <-- metadata
130132
```
131-
Since the dataset is really large, you can download parts of the dataset.
132133

133134
Then run
134135
```bash
135-
python create_data.py nuscenes_data_prep --data_path=NUSCENES_TRAINVAL_DATASET_ROOT --version="v1.0-trainval" --max_sweeps=9
136-
python create_data.py nuscenes_data_prep --data_path=NUSCENES_TEST_DATASET_ROOT --version="v1.0-test" --max_sweeps=9
136+
python create_data.py nuscenes_data_prep --data_path=NUSCENES_TRAINVAL_DATASET_ROOT --version="v1.0-trainval" --max_sweeps=10
137+
python create_data.py nuscenes_data_prep --data_path=NUSCENES_TEST_DATASET_ROOT --version="v1.0-test" --max_sweeps=10
137138
```
138139

139140
* Modify config file
@@ -168,10 +169,24 @@ eval_input_reader: {
168169

169170
I recommend to use script.py to train and eval. see script.py for more details.
170171

172+
#### train with single GPU
173+
171174
```bash
172175
python ./pytorch/train.py train --config_path=./configs/car.fhd.config --model_dir=/path/to/model_dir
173176
```
174177

178+
#### train with multiple GPU (need test, I only have one GPU)
179+
180+
Assume you have 4 GPUs and want to train with 3 GPUs:
181+
182+
```bash
183+
CUDA_VISIBLE_DEVICES=0,1,3 python ./pytorch/train.py train --config_path=./configs/car.fhd.config --model_dir=/path/to/model_dir --multi_gpu=True
184+
```
185+
186+
#### train with fp16 (mixed precision)
187+
188+
Modify config file, set enable_mixed_precision to true.
189+
175190
* Make sure "/path/to/model_dir" doesn't exist if you want to train new model. A new directory will be created if the model_dir doesn't exist, otherwise will read checkpoints in it.
176191

177192
* training process use batchsize=6 as default for 1080Ti, you need to reduce batchsize if your GPU has less memory.

RELEASE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
4. Full Tensorboard support.
1414

15+
5. FP16 and multi-gpu (need test, I only have one gpu) support.
16+
1517
## Minor Improvements and Bug fixes
1618

1719
1. Move all data-specific functions to their corresponding dataset file.

second/builder/dataset_builder.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ def build(input_reader_config,
3535
model_config,
3636
training,
3737
voxel_generator,
38-
target_assigner):
38+
target_assigner,
39+
multi_gpu=False):
3940
"""Builds a tensor dictionary based on the InputReader config.
4041
4142
Args:
@@ -69,6 +70,7 @@ def build(input_reader_config,
6970
assert all([n != '' for n in target_assigner.classes]), "you must specify class_name in anchor_generators."
7071
dataset_cls = get_dataset_class(dataset_cfg.dataset_class_name)
7172
assert dataset_cls.NumPointFeatures >= 3, "you must set this to correct value"
73+
assert dataset_cls.NumPointFeatures == num_point_features, "currently you need keep them same"
7274
prep_func = partial(
7375
prep_pointcloud,
7476
root_path=dataset_cfg.kitti_root_path,
@@ -95,7 +97,8 @@ def build(input_reader_config,
9597
remove_points_after_sample=prep_cfg.remove_points_after_sample,
9698
remove_environment=prep_cfg.remove_environment,
9799
use_group_id=prep_cfg.use_group_id,
98-
out_size_factor=out_size_factor)
100+
out_size_factor=out_size_factor,
101+
multi_gpu=multi_gpu)
99102

100103
ret = target_assigner.generate_anchors(feature_map_size)
101104
class_names = target_assigner.classes

second/configs/all.fhd.config

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ model: {
77
max_number_of_points_per_voxel : 5
88
}
99
voxel_feature_extractor: {
10-
module_class_name: "SimpleVoxel"
10+
module_class_name: "SimpleVoxelRadius"
1111
num_filters: [16]
1212
with_distance: false
1313
num_input_features: 4
@@ -233,8 +233,8 @@ train_config: {
233233
steps_per_eval: 6190 # 1238 * 5
234234
save_checkpoints_secs : 1800 # half hour
235235
save_summary_steps : 10
236-
enable_mixed_precision: false # for fp16 training, but sparseconvnet don't support fp16
237-
loss_scale_factor : 512.0
236+
enable_mixed_precision: false
237+
loss_scale_factor: 8.0
238238
clear_metrics_every_epoch: true
239239
}
240240

second/configs/car.fhd.config

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ model: {
88
}
99

1010
voxel_feature_extractor: {
11-
module_class_name: "VoxelFeatureExtractorV3"
11+
module_class_name: "SimpleVoxel"
1212
num_filters: [16]
1313
with_distance: false
1414
num_input_features: 4
@@ -186,8 +186,8 @@ train_config: {
186186

187187
save_checkpoints_secs : 1800 # half hour
188188
save_summary_steps : 10
189-
enable_mixed_precision: false # for fp16 training, but sparseconvnet don't support fp16
190-
loss_scale_factor : 512.0
189+
enable_mixed_precision: false
190+
loss_scale_factor : 8.0
191191
clear_metrics_every_epoch: true
192192
}
193193

second/configs/car.fhd.onestage.config

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ model: {
88
}
99

1010
voxel_feature_extractor: {
11-
module_class_name: "VoxelFeatureExtractorV3"
11+
module_class_name: "SimpleVoxel"
1212
num_filters: [16]
1313
with_distance: false
1414
num_input_features: 4
@@ -170,8 +170,8 @@ train_config: {
170170
steps_per_eval: 3095 # 619 * 5
171171
save_checkpoints_secs : 1800 # half hour
172172
save_summary_steps : 10
173-
enable_mixed_precision: false # for fp16 training, don't use this.
174-
loss_scale_factor : 512.0
173+
enable_mixed_precision: false
174+
loss_scale_factor : 8.0
175175
clear_metrics_every_epoch: true
176176
}
177177

second/configs/car.lite.config

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ model: {
99
}
1010

1111
voxel_feature_extractor: {
12-
module_class_name: "SimpleVoxel"
12+
module_class_name: "SimpleVoxelRadius"
1313
num_filters: [16]
1414
with_distance: false
1515
num_input_features: 4
@@ -176,8 +176,8 @@ train_config: {
176176
steps_per_eval: 1550 # 310 * 5
177177
save_checkpoints_secs : 1800 # half hour
178178
save_summary_steps : 10
179-
enable_mixed_precision: false # for fp16 training, but sparseconvnet don't support fp16
180-
loss_scale_factor : 512.0
179+
enable_mixed_precision: false
180+
loss_scale_factor: 8.0
181181
clear_metrics_every_epoch: true
182182
}
183183

second/configs/car.lite.nu.config

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,30 @@ model: {
22
second: {
33
voxel_generator {
44
point_cloud_range : [-50, -50.0, -4, 50, 50, 2]
5-
voxel_size : [0.1, 0.1, 0.3]
5+
voxel_size : [0.05, 0.05, 0.15]
66
max_number_of_points_per_voxel : 1
77
}
88

99
voxel_feature_extractor: {
10-
module_class_name: "SimpleVoxel"
10+
module_class_name: "SimpleVoxelRadius"
1111
num_filters: [16]
1212
with_distance: false
1313
num_input_features: 4
1414
}
1515
middle_feature_extractor: {
16-
module_class_name: "SpMiddleHDLite"
16+
module_class_name: "SpMiddleFHDLite"
1717
# num_filters_down1: [] # protobuf don't support empty list.
1818
# num_filters_down2: []
19-
downsample_factor: 4
20-
num_input_features: 3 # SimpleVoxel output 3 - 1 features
19+
downsample_factor: 8
20+
num_input_features: 3
2121
}
2222
rpn: {
2323
module_class_name: "RPNV2"
2424
layer_nums: [5]
2525
layer_strides: [1]
2626
num_filters: [128]
27-
# upsample_strides: [1]
28-
# num_upsample_filters: [128]
27+
upsample_strides: [1]
28+
num_upsample_filters: [128]
2929
use_groupnorm: false
3030
num_groups: 32
3131
num_input_features: 128
@@ -67,8 +67,8 @@ model: {
6767
use_multi_class_nms: false
6868
nms_pre_max_size: 1000
6969
nms_post_max_size: 100
70-
nms_score_threshold: 0.3 # 0.4 in submit, but 0.3 can get better hard performance
71-
nms_iou_threshold: 0.01
70+
nms_score_threshold: 0.05 # 0.4 in submit, but 0.3 can get better hard performance
71+
nms_iou_threshold: 0.5
7272

7373
box_coder: {
7474
ground_box3d_coder: {
@@ -79,12 +79,12 @@ model: {
7979
target_assigner: {
8080
anchor_generators: {
8181
anchor_generator_range: {
82-
sizes: [1.968534, 4.6260232, 1.7432361] # wlh
83-
anchor_ranges: [-50, -50.0, -0.916, 50, 50, -0.916]
82+
sizes: [1.95017717, 4.60718145, 1.72270761] # wlh
83+
anchor_ranges: [-50, -50.0, -0.93897414, 50, 50, -0.93897414]
8484
rotations: [0, 1.57] # DON'T modify this unless you are very familiar with my code.
8585
matched_threshold : 0.6
8686
unmatched_threshold : 0.45
87-
class_name: "vehicle.car"
87+
class_name: "car"
8888
}
8989
}
9090
sample_positive_fraction : -1
@@ -102,17 +102,23 @@ train_input_reader: {
102102
dataset_class_name: "NuScenesDataset"
103103
kitti_info_path: "/media/yy/960evo/datasets/nuscene/v1.0-trainval/infos_train.pkl"
104104
kitti_root_path: "/media/yy/960evo/datasets/nuscene/v1.0-trainval"
105+
# kitti_info_path: "/media/yy/960evo/datasets/nuscene/v1.0-mini/infos_train.pkl"
106+
# kitti_root_path: "/media/yy/960evo/datasets/nuscene/v1.0-mini"
107+
105108
}
106109

107-
batch_size: 8
110+
batch_size: 6
108111
preprocess: {
109-
max_number_of_voxels: 20000
110-
shuffle_points: true
112+
max_number_of_voxels: 63000
113+
shuffle_points: false
111114
num_workers: 3
112-
groundtruth_localization_noise_std: [1.0, 1.0, 0.5]
115+
groundtruth_localization_noise_std: [0, 0, 0]
116+
groundtruth_rotation_uniform_noise: [0, 0]
117+
118+
# groundtruth_localization_noise_std: [0.25, 0.25, 0.25]
113119
# groundtruth_rotation_uniform_noise: [-0.3141592654, 0.3141592654]
114-
groundtruth_rotation_uniform_noise: [-0.78539816, 0.78539816]
115-
global_rotation_uniform_noise: [-0.78539816, 0.78539816]
120+
# groundtruth_rotation_uniform_noise: [-0.78539816, 0.78539816]
121+
global_rotation_uniform_noise: [-1.57, 1.57]
116122
global_scaling_uniform_noise: [0.95, 1.05]
117123
global_random_rotation_range_per_object: [0, 0] # pi/4 ~ 3pi/4
118124
global_translate_noise_std: [0.2, 0.2, 0.2]
@@ -123,23 +129,9 @@ train_input_reader: {
123129
remove_unknown_examples: false
124130
remove_environment: false
125131
database_sampler {
126-
database_info_path: "/media/yy/960evo/datasets/nuscene/v1.0-trainval/kitti_dbinfos_train.pkl"
127-
sample_groups {
128-
name_to_max_num {
129-
key: "vehicle.car"
130-
value: 5
131-
}
132-
}
133-
database_prep_steps {
134-
filter_by_min_num_points {
135-
min_num_point_pairs {
136-
key: "vehicle.car"
137-
value: 5
138-
}
139-
}
140-
}
141-
global_random_rotation_range_per_object: [0, 0]
142-
rate: 1.0
132+
# leave this empty to disable database_sampler, nuscenes don't need sample
133+
# because 1. the number of ground-truth is enough. 2. sweeps don't support
134+
# sample.
143135
}
144136
}
145137
}
@@ -160,24 +152,24 @@ train_config: {
160152
fixed_weight_decay: true
161153
use_moving_average: false
162154
}
163-
steps: 70240 # 3512 * 20 (28096 / 8)
164-
steps_per_eval: 7024 # 310 * 5
155+
steps: 234450 # 4689 * 50 (28130 // 6 + 1)
156+
steps_per_eval: 9378 # 4689 * 2
165157
save_checkpoints_secs : 1800 # half hour
166158
save_summary_steps : 10
167-
enable_mixed_precision: false # for fp16 training, but sparseconvnet don't support fp16
168-
loss_scale_factor : 512.0
159+
enable_mixed_precision: false
160+
loss_scale_factor: 8.0
169161
clear_metrics_every_epoch: true
170162
}
171163

172164
eval_input_reader: {
173-
batch_size: 8
165+
batch_size: 6
174166
dataset: {
175167
dataset_class_name: "NuScenesDataset"
176168
kitti_info_path: "/media/yy/960evo/datasets/nuscene/v1.0-trainval/infos_val.pkl"
177169
kitti_root_path: "/media/yy/960evo/datasets/nuscene/v1.0-trainval"
178170
}
179171
preprocess: {
180-
max_number_of_voxels: 50000
172+
max_number_of_voxels: 80000
181173
shuffle_points: false
182174
num_workers: 3
183175
anchor_area_threshold: -1

second/configs/people.fhd.config

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ model: {
88
}
99

1010
voxel_feature_extractor: {
11-
module_class_name: "VoxelFeatureExtractorV3"
11+
module_class_name: "SimpleVoxel"
1212
num_filters: [16]
1313
with_distance: false
1414
num_input_features: 4
@@ -197,8 +197,8 @@ train_config: {
197197
steps_per_eval: 3095 # 619 * 5
198198
save_checkpoints_secs : 1800 # half hour
199199
save_summary_steps : 10
200-
enable_mixed_precision: false # for fp16 training, but sparseconvnet don't support fp16
201-
loss_scale_factor : 512.0
200+
enable_mixed_precision: false
201+
loss_scale_factor: 8.0
202202
clear_metrics_every_epoch: true
203203
}
204204

second/configs/pointpillars/car/xyres_16.config

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ model: {
9999
train_input_reader: {
100100
dataset: {
101101
dataset_class_name: "KittiDataset"
102-
kitti_info_path: "/media/yy/960evo/datasets/kitti/kitti_infos_train.pkl"
103-
kitti_root_path: "/media/yy/960evo/datasets/kitti"
102+
kitti_info_path: "/media/yy/My Passport/datasets/kitti/kitti_infos_train.pkl"
103+
kitti_root_path: "/media/yy/My Passport/datasets/kitti"
104104
}
105105

106106
batch_size: 2
@@ -121,7 +121,7 @@ train_input_reader: {
121121
remove_unknown_examples: false
122122
remove_environment: false
123123
database_sampler {
124-
database_info_path: "/media/yy/960evo/datasets/kitti/kitti_dbinfos_train.pkl"
124+
database_info_path: "/media/yy/My Passport/datasets/kitti/kitti_dbinfos_train.pkl"
125125
sample_groups {
126126
name_to_max_num {
127127
key: "Car"
@@ -164,21 +164,21 @@ train_config: {
164164
use_moving_average: false
165165

166166
}
167-
steps: 92800 # 1856 steps per epoch * 50 epochs
168-
steps_per_eval: 9280 # 1856 steps per epoch * 5 epochs
167+
steps: 37120 # 92800 # 1856 steps per epoch * 50 epochs
168+
steps_per_eval: 3712 # 9280 # 1856 steps per epoch * 5 epochs
169169
save_checkpoints_secs : 1800 # half hour
170170
save_summary_steps : 10
171171
enable_mixed_precision: false
172-
loss_scale_factor : 512.0
172+
loss_scale_factor: 8.0
173173
clear_metrics_every_epoch: true
174174
}
175175

176176
eval_input_reader: {
177177
dataset: {
178178
dataset_class_name: "KittiDataset"
179-
kitti_info_path: "/media/yy/960evo/datasets/kitti/kitti_infos_val.pkl"
180-
# kitti_info_path: "/media/yy/960evo/datasets/kitti/kitti_infos_test.pkl"
181-
kitti_root_path: "/media/yy/960evo/datasets/kitti"
179+
kitti_info_path: "/media/yy/My Passport/datasets/kitti/kitti_infos_val.pkl"
180+
# kitti_info_path: "/media/yy/My Passport/datasets/kitti/kitti_infos_test.pkl"
181+
kitti_root_path: "/media/yy/My Passport/datasets/kitti"
182182
}
183183
batch_size: 2
184184

0 commit comments

Comments
 (0)