Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Update gather model script #1917

Open
wants to merge 3 commits into
base: dev-1.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 36 additions & 18 deletions .dev_scripts/gather_models.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
# Copyright (c) OpenMMLab. All rights reserved.
"""Script to gather benchmarked models and prepare them for upload.

1. Organize the model save directory

Assumes that the directory format of the model after training is:
work_dir/config_folder/config_file/, so it is necessary to organize
the directory into the following form in advance during training.

For example, the command during training should be:

./tools/slurm_train.sh mm_det centerpoint
configs/centerpoint/centerpoint_0075voxel_second_secfpn_4x8_cyclic_20e_nus.py
work_dir/centerpoint/centerpoint_0075voxel_second_secfpn_4x8_cyclic_20e_nus.py

2. Gather model

Use ./dev_scripts/gather_model.py to batch process the model:

Usage:
python gather_models.py ${root_path} ${out_dir}
python .dev_scripts/gather_models.py ${SAVED_DIR} ${OUT_DIR}

- SAVED_DIR: the model ckpt, log path after training, default is . /work_dir
- OUT_DIR: The path where the output information is saved after processing by
the script, the default path is . /gather

Example:
python gather_models.py \
work_dirs/pgd_r101_caffe_fpn_gn-head_3x4_4x_kitti-mono3d \
work_dirs/pgd_r101_caffe_fpn_gn-head_3x4_4x_kitti-mono3d

Note that before running the above command, rename the directory with the
config name if you did not use the default directory name, create
a corresponding directory 'pgd' under the above path and put the used config
into it.
python .dev_scripts/gather_models.py ./work_dir/ ./gather
"""

import argparse
Expand Down Expand Up @@ -47,8 +60,10 @@
RESULTS_LUT = {
'coco': ['bbox_mAP', 'segm_mAP'],
'nus': ['pts_bbox_NuScenes/NDS', 'NDS'],
'kitti-3d-3class': ['KITTI/Overall_3D_moderate', 'Overall_3D_moderate'],
'kitti-3d-car': ['KITTI/Car_3D_moderate_strict', 'Car_3D_moderate_strict'],
'kitti-3d-3class':
['KITTI/Overall_3D_AP11_moderate', 'Overall_3D_AP11_moderate'],
'kitti-3d-car':
['KITTI/Car_3D_AP11_moderate_strict', 'Car_3D_AP11_moderate_strict'],
'lyft': ['score'],
'scannet_seg': ['miou'],
's3dis_seg': ['miou'],
Expand Down Expand Up @@ -158,13 +173,15 @@ def main():
# and parse the best performance
model_infos = []
for used_config in used_configs:
# get logs
log_json_path = glob.glob(osp.join(models_root, '*.log.json'))[0]
log_txt_path = glob.glob(osp.join(models_root, '*.log'))[0]
exp_dir = osp.join(models_root, used_config)
# get the latest logs
log_json_path = list(
sorted(glob.glob(osp.join(exp_dir, '*.log.json'))))[-1]
log_txt_path = list(sorted(glob.glob(osp.join(exp_dir, '*.log'))))[-1]
model_performance = get_best_results(log_json_path)
final_epoch = model_performance['epoch']
final_model = 'epoch_{}.pth'.format(final_epoch)
model_path = osp.join(models_root, final_model)
model_path = osp.join(exp_dir, final_model)

# skip if the model is still training
if not osp.exists(model_path):
Expand Down Expand Up @@ -193,7 +210,7 @@ def main():
model_name = model['config'].split('/')[-1].rstrip(
'.py') + '_' + model['model_time']
publish_model_path = osp.join(model_publish_dir, model_name)
trained_model_path = osp.join(models_root,
trained_model_path = osp.join(models_root, model['config'],
'epoch_{}.pth'.format(model['epochs']))

# convert model
Expand All @@ -202,10 +219,11 @@ def main():

# copy log
shutil.copy(
osp.join(models_root, model['log_json_path']),
osp.join(models_root, model['config'], model['log_json_path']),
osp.join(model_publish_dir, f'{model_name}.log.json'))
shutil.copy(
osp.join(models_root, model['log_json_path'].rstrip('.json')),
osp.join(models_root, model['config'],
model['log_json_path'].rstrip('.json')),
osp.join(model_publish_dir, f'{model_name}.log'))

# copy config to guarantee reproducibility
Expand Down