runner.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # Copyright (c) 2024 PaddlePaddle Authors. 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. from ..cls import ClsRunner
  15. class ShiTuRecRunner(ClsRunner):
  16. """ShiTuRec Runner"""
  17. def _extract_eval_metrics(stdout: str) -> dict:
  18. """extract evaluation metrics from training log
  19. Args:
  20. stdout (str): the training log
  21. Returns:
  22. dict: the training metric
  23. """
  24. import re
  25. _DP = r"[-+]?[0-9]*\.?[0-9]+(?:[eE][-+]?[0-9]+)?"
  26. patterns = [
  27. r"\[Eval\]\[Epoch 0\]\[Avg\].*top1: (_dp), top5: (_dp)".replace("_dp", _DP),
  28. r"\[Eval\]\[Epoch 0\]\[Avg\].*recall1: (_dp), recall5: (_dp), mAP: (_dp)".replace(
  29. "_dp", _DP
  30. ),
  31. ]
  32. keys = [["val.top1", "val.top5"], ["recall1", "recall5", "mAP"]]
  33. metric_dict = dict()
  34. for pattern, key in zip(patterns, keys):
  35. pattern = re.compile(pattern)
  36. for line in stdout.splitlines():
  37. match = pattern.search(line)
  38. if match:
  39. for k, v in zip(key, map(float, match.groups())):
  40. metric_dict[k] = v
  41. return metric_dict