Pipeline.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. from typing import List
  2. from pycs.interfaces.MediaFile import MediaFile
  3. from pycs.interfaces.MediaStorage import MediaStorage
  4. class Pipeline:
  5. """
  6. pipeline interface that should be implemented by model developers
  7. """
  8. #pylint: disable=unnecessary-pass
  9. def __init__(self, root_folder: str, distribution: dict):
  10. """
  11. prepare everything needed to run jobs later
  12. :param root_folder: relative path to model folder
  13. :param distribution: dict parsed from distribution.json
  14. """
  15. pass
  16. #pylint: disable=unnecessary-pass
  17. def close(self):
  18. """
  19. is called everytime a pipeline is not needed anymore and should be used
  20. to free native resources
  21. :return:
  22. """
  23. pass
  24. #pylint: disable=no-self-use
  25. def collections(self) -> List[dict]:
  26. """
  27. is called while initializing a pipeline to receive available
  28. collections
  29. :return: list of collections or None
  30. """
  31. return []
  32. @staticmethod
  33. def create_collection(reference: str,
  34. name: str,
  35. description: str = None,
  36. autoselect: bool = False) -> dict:
  37. """
  38. create a collection dict
  39. :param reference: unique reference
  40. :param name: collection name
  41. :param description: collection description
  42. :param autoselect: show this collection by default if it contains elements
  43. :return: collection dict
  44. """
  45. return {
  46. 'reference': reference,
  47. 'name': name,
  48. 'description': description,
  49. 'autoselect': autoselect
  50. }
  51. def execute(self, storage: MediaStorage, file: MediaFile):
  52. """
  53. receive a file, create predictions and add them to the object
  54. :param storage: database abstraction object
  55. :param file: which should be analyzed
  56. """
  57. raise NotImplementedError
  58. def fit(self, storage: MediaStorage):
  59. """
  60. receive a list of annotated media files and adapt the underlying model
  61. :param storage: database abstraction object
  62. """
  63. raise NotImplementedError