run_pbrt.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import os
  2. import argparse
  3. str_command = "{0} --startindex {1} --images {2} --samples {3} --folder {4} {5}"
  4. def main():
  5. parser = argparse.ArgumentParser(description="Run and relaunch computation of pbrt-v3")
  6. parser.add_argument('--pbrt', type=str, help='executable pbrt file', required=True)
  7. parser.add_argument('--scenes', type=str, help='folder with all pbrt scenes', required=True)
  8. parser.add_argument('--output', type=str, help='output folder for scenes', required=True)
  9. parser.add_argument('--samples', type=int, help='number of expected samples for this run', required=True)
  10. parser.add_argument('--images', type=int, help='number of expected images for this run', required=True)
  11. parser.add_argument('--file', type=str, help='file with expected pbrt scenes to launch', required=True)
  12. args = parser.parse_args()
  13. p_pbrt = args.pbrt
  14. p_scenes = args.scenes
  15. p_output = args.output
  16. p_samples = args.samples
  17. p_images = args.images
  18. p_file = args.file
  19. with open(p_file, 'r') as f:
  20. lines = [ l.replace('\n', '') for l in f.readlines() ]
  21. for l in lines:
  22. scene_path = os.path.join(p_scenes, l)
  23. folder = l.split('/')[-1].replace('.pbrt', '')
  24. print(folder)
  25. output_folder = os.path.join(p_output, folder)
  26. # check restart from
  27. start_index = 0
  28. current_nb_images = p_images
  29. if os.path.exists(output_folder):
  30. n_elements = len(os.listdir(output_folder))
  31. # update start index and number of expected images now
  32. start_index = n_elements
  33. current_nb_images = p_images - n_elements
  34. if current_nb_images > 0:
  35. print('Run {0} images with {1} samples using {2} as first index for : {3}'.format(current_nb_images, p_samples, start_index, l))
  36. main_command = str_command.format(p_pbrt, start_index, current_nb_images, p_samples, p_output, scene_path)
  37. os.system(main_command)
  38. else:
  39. print('All expected images already generated for : {0}'.format(l))
  40. if __name__ == "__main__":
  41. main()