您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

multiple.py 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. """Multiple Image Transform Processing."""
  2. import copy
  3. from multiprocessing.pool import ThreadPool
  4. from config import Config as Conf
  5. from processing import Processing, SimpleProcessing
  6. from utils import camel_case_to_str
  7. class MultipleImageProcessing(Processing):
  8. """Multiple Image Processing Class."""
  9. def _setup(self, *args):
  10. self._input_paths = self._args['input']
  11. self._output_paths = self._args['output']
  12. self._process_list = []
  13. self._multiprocessing = Conf.multiprocessing()
  14. self._process_list = []
  15. for input_path, output_path in zip(self._input_paths, self._output_paths):
  16. args = copy.deepcopy(self._args)
  17. args['input'] = input_path
  18. args['output'] = output_path
  19. self._process_list.append((SimpleProcessing(args), args))
  20. Conf.log.debug(self._process_list)
  21. def _process_one(self, a):
  22. Conf.log.info("{} : {}/{}".format(
  23. camel_case_to_str(self.__class__.__name__), a[1] + 1, len(self._process_list)
  24. ))
  25. a[0][0].run(config=a[0][1])
  26. def _execute(self, *args):
  27. """
  28. Execute all phases on the list of images.
  29. :return: None
  30. """
  31. if not self._multiprocessing:
  32. for x in zip(self._process_list, range(len(self._process_list))):
  33. self._process_one(x)
  34. else:
  35. Conf.log.debug("Using Multiprocessing")
  36. pool = ThreadPool(Conf.args['n_cores'])
  37. pool.map(self._process_one, zip(self._process_list, range(len(self._process_list))))
  38. pool.close()
  39. pool.join()