Skip to content

Commit

Permalink
Give nuScenes-lidarseg challenge participants an option to zip up the…
Browse files Browse the repository at this point in the history
…ir results folder (nutonomy#509)

* Add option to zip results_folder in validate_submission.py

* Check that folder to zip to exists

* Docstring for zip_out param
  • Loading branch information
whyekit-motional authored Dec 2, 2020
1 parent acdbf5d commit 25096fd
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions python-sdk/nuscenes/eval/lidarseg/validate_submission.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import argparse
import json
import os
import shutil

import numpy as np
from tqdm import tqdm
Expand All @@ -10,7 +11,11 @@
from nuscenes.utils.data_classes import LidarPointCloud


def validate_submission(nusc: NuScenes, results_folder: str, eval_set: str, verbose: bool = False) -> None:
def validate_submission(nusc: NuScenes,
results_folder: str,
eval_set: str,
verbose: bool = False,
zip_out: str = None) -> None:
"""
Checks if a results folder is valid. The following checks are performed:
- Check that the submission folder is according to that described in
Expand All @@ -27,6 +32,7 @@ def validate_submission(nusc: NuScenes, results_folder: str, eval_set: str, verb
:param results_folder: Path to the folder.
:param eval_set: The dataset split to evaluate on, e.g. train, val or test.
:param verbose: Whether to print messages during the evaluation.
:param zip_out: Path to zip results_folder to, if provided.
"""
mapper = LidarsegClassMapper(nusc)
num_classes = len(mapper.coarse_name_2_coarse_idx_mapping)
Expand Down Expand Up @@ -111,6 +117,16 @@ def validate_submission(nusc: NuScenes, results_folder: str, eval_set: str, verb
if verbose:
print('Results folder {} successfully validated!'.format(results_folder))

# Zip up results folder if desired.
if zip_out:
assert os.path.exists(zip_out), \
'Error: The folder {} to zip the results to does not exist.'.format(zip_out)

results_zip = os.path.join(zip_out, os.path.basename(os.path.normpath(results_folder)))
results_zip_name = shutil.make_archive(results_zip, 'zip', results_folder)
if verbose:
print('Results folder {} zipped to {}'.format(results_folder, results_zip_name))


if __name__ == '__main__':
# Settings.
Expand All @@ -125,13 +141,20 @@ def validate_submission(nusc: NuScenes, results_folder: str, eval_set: str, verb
help='Which version of the nuScenes dataset to evaluate on, e.g. v1.0-trainval.')
parser.add_argument('--verbose', type=bool, default=False,
help='Whether to print to stdout.')
parser.add_argument('--zip_out', type=str, default=None,
help='Whether to print to stdout.')
args = parser.parse_args()

result_path_ = args.result_path
eval_set_ = args.eval_set
dataroot_ = args.dataroot
version_ = args.version
verbose_ = args.verbose
zip_out_ = args.zip_out

nusc_ = NuScenes(version=version_, dataroot=dataroot_, verbose=verbose_)
validate_submission(nusc=nusc_, results_folder=result_path_, eval_set=eval_set_, verbose=verbose_)
validate_submission(nusc=nusc_,
results_folder=result_path_,
eval_set=eval_set_,
verbose=verbose_,
zip_out=zip_out_)

0 comments on commit 25096fd

Please sign in to comment.