single_case_eval.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. ##################################################################
  4. #
  5. # Copyright (c) 2023 CICV, Inc. All Rights Reserved
  6. #
  7. ##################################################################
  8. """
  9. @Authors: yangzihao(yangzihao@china-icv.cn)
  10. @Data: 2024/01/30
  11. @Last Modified: 2024/01/30
  12. @Summary: Evaluateion functions
  13. """
  14. import os
  15. import sys
  16. sys.path.append('../config')
  17. sys.path.append('../common')
  18. sys.path.append('../modules')
  19. sys.path.append('../results')
  20. import json
  21. import traceback
  22. import log
  23. from config_parser import ConfigParse
  24. from single_case_evaluate import single_case_evaluate, single_case_statistic
  25. # from data_quality import frame_loss_statistic
  26. # from pdf_report_generate import report_generate
  27. from report_generate import report_generate
  28. def single_case_eval(configPath, resultPath, case_name):
  29. logger = log.get_logger()
  30. # case_name = os.path.basename(os.path.dirname(dataPath))
  31. # case_name = dataPath.split('/')[-1]
  32. # 判断文件夹是否为空
  33. if len(os.listdir(resultPath)) == 0:
  34. print("No files in data_path!") # 路径异常
  35. logger.error(f"[case:{case_name}] SINGLE_CASE_EVAL: No files in data_path!")
  36. sys.exit(-1)
  37. # 加载配置文件
  38. try:
  39. # json_file = os.path.join(configPath, 'config.json')
  40. config = ConfigParse(configPath)
  41. except Exception as e:
  42. print('Config file parsing ERROR!', e)
  43. traceback.print_exc()
  44. logger.error(f"[case:{case_name}] SINGLE_CASE_EVAL: Config file parsing ERROR: {repr(e)}!", exc_info=True)
  45. sys.exit(-1)
  46. # 单用例评价,并生成报告
  47. try:
  48. case_dict = single_case_evaluate(resultPath, config, case_name) # 评估单用例
  49. single_case_dict = single_case_statistic(case_dict) # 对单用例结果增加内容,并生成报告
  50. # 将单用例测试结果保存为json文件
  51. # single_case_dict.pop('playbackData')
  52. # single_case_dict.pop('evalData')
  53. # with open(f'{resultPath}/report.json', 'w', encoding='utf-8') as f:
  54. # f.write(json.dumps(single_case_dict, ensure_ascii=False))
  55. reportDict = single_case_dict
  56. reportPdf = f'{resultPath}/report.pdf'
  57. report_generate(reportDict, reportPdf)
  58. except Exception as e:
  59. traceback.print_exc()
  60. logger.error(f"[case:{case_name}] SINGLE_CASE_EVAL: Evaluate single case ERROR: {repr(e)}!", exc_info=True)
  61. sys.exit(-1)
  62. # def data_quality_detect(dataPath, case_name):
  63. # logger = log.get_logger()
  64. #
  65. # # first_order_loss = 0.01 # first : little loss 100
  66. # second_order_loss = 0.05 # second : could use 95
  67. # third_order_loss = 0.10 # third : could not use 90
  68. #
  69. # frame_loss_dict = frame_loss_statistic(dataPath)
  70. #
  71. # flag_frame_loss = False
  72. # for key, value in frame_loss_dict.items():
  73. # # sensor data
  74. # sensor_data = ["RoadMark", "RoadPos", "TrafficLight", "TrafficSign"]
  75. # if any(file in key for file in sensor_data):
  76. # # if "RoadMark" in key or "RoadPos" in key or "TrafficLight" in key or "TrafficSign" in key:
  77. # # if key[:-4] in ["RoadMark", "RoadPos", "TrafficLight", "TrafficSign"]:
  78. # logger.info(f"[case:{case_name}] SINGLE_CASE_EVAL: [{key}] : {value['result']}")
  79. # continue
  80. #
  81. # if value['frame_loss_rate'] > third_order_loss:
  82. # logger.error(
  83. # f"[case:{case_name}] SINGLE_CASE_EVAL: [{key}] frame loss rate > {third_order_loss * 100}%: {value['result']}")
  84. # flag_frame_loss = True
  85. # elif value['frame_loss_rate'] > second_order_loss:
  86. # logger.info(
  87. # f"[case:{case_name}] SINGLE_CASE_EVAL: [{key}] frame loss rate > {second_order_loss * 100}%: {value['result']}")
  88. # else:
  89. # logger.info(
  90. # f"[case:{case_name}] SINGLE_CASE_EVAL: [{key}] frame loss rate < {second_order_loss * 100}%: {value['result']}")
  91. #
  92. # return flag_frame_loss