preprocess.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. import os
  15. import time
  16. from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser
  17. from data_preprocessing.preprocessor import Preprocessor
  18. from utils.utils import get_task_code
  19. parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter)
  20. parser.add_argument("--data", type=str, default="/data", help="Path to data directory")
  21. parser.add_argument("--results", type=str, default="/data", help="Path for saving results directory")
  22. parser.add_argument(
  23. "--exec_mode",
  24. type=str,
  25. default="training",
  26. choices=["training", "val", "test"],
  27. help="Mode for data preprocessing",
  28. )
  29. parser.add_argument("--dilation", action="store_true", help="Perform morphological label dilation")
  30. parser.add_argument("--task", type=str, help="Number of task to be run. MSD uses numbers 01-10")
  31. parser.add_argument("--dim", type=int, default=3, choices=[2, 3], help="Data dimension to prepare")
  32. parser.add_argument("--n_jobs", type=int, default=-1, help="Number of parallel jobs for data preprocessing")
  33. if __name__ == "__main__":
  34. args = parser.parse_args()
  35. start = time.time()
  36. Preprocessor(args).run()
  37. task_code = get_task_code(args)
  38. path = os.path.join(args.data, task_code)
  39. if args.exec_mode == "test":
  40. path = os.path.join(path, "test")
  41. end = time.time()
  42. print(f"Preprocessing time: {(end - start):.2f}")