train.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536
  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. from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser
  16. from os.path import dirname
  17. from subprocess import call
  18. parser = ArgumentParser(ArgumentDefaultsHelpFormatter)
  19. parser.add_argument("--gpus", type=int, required=True, help="Number of GPUs")
  20. parser.add_argument("--fold", type=int, required=True, choices=[0, 1, 2, 3, 4], help="Fold number")
  21. parser.add_argument("--dim", type=int, required=True, choices=[2, 3], help="Dimension of UNet")
  22. parser.add_argument("--amp", action="store_true", help="Enable automatic mixed precision")
  23. if __name__ == "__main__":
  24. args = parser.parse_args()
  25. path_to_main = os.path.join(dirname(dirname(os.path.realpath(__file__))), "main.py")
  26. cmd = f"python {path_to_main} --exec_mode train --task 01 --deep_supervision --save_ckpt "
  27. cmd += f"--dim {args.dim} "
  28. cmd += f"--batch_size {2 if args.dim == 3 else 16} "
  29. cmd += f"--val_batch_size {4 if args.dim == 3 else 64} "
  30. cmd += f"--fold {args.fold} "
  31. cmd += f"--gpus {args.gpus} "
  32. cmd += "--amp " if args.amp else ""
  33. call(cmd, shell=True)