Skip to content
This repository was archived by the owner on Oct 13, 2021. It is now read-only.

Commit 66a03fa

Browse files
committed
(1) save all evaluation checkpoints and (2) publish more metrics to tensorboard
1 parent 456d2b5 commit 66a03fa

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

second/pytorch/train.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ def train(config_path,
9898

9999
model_dir = pathlib.Path(model_dir)
100100
model_dir.mkdir(parents=True, exist_ok=True)
101+
eval_checkpoint_dir = model_dir / 'eval_checkpoints'
102+
eval_checkpoint_dir.mkdir(parents=True, exist_ok=True)
101103
if result_path is None:
102104
result_path = model_dir / 'results'
103105
config_file_bkp = "pipeline.config"
@@ -335,6 +337,10 @@ def _worker_init_fn(worker_id):
335337
total_step_elapsed += steps
336338
torchplus.train.save_models(model_dir, [net, optimizer],
337339
net.get_global_step())
340+
341+
# Ensure that all evaluation points are saved forever
342+
torchplus.train.save_models(eval_checkpoint_dir, [net, optimizer], net.get_global_step(), max_to_keep=100)
343+
338344
net.eval()
339345
result_path_step = result_path / f"step_{net.get_global_step()}"
340346
result_path_step.mkdir(parents=True, exist_ok=True)
@@ -379,10 +385,20 @@ def _worker_init_fn(worker_id):
379385
]
380386
if not pickle_result:
381387
dt_annos = kitti.get_label_annos(result_path_step)
382-
result = get_official_eval_result(gt_annos, dt_annos, class_names)
388+
result, mAPbbox, mAPbev, mAP3d, mAPaos = get_official_eval_result(gt_annos, dt_annos, class_names,
389+
return_data=True)
383390
print(result, file=logf)
384391
print(result)
385392
writer.add_text('eval_result', result, global_step)
393+
394+
for i, class_name in enumerate(class_names):
395+
writer.add_scalar('bev_ap:{}'.format(class_name), mAPbev[i, 1, 0], global_step)
396+
writer.add_scalar('3d_ap:{}'.format(class_name), mAP3d[i, 1, 0], global_step)
397+
writer.add_scalar('aos_ap:{}'.format(class_name), mAPaos[i, 1, 0], global_step)
398+
writer.add_scalar('bev_map', np.mean(mAPbev[:, 1, 0]), global_step)
399+
writer.add_scalar('3d_map', np.mean(mAP3d[:, 1, 0]), global_step)
400+
writer.add_scalar('aos_map', np.mean(mAPaos[:, 1, 0]), global_step)
401+
386402
result = get_coco_eval_result(gt_annos, dt_annos, class_names)
387403
print(result, file=logf)
388404
print(result)

second/utils/eval.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -788,12 +788,12 @@ def get_official_eval_result_v1(gt_annos, dt_annos, current_class):
788788
return result
789789

790790

791-
def get_official_eval_result(gt_annos, dt_annos, current_classes, difficultys=[0, 1, 2]):
792-
overlap_0_7 = np.array([[0.7, 0.5, 0.5, 0.7,
793-
0.5, 0.7, 0.7, 0.7], [0.7, 0.5, 0.5, 0.7, 0.5, 0.7, 0.7, 0.7],
791+
def get_official_eval_result(gt_annos, dt_annos, current_classes, difficultys=[0, 1, 2], return_data=False):
792+
overlap_0_7 = np.array([[0.7, 0.5, 0.5, 0.7, 0.5, 0.7, 0.7, 0.7],
793+
[0.7, 0.5, 0.5, 0.7, 0.5, 0.7, 0.7, 0.7],
794794
[0.7, 0.5, 0.5, 0.7, 0.5, 0.7, 0.7, 0.7]])
795-
overlap_0_5 = np.array([[0.7, 0.5, 0.5, 0.7,
796-
0.5, 0.5, 0.5, 0.5], [0.5, 0.25, 0.25, 0.5, 0.25, 0.5, 0.5, 0.5],
795+
overlap_0_5 = np.array([[0.7, 0.5, 0.5, 0.7, 0.5, 0.5, 0.5, 0.5],
796+
[0.5, 0.25, 0.25, 0.5, 0.25, 0.5, 0.5, 0.5],
797797
[0.5, 0.25, 0.25, 0.5, 0.25, 0.5, 0.5, 0.5]])
798798
min_overlaps = np.stack([overlap_0_7, overlap_0_5], axis=0) # [2, 3, 5]
799799
class_to_name = {
@@ -847,8 +847,11 @@ def get_official_eval_result(gt_annos, dt_annos, current_classes, difficultys=[0
847847
result += print_str((f"aos AP:{mAPaos[j, 0, i]:.2f}, "
848848
f"{mAPaos[j, 1, i]:.2f}, "
849849
f"{mAPaos[j, 2, i]:.2f}"))
850+
if return_data:
851+
return result, mAPbbox, mAPbev, mAP3d, mAPaos
852+
else:
853+
return result
850854

851-
return result
852855

853856
def get_coco_eval_result(gt_annos, dt_annos, current_classes):
854857
class_to_name = {

0 commit comments

Comments
 (0)