sampling.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import os
  2. from generate_carla import *
  3. from sampling_predict import *
  4. import pandas as pd
  5. model_name = "1"
  6. def sample_simulate(color1, color2, color3, time1, time2, fog, rain, sun, seed_name, domain_flags):
  7. mutation_name = seed_name.split("_")
  8. complete_mutation_name = "seed_0_0_" + mutation_name[3]
  9. parse_path = "../seed_pool/" + complete_mutation_name
  10. seed_number = mutation_name[3][0]
  11. # 使用minidom解析器打开 XML 文档
  12. DOMTree = xml.dom.minidom.parse(parse_path)
  13. # Linux下改一下路径
  14. ele = DOMTree.documentElement
  15. e = ele.getElementsByTagName("Entities")[0]
  16. s = ele.getElementsByTagName("Storyboard")[0]
  17. xml_path = '../seed_pool/' + seed_name
  18. variable = {"name": "origin & random parameters"}
  19. rand_para = [color1, color2, color3, time1, time2, fog, rain, sun]
  20. Simulation(rand_para, variable, e, s, domain_flags)
  21. # print("[" + os.path.basename(__file__) + ", Line " + str(sys._getframe().f_lineno) + ", " + sys._getframe().f_code.co_name + "] ", variable)
  22. writeBack(xml_path, DOMTree)
  23. print("[" + os.path.basename(__file__) + ", Line " + str(sys._getframe().f_lineno) + ", " + sys._getframe().f_code.co_name + "] ", "\n############# BEFORE RUNNING! ##############\n")
  24. os.system("bash ./ga_sim.sh " + seed_name)
  25. print("[" + os.path.basename(__file__) + ", Line " + str(sys._getframe().f_lineno) + ", " + sys._getframe().f_code.co_name + "] ", "\n############# AFTER RUNNING! ##############\n")
  26. sample_predict = prenum(model_name, seed_number)
  27. # os.system("python ga_error_test.py "+model_name+" 1 "+seed_name)
  28. # error=0
  29. # with open('./error_count.csv', 'r') as f:
  30. # rows = len(f.readlines()) - 1
  31. # f.seek(0)
  32. # for i, line in enumerate(f):
  33. # if i == 0:
  34. # continue
  35. # if line.split(',')[0]==seed_name:
  36. # error= int(line.split(',')[1])
  37. test_dataset_path = '../scenario_runner-0.9.13/_out/label_test.csv' # clear csv of each seed of sampling
  38. df = pd.read_csv(test_dataset_path)
  39. df.head(2)
  40. df = df.drop(df.index[0:250])
  41. df.to_csv(test_dataset_path, index=False, sep=',', encoding="utf-8")
  42. # path = '../scenario_runner-0.9.13/_out/'
  43. # shutil.rmtree(path + 'center') # 清空out
  44. # os.mkdir(path + 'center')
  45. return sample_predict