begin_radar_test.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import os
  2. import re
  3. import sys
  4. import argparse
  5. import shutil
  6. sys.path.append("/home/vangogh/software/FuzzScene/code/")
  7. import Constants
  8. def clear_output():
  9. path = Constants.CARLA_RADAR_PNG_OUTPUT_PATH
  10. shutil.rmtree(path) # 清空out图片
  11. os.mkdir(path)
  12. label_path = Constants.CARLA_RADAR_LABEL_OUTPUT_PATH
  13. file_list = os.listdir(label_path)
  14. for file in file_list:
  15. if re.match(r"label_test_\d+\.csv", file):
  16. os.remove(label_path + file)
  17. if os.path.exists(label_path + 'label_test.csv'): # 清空label_test.csv
  18. os.remove(label_path + 'label_test.csv')
  19. shutil.copy(label_path + 'label_test_null.csv', label_path + 'label_test.csv')
  20. # 清空radarx.csv以及mse.csv
  21. csv_path = Constants.CARLA_RADAR_DATA_PATH
  22. file_list = os.listdir(csv_path)
  23. for file in file_list:
  24. if re.match(r"radar\d+\.csv", file) or re.match(r"mse\.csv", file):
  25. os.remove(csv_path + file)
  26. seed_pool_path = Constants.RADAR_SEED_POOL
  27. if os.path.exists(seed_pool_path):
  28. shutil.rmtree(seed_pool_path) # 清空seed_pool
  29. shutil.copytree(Constants.RADAR_SEED_POOL_BAK, seed_pool_path)
  30. def main():
  31. print("[" + os.path.basename(__file__) + ", Line " + str(sys._getframe().f_lineno) + ", " + sys._getframe().f_code.co_name + "] ", "# Begin generate radar test data ")
  32. os.system("python radar_chart.py")
  33. print("[" + os.path.basename(__file__) + ", Line " + str(sys._getframe().f_lineno) + ", " + sys._getframe().f_code.co_name + "] ", "# Generate radar test data done, Start split data ")
  34. os.system("python " + Constants.CARLA_RADAR_LABEL_OUTPUT_PATH + "split.py")
  35. print("[" + os.path.basename(__file__) + ", Line " + str(sys._getframe().f_lineno) + ", " + sys._getframe().f_code.co_name + "] ", "# Split data done, Start radar test ")
  36. # 检查目录Constants.CARLA_RADAR_LABEL_OUTPUT_PATH下有多少个划分出的label子文件,子文件具有label_test_xx.csv的格式
  37. # # 定义文件名的正则表达式
  38. file_pattern = r"label_test_\d+\.csv"
  39. # 统计匹配到的文件数量
  40. count = 0
  41. for filename in os.listdir(Constants.CARLA_RADAR_LABEL_OUTPUT_PATH):
  42. if re.match(file_pattern, filename):
  43. count += 1
  44. print("[" + os.path.basename(__file__) + ", Line " + str(sys._getframe().f_lineno) + ", " + sys._getframe().f_code.co_name + "] ", "Found " + str(count) + " sub label files, Start radar test")
  45. for model_id in range(0, Constants.MODEL_NUM):
  46. for seq in range(0, count):
  47. os.system('python radar_error_test.py ' + str(Constants.MODEL_ARR[model_id]) + ' ' + str(seq))
  48. print("[" + os.path.basename(__file__) + ", Line " + str(sys._getframe().f_lineno) + ", " + sys._getframe().f_code.co_name + "] ", "# Radar test done, Start cal mse ")
  49. os.system("python " + Constants.CARLA_RADAR_DATA_PATH + "cal_mse.py")
  50. print("[" + os.path.basename(__file__) + ", Line " + str(sys._getframe().f_lineno) + ", " + sys._getframe().f_code.co_name + "] ", "# Cal mse done")
  51. print("# Operators Test Over")
  52. if __name__ == "__main__":
  53. if Constants.CLEAR_OUTPUT:
  54. clear_output()
  55. main()