main.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. """Entry point of the application.
  15. This file serves as entry point to the run of UNet for segmentation of neuronal processes.
  16. Example:
  17. Training can be adjusted by modifying the arguments specified below::
  18. $ python main.py --exec_mode train --model_dir /dataset ...
  19. """
  20. import horovod.tensorflow as hvd
  21. from model.unet import Unet
  22. from runtime.run import train, evaluate, predict
  23. from runtime.setup import get_logger, set_flags, prepare_model_dir
  24. from runtime.arguments import PARSER, parse_args
  25. from data_loading.data_loader import Dataset
  26. def main():
  27. """
  28. Starting point of the application
  29. """
  30. hvd.init()
  31. params = parse_args(PARSER.parse_args())
  32. set_flags(params)
  33. model_dir = prepare_model_dir(params)
  34. params.model_dir = model_dir
  35. logger = get_logger(params)
  36. model = Unet()
  37. dataset = Dataset(data_dir=params.data_dir,
  38. batch_size=params.batch_size,
  39. fold=params.fold,
  40. augment=params.augment,
  41. gpu_id=hvd.rank(),
  42. num_gpus=hvd.size(),
  43. seed=params.seed,
  44. amp=params.use_amp)
  45. if 'train' in params.exec_mode:
  46. train(params, model, dataset, logger)
  47. if 'evaluate' in params.exec_mode:
  48. if hvd.rank() == 0:
  49. evaluate(params, model, dataset, logger)
  50. if 'predict' in params.exec_mode:
  51. if hvd.rank() == 0:
  52. predict(params, model, dataset, logger)
  53. if __name__ == '__main__':
  54. main()