run_all_estimators.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import os
  2. import argparse
  3. import time
  4. def main():
  5. estimators = ["median", "variance", "std", "skewness", "kurtosis", "mode"]
  6. parser = argparse.ArgumentParser("Run estimators reconstruction")
  7. parser.add_argument('--folder', type=str, help='folder with rawls scene data', required=True)
  8. parser.add_argument('--nfiles', type=int, help='expected number of rawls files', required=True)
  9. parser.add_argument('--est', type=str, help='estimator to use', choices=estimators, required=True)
  10. parser.add_argument('--tiles', type=str, help='tiles size: 100,100', default="100,100")
  11. parser.add_argument('--output', type=str, help='output folder', required=True)
  12. args = parser.parse_args()
  13. p_folder = args.folder
  14. p_nfiles = args.nfiles
  15. p_est = args.est
  16. x_tile, y_tile = list(map(int, args.tiles.split(',')))
  17. p_output = args.output
  18. scenes = sorted(os.listdir(p_folder))
  19. for scene in scenes:
  20. scene_path = os.path.join(p_folder, scene)
  21. nelements = len(os.listdir(scene_path))
  22. if nelements == p_nfiles:
  23. print('Extraction of {0} estimator for {1} scene'.format(p_est, scene))
  24. output_folder = os.path.join(p_output, p_est, scene)
  25. if not os.path.exists(output_folder):
  26. os.makedirs(output_folder)
  27. outfilename = os.path.join(output_folder, scene + '_10000.rawls')
  28. if not os.path.exists(outfilename):
  29. t1 = time.time()
  30. os.system('./build/main/extract_stats_images --folder {0} --bwidth {1} --bheight {2} --outfile {3} --estimator {4}'.format(scene_path, x_tile, y_tile, p_est, outfilename))
  31. t2 = time.time()
  32. delta = (t2 - t1)
  33. print(f'Extraction for {scene}, took {delta}')
  34. else:
  35. print('Already generated')
  36. if __name__ == "__main__":
  37. main()