tool.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import sys
  2. import os
  3. import json
  4. # from lemon_master.mutation_executor import lemon_process
  5. from lemon_master.run.mutation_executor import lemon_process
  6. def mock(exp: str, root_dir: str, output_dir: str, mutate_num: int, config_name: str):
  7. print("running")
  8. print("exp:", exp)
  9. print("root_dir:", root_dir)
  10. print("out_dir:", output_dir)
  11. print("mutate_num:", mutate_num)
  12. print("config_name:", config_name)
  13. data = [
  14. {
  15. "model": "lenet5-fashion-mnist",
  16. "method": "origin0",
  17. "result": {
  18. "Losses": 0.3032414233312011,
  19. "Accuracy": 0.9062593914568424,
  20. "MemoryInfoList": 1.2329671382904053,
  21. },
  22. }
  23. ]
  24. return data
  25. result_num = 0
  26. def runtool(
  27. exp: str, mutate_num: int
  28. ):
  29. global result_num
  30. config_name = "demo.conf"
  31. base_dir = os.path.dirname(os.path.abspath(__file__))
  32. print(base_dir)
  33. result_num = ( result_num + 1 ) % 5
  34. output_dir = os.path.join(base_dir, "output", str(result_num))
  35. if os.path.exists(output_dir):
  36. print("remove output_dir:", output_dir)
  37. # TODO: 正式时需要删除 os.system("rm -rf " + output_dir)
  38. print("running")
  39. print("exp:", exp)
  40. print("out_dir:", output_dir)
  41. print("mutate_num:", mutate_num)
  42. print("config_name:", config_name)
  43. root_dir = os.path.join(base_dir, "lemon_master")
  44. target_dir = os.path.join(base_dir, "lemon_master", "run")
  45. print(target_dir)
  46. sys.path.append(target_dir)
  47. # TODO: 正式时需要注释lemon_process(exp, root_dir, output_dir, mutate_num, config_name)
  48. real_output_dir = os.path.join(output_dir, exp)
  49. mxnet_json = os.path.join(real_output_dir, "mxnet.json")
  50. with open(
  51. mxnet_json, "r"
  52. ) as file1: # tensorflow.json
  53. data1 = json.load(file1)
  54. tensorflow_json = os.path.join(real_output_dir, "tensorflow.json")
  55. with open(tensorflow_json, "r") as file2:
  56. data2 = json.load(file2)
  57. combined_data = {
  58. "mxnet": data1,
  59. "tensorflow": data2
  60. }
  61. return combined_data