train.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # Copyright 2017-2018 The Apache Software Foundation
  2. #
  3. # Licensed to the Apache Software Foundation (ASF) under one
  4. # or more contributor license agreements. See the NOTICE file
  5. # distributed with this work for additional information
  6. # regarding copyright ownership. The ASF licenses this file
  7. # to you under the Apache License, Version 2.0 (the
  8. # "License"); you may not use this file except in compliance
  9. # with the License. You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing,
  14. # software distributed under the License is distributed on an
  15. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. # KIND, either express or implied. See the License for the
  17. # specific language governing permissions and limitations
  18. # under the License.
  19. #
  20. # -----------------------------------------------------------------------
  21. #
  22. # Copyright (c) 2019-2022, NVIDIA CORPORATION. All rights reserved.
  23. #
  24. # Licensed under the Apache License, Version 2.0 (the "License");
  25. # you may not use this file except in compliance with the License.
  26. # You may obtain a copy of the License at
  27. #
  28. # http://www.apache.org/licenses/LICENSE-2.0
  29. #
  30. # Unless required by applicable law or agreed to in writing, software
  31. # distributed under the License is distributed on an "AS IS" BASIS,
  32. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  33. # See the License for the specific language governing permissions and
  34. # limitations under the License.
  35. import argparse
  36. import dllogger
  37. import horovod.mxnet as hvd
  38. import dali
  39. import data
  40. import fit
  41. import models
  42. from log_utils import setup_logging
  43. def parse_args():
  44. parser = argparse.ArgumentParser(description="Train classification models on ImageNet",
  45. formatter_class=argparse.ArgumentDefaultsHelpFormatter)
  46. models.add_model_args(parser)
  47. fit.add_fit_args(parser)
  48. data.add_data_args(parser)
  49. dali.add_dali_args(parser)
  50. data.add_data_aug_args(parser)
  51. return parser.parse_args()
  52. if __name__ == '__main__':
  53. args = parse_args()
  54. if 'horovod' in args.kv_store:
  55. hvd.init()
  56. setup_logging(args)
  57. dllogger.log(step='PARAMETER', data=vars(args))
  58. model = models.get_model(**vars(args))
  59. data_loader = data.get_data_loader(args)
  60. fit.fit(args, model, data_loader)