You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

config.py 3.2 kB

5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # Copyright 2020 Huawei Technologies Co., Ltd
  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. # ============================================================================
  15. """
  16. network config setting, will be used in train.py and eval.py
  17. """
  18. import os
  19. from easydict import EasyDict as ed
  20. def set_config(args):
  21. config_cpu = ed({
  22. "num_classes": 26,
  23. "image_height": 224,
  24. "image_width": 224,
  25. "batch_size": 150,
  26. "epoch_size": 15,
  27. "warmup_epochs": 0,
  28. "lr_init": .0,
  29. "lr_end": 0.03,
  30. "lr_max": 0.03,
  31. "momentum": 0.9,
  32. "weight_decay": 4e-5,
  33. "label_smooth": 0.1,
  34. "loss_scale": 1024,
  35. "save_checkpoint": True,
  36. "save_checkpoint_epochs": 1,
  37. "keep_checkpoint_max": 20,
  38. "save_checkpoint_path": "./",
  39. "platform": args.platform,
  40. "run_distribute": False,
  41. "activation": "Softmax"
  42. })
  43. config_gpu = ed({
  44. "num_classes": 1000,
  45. "image_height": 224,
  46. "image_width": 224,
  47. "batch_size": 150,
  48. "epoch_size": 200,
  49. "warmup_epochs": 0,
  50. "lr_init": .0,
  51. "lr_end": .0,
  52. "lr_max": 0.8,
  53. "momentum": 0.9,
  54. "weight_decay": 4e-5,
  55. "label_smooth": 0.1,
  56. "loss_scale": 1024,
  57. "save_checkpoint": True,
  58. "save_checkpoint_epochs": 1,
  59. "keep_checkpoint_max": 200,
  60. "save_checkpoint_path": "./",
  61. "platform": args.platform,
  62. "ccl": "nccl",
  63. "run_distribute": args.run_distribute,
  64. "activation": "Softmax"
  65. })
  66. config_ascend = ed({
  67. "num_classes": 1000,
  68. "image_height": 224,
  69. "image_width": 224,
  70. "batch_size": 256,
  71. "epoch_size": 200,
  72. "warmup_epochs": 4,
  73. "lr_init": 0.00,
  74. "lr_end": 0.00,
  75. "lr_max": 0.4,
  76. "momentum": 0.9,
  77. "weight_decay": 4e-5,
  78. "label_smooth": 0.1,
  79. "loss_scale": 1024,
  80. "save_checkpoint": True,
  81. "save_checkpoint_epochs": 1,
  82. "keep_checkpoint_max": 200,
  83. "save_checkpoint_path": "./",
  84. "platform": args.platform,
  85. "ccl": "hccl",
  86. "device_id": int(os.getenv('DEVICE_ID', '0')),
  87. "rank_id": int(os.getenv('RANK_ID', '0')),
  88. "rank_size": int(os.getenv('RANK_SIZE', '1')),
  89. "run_distribute": int(os.getenv('RANK_SIZE', '1')) > 1.,
  90. "activation": "Softmax"
  91. })
  92. config = ed({"CPU": config_cpu,
  93. "GPU": config_gpu,
  94. "Ascend": config_ascend})
  95. if args.platform not in config.keys():
  96. raise ValueError("Unsupport platform.")
  97. return config[args.platform]