run_all_estimators_reduced.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import os
  2. import argparse
  3. import time
  4. def main():
  5. estimators = ["mean", "median", "var", "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('--tiles', type=str, help='tiles size: 100,100', default="100,100")
  10. parser.add_argument('--output', type=str, help='output folder', required=True)
  11. args = parser.parse_args()
  12. p_folder = args.folder
  13. p_nfiles = args.nfiles
  14. x_tile, y_tile = list(map(int, args.tiles.split(',')))
  15. p_output = args.output
  16. scenes = sorted(os.listdir(p_folder))
  17. for scene in scenes:
  18. scene_path = os.path.join(p_folder, scene)
  19. nelements = len(os.listdir(scene_path))
  20. if nelements == p_nfiles:
  21. # check all scene folder exists
  22. checked_folder = []
  23. for est in estimators:
  24. output_folder = os.path.join(p_output, est, scene)
  25. if not os.path.exists(output_folder):
  26. os.makedirs(output_folder)
  27. outfilename = os.path.join(output_folder, scene + '.rawls')
  28. checked_folder.append(os.path.exists(outfilename))
  29. if not all(checked_folder):
  30. print(f'Extraction of estimators for {scene} scene')
  31. t1 = time.time()
  32. os.system('./build/main/extract_stats_images_all_reduced --folder {0} --bwidth {1} --bheight {2} --nfiles {3} --output {4}'.format(scene_path, x_tile, y_tile, p_nfiles, p_output))
  33. t2 = time.time()
  34. delta = (t2 - t1)
  35. print(f'Extraction for {scene}, took {delta}')
  36. else:
  37. print(f'Estimators for {scene}, already generated')
  38. if __name__ == "__main__":
  39. main()