You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.py 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. """main logic."""
  2. import os
  3. import sys
  4. import time
  5. from multiprocessing import freeze_support
  6. import argv
  7. from config import Config as Conf
  8. from processing import SimpleProcessing
  9. from processing.folder import FolderImageProcessing
  10. from processing.multiple import MultipleImageProcessing
  11. def main(_):
  12. """Start main logic."""
  13. Conf.log.info("Welcome to DreamPower")
  14. if Conf.args['gpu_ids']:
  15. Conf.log.info("GAN Processing Will Use GPU IDs: {}".format(Conf.args['gpu_ids']))
  16. else:
  17. Conf.log.info("GAN Processing Will Use CPU")
  18. # Processing
  19. start = time.time()
  20. select_processing().run()
  21. Conf.log.info("Done! We have taken {} seconds".format(round(time.time() - start, 2)))
  22. # Exit
  23. sys.exit()
  24. def select_processing():
  25. """
  26. Select the processing to use following args parameters.
  27. :return: <Process> a process to run
  28. """
  29. if os.path.isdir(Conf.args['input']):
  30. process = processing_image_folder()
  31. elif Conf.args['n_runs'] != 1:
  32. process = multiple_image_processing()
  33. else:
  34. process = simple_image_processing()
  35. Conf.log.debug("Process to execute : {}".format(process))
  36. return process
  37. def simple_image_processing():
  38. """
  39. Define a simple image process ready to run.
  40. :param phases: <ImageTransform[]> list of image transformation
  41. :return: <SimpleTransform> a image process run ready
  42. """
  43. return SimpleProcessing()
  44. def multiple_image_processing():
  45. """
  46. Define a multiple image process ready to run.
  47. :param n_runs: number of times to process
  48. :return: <MultipleTransform> a multiple image process run ready
  49. """
  50. filename, extension = os.path.splitext(Conf.args['output'])
  51. Conf.args['input'] = [Conf.args['input'] for _ in range(Conf.args['n_runs'])]
  52. Conf.args['output'] = ["{}{}{}".format(filename, i, extension) for i in range(Conf.args['n_runs'])]
  53. return MultipleImageProcessing()
  54. def processing_image_folder():
  55. """
  56. Define a folder image process ready to run.
  57. :return: <FolderImageTransform> a image process run ready
  58. """
  59. return FolderImageProcessing()
  60. if __name__ == "__main__":
  61. freeze_support()
  62. argv.run()