logging.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # !/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # ==============================================================================
  4. #
  5. # Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
  6. #
  7. # Licensed under the Apache License, Version 2.0 (the "License");
  8. # you may not use this file except in compliance with the License.
  9. # 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, software
  14. # distributed under the License is distributed on an "AS IS" BASIS,
  15. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. # See the License for the specific language governing permissions and
  17. # limitations under the License.
  18. #
  19. # ==============================================================================
  20. import dllogger as Logger
  21. def format_step(step):
  22. if isinstance(step, str):
  23. return step
  24. if isinstance(step, int):
  25. return "Iteration: {} ".format(step)
  26. s = ""
  27. if len(step) > 0:
  28. s += "Epoch: {} ".format(step[0])
  29. if len(step) > 1:
  30. s += "Iteration: {} ".format(step[1])
  31. if len(step) > 2:
  32. s += "Validation Iteration: {} ".format(step[2])
  33. return s
  34. def init_dllogger(log_dir):
  35. Logger.init([
  36. Logger.StdOutBackend(Logger.Verbosity.DEFAULT, step_format=format_step),
  37. Logger.JSONStreamBackend(Logger.Verbosity.VERBOSE, log_dir)
  38. ])