nn_model.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. import typing
  17. from federatedml.framework.weights import Weights
  18. class NNModel(object):
  19. def get_model_weights(self) -> Weights:
  20. pass
  21. def set_model_weights(self, weights: Weights):
  22. pass
  23. def export_model(self):
  24. pass
  25. def load_model(self):
  26. pass
  27. def train(self, data, **kwargs):
  28. pass
  29. def predict(self, data, **kwargs):
  30. pass
  31. def evaluate(self, data, **kwargs):
  32. pass
  33. def modify(self, func: typing.Callable[[Weights], Weights]) -> Weights:
  34. weights = self.get_model_weights()
  35. self.set_model_weights(func(weights))
  36. return weights
  37. class DataConverter(object):
  38. def convert(self, data, *args, **kwargs):
  39. pass
  40. def get_nn_builder(config_type):
  41. if config_type == "keras":
  42. from federatedml.transfer_learning.hetero_ftl.backend.tf_keras.nn_model import build_keras
  43. return build_keras
  44. else:
  45. raise ValueError(f"{config_type} is not supported")