display_simulation_curves.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. # main imports
  2. import numpy as np
  3. import pandas as pd
  4. import os, sys, argparse
  5. # image processing imports
  6. import matplotlib.pyplot as plt
  7. # modules imports
  8. sys.path.insert(0, '') # trick to enable import of main folder module
  9. import custom_config as cfg
  10. from data_attributes import get_image_features
  11. # other variables
  12. learned_zones_folder = cfg.learned_zones_folder
  13. models_name = cfg.models_names_list
  14. label_freq = 6
  15. def display_curves(folder_path, model_name):
  16. """
  17. @brief Method used to display simulation given .csv files
  18. @param folder_path, folder which contains all .csv files obtained during simulation
  19. @param model_name, current name of model
  20. @return nothing
  21. """
  22. for name in models_name:
  23. if name in model_name:
  24. data_filename = model_name
  25. learned_zones_folder_path = os.path.join(learned_zones_folder, data_filename)
  26. data_files = [x for x in os.listdir(folder_path) if '.png' not in x]
  27. scene_names = [f.split('_')[3] for f in data_files]
  28. for id, f in enumerate(data_files):
  29. print(scene_names[id])
  30. path_file = os.path.join(folder_path, f)
  31. scenes_zones_used_file_path = os.path.join(learned_zones_folder_path, scene_names[id] + '.csv')
  32. zones_used = []
  33. with open(scenes_zones_used_file_path, 'r') as f:
  34. zones_used = [int(x) for x in f.readline().split(';') if x != '']
  35. print(zones_used)
  36. df = pd.read_csv(path_file, header=None, sep=";")
  37. fig=plt.figure(figsize=(35, 22))
  38. fig.suptitle("Detection simulation for " + scene_names[id] + " scene", fontsize=20)
  39. for index, row in df.iterrows():
  40. row = np.asarray(row)
  41. threshold = row[2]
  42. start_index = row[3]
  43. step_value = row[4]
  44. counter_index = 0
  45. current_value = start_index
  46. while(current_value < threshold):
  47. counter_index += 1
  48. current_value += step_value
  49. fig.add_subplot(4, 4, (index + 1))
  50. plt.plot(row[5:])
  51. if index in zones_used:
  52. ax = plt.gca()
  53. ax.set_facecolor((0.9, 0.95, 0.95))
  54. # draw vertical line from (70,100) to (70, 250)
  55. plt.plot([counter_index, counter_index], [-2, 2], 'k-', lw=2, color='red')
  56. if index % 4 == 0:
  57. plt.ylabel('Not noisy / Noisy', fontsize=20)
  58. if index >= 12:
  59. plt.xlabel('Samples per pixel', fontsize=20)
  60. x_labels = [id * step_value + start_index for id, val in enumerate(row[5:]) if id % label_freq == 0]
  61. x = [v for v in np.arange(0, len(row[5:])+1) if v % label_freq == 0]
  62. plt.xticks(x, x_labels, rotation=45)
  63. plt.ylim(-1, 2)
  64. plt.savefig(os.path.join(folder_path, scene_names[id] + '_simulation_curve.png'))
  65. #plt.show()
  66. def main():
  67. parser = argparse.ArgumentParser(description="Display simulations curves from simulation data")
  68. parser.add_argument('--folder', type=str, help='Folder which contains simulations data for scenes')
  69. parser.add_argument('--model', type=str, help='Name of the model used for simulations')
  70. args = parser.parse_args()
  71. p_folder = args.folder
  72. if args.model:
  73. p_model = args.model
  74. else:
  75. # find p_model from folder if model arg not given (folder path need to have model name)
  76. if p_folder.split('/')[-1]:
  77. p_model = p_folder.split('/')[-1]
  78. else:
  79. p_model = p_folder.split('/')[-2]
  80. print(p_model)
  81. display_curves(p_folder, p_model)
  82. print(p_folder)
  83. if __name__== "__main__":
  84. main()