save_model_result_in_md.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. from sklearn.externals import joblib
  2. import numpy as np
  3. from ipfml import processing
  4. from PIL import Image
  5. import sys, os, argparse
  6. import subprocess
  7. import time
  8. from modules.utils import config as cfg
  9. threshold_map_folder = cfg.threshold_map_folder
  10. threshold_map_file_prefix = cfg.threshold_map_folder + "_"
  11. markdowns_folder = cfg.models_information_folder
  12. zones = cfg.zones_indices
  13. current_dirpath = os.getcwd()
  14. def main():
  15. parser = argparse.ArgumentParser(description="Display SVD data of scene zone")
  16. parser.add_argument('--interval', type=str, help='Interval value to keep from svd', default='"0, 200"')
  17. parser.add_argument('--model', type=str, help='.joblib or .json file (sklearn or keras model)')
  18. parser.add_argument('--metric', type=str, help='Metric data choice', choices=cfg.metric_choices)
  19. parser.add_argument('--mode', type=str, help='Kind of normalization level wished', choices=cfg.normalization_choices)
  20. args = parser.parse_args()
  21. p_interval = list(map(int, args.interval.split(',')))
  22. p_model_file = args.model
  23. p_metric = args.metric
  24. p_mode = args.mode
  25. # call model and get global result in scenes
  26. begin, end = p_interval
  27. bash_cmd = "bash testModelByScene.sh '" + str(begin) + "' '" + str(end) + "' '" + p_model_file + "' '" + p_mode + "' '" + p_metric + "'"
  28. print(bash_cmd)
  29. ## call command ##
  30. p = subprocess.Popen(bash_cmd, stdout=subprocess.PIPE, shell=True)
  31. (output, err) = p.communicate()
  32. ## Wait for result ##
  33. p_status = p.wait()
  34. if not os.path.exists(markdowns_folder):
  35. os.makedirs(markdowns_folder)
  36. # get model name to construct model
  37. md_model_path = os.path.join(markdowns_folder, p_model_file.split('/')[-1].replace('.joblib', '.md'))
  38. with open(md_model_path, 'w') as f:
  39. f.write(output.decode("utf-8"))
  40. # read each threshold_map information if exists
  41. model_map_info_path = os.path.join(threshold_map_folder, p_model_file.replace('saved_models/', ''))
  42. if not os.path.exists(model_map_info_path):
  43. f.write('\n\n No threshold map information')
  44. else:
  45. maps_files = os.listdir(model_map_info_path)
  46. # get all map information
  47. for t_map_file in maps_files:
  48. file_path = os.path.join(model_map_info_path, t_map_file)
  49. with open(file_path, 'r') as map_file:
  50. title_scene = t_map_file.replace(threshold_map_file_prefix, '')
  51. f.write('\n\n## ' + title_scene + '\n')
  52. content = map_file.readlines()
  53. # getting each map line information
  54. for line in content:
  55. f.write(line)
  56. f.close()
  57. if __name__== "__main__":
  58. main()