output.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #
  2. # Copyright 2019 The FATE Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. from pipeline.backend.config import IODataType
  17. class Output(object):
  18. def __init__(self, name, data_type='single', has_data=True, has_model=True, has_cache=False, output_unit=1):
  19. if has_model:
  20. self.model = Model(name).model
  21. self.model_output = Model(name).get_all_output()
  22. if has_data:
  23. if data_type == "single":
  24. self.data = SingleOutputData(name).data
  25. self.data_output = SingleOutputData(name).get_all_output()
  26. elif data_type == "multi":
  27. self.data = TraditionalMultiOutputData(name)
  28. self.data_output = TraditionalMultiOutputData(name).get_all_output()
  29. else:
  30. self.data = NoLimitOutputData(name, output_unit)
  31. self.data_output = NoLimitOutputData(name, output_unit).get_all_output()
  32. if has_cache:
  33. self.cache = Cache(name).cache
  34. self.cache_output = Cache(name).get_all_output()
  35. class Model(object):
  36. def __init__(self, prefix):
  37. self.prefix = prefix
  38. @property
  39. def model(self):
  40. return ".".join([self.prefix, "model"])
  41. @staticmethod
  42. def get_all_output():
  43. return ["model"]
  44. class SingleOutputData(object):
  45. def __init__(self, prefix):
  46. self.prefix = prefix
  47. @property
  48. def data(self):
  49. return ".".join([self.prefix, IODataType.SINGLE])
  50. @staticmethod
  51. def get_all_output():
  52. return ["data"]
  53. class TraditionalMultiOutputData(object):
  54. def __init__(self, prefix):
  55. self.prefix = prefix
  56. @property
  57. def train_data(self):
  58. return ".".join([self.prefix, IODataType.TRAIN])
  59. @property
  60. def test_data(self):
  61. return ".".join([self.prefix, IODataType.TEST])
  62. @property
  63. def validate_data(self):
  64. return ".".join([self.prefix, IODataType.VALIDATE])
  65. @staticmethod
  66. def get_all_output():
  67. return [IODataType.TRAIN,
  68. IODataType.VALIDATE,
  69. IODataType.TEST]
  70. class NoLimitOutputData(object):
  71. def __init__(self, prefix, output_unit=1):
  72. self.prefix = prefix
  73. self.output_unit = output_unit
  74. @property
  75. def data(self):
  76. return [self.prefix + "." + "data_" + str(i) for i in range(self.output_unit)]
  77. def get_all_output(self):
  78. return ["data_" + str(i) for i in range(self.output_unit)]
  79. class Cache(object):
  80. def __init__(self, prefix):
  81. self.prefix = prefix
  82. @property
  83. def cache(self):
  84. return ".".join([self.prefix, "cache"])
  85. @staticmethod
  86. def get_all_output():
  87. return ["cache"]