6
0

Pipeline.py 2.1 KB

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