Pipeline.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. from typing import List
  2. from pycs.pipeline.Fit import Fit
  3. from pycs.pipeline.Job import Job
  4. class Pipeline:
  5. def __init__(self, root_folder, distribution):
  6. """
  7. prepare everything needed to run jobs later
  8. :param root_folder: relative path to model folder
  9. :param distribution: object parsed from distribution.json
  10. """
  11. raise NotImplementedError
  12. def close(self):
  13. """
  14. is called everytime a pipeline is not needed anymore and should be used
  15. to free native resources
  16. :return:
  17. """
  18. raise NotImplementedError
  19. def execute(self, job: Job) -> List[dict]:
  20. """
  21. receive a job, execute it and return the predicted result
  22. :param job: that should be executed
  23. :return:
  24. """
  25. raise NotImplementedError
  26. # TODO documentation
  27. def fit(self, fit: List[Fit]):
  28. raise NotImplementedError
  29. # TODO documentation
  30. @staticmethod
  31. def create_labeled_image_result(label):
  32. return {
  33. 'type': 'labeled-image',
  34. 'label': label
  35. }
  36. # TODO documentation
  37. @staticmethod
  38. def create_bounding_box_result(x, y, w, h):
  39. return {
  40. 'type': 'bounding-box',
  41. 'x': x,
  42. 'y': y,
  43. 'w': w,
  44. 'h': h
  45. }
  46. # TODO documentation
  47. @staticmethod
  48. def create_labeled_bounding_box_result(x, y, w, h, label):
  49. return {
  50. 'type': 'labeled-bounding-box',
  51. 'x': x,
  52. 'y': y,
  53. 'w': w,
  54. 'h': h,
  55. 'label': label
  56. }