You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

train.py 2.6 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # Copyright 2023 The KubeEdge Authors.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. import os
  15. from sedna.core.lifelong_learning import LifelongLearning
  16. from sedna.common.config import Context, BaseConfig
  17. from sedna.datasources import TxtDataParse
  18. from interface import Estimator
  19. def _load_txt_dataset(dataset_url):
  20. # use original dataset url
  21. original_dataset_url = Context.get_parameters('original_dataset_url', "")
  22. dataset_urls = dataset_url.split()
  23. dataset_urls = [
  24. os.path.join(
  25. os.path.dirname(original_dataset_url),
  26. dataset_url) for dataset_url in dataset_urls]
  27. return dataset_urls[:-1], dataset_urls[-1]
  28. def train(estimator, train_data):
  29. task_definition = {
  30. "method": "TaskDefinitionByOrigin",
  31. "param": {
  32. "attribute": Context.get_parameters("attribute"),
  33. "city": Context.get_parameters("city")
  34. }
  35. }
  36. task_allocation = {
  37. "method": "TaskAllocationByOrigin"
  38. }
  39. ll_job = LifelongLearning(estimator,
  40. task_definition=task_definition,
  41. task_relationship_discovery=None,
  42. task_allocation=task_allocation,
  43. task_remodeling=None,
  44. inference_integrate=None,
  45. task_update_decision=None,
  46. unseen_task_allocation=None,
  47. unseen_sample_recognition=None,
  48. unseen_sample_re_recognition=None
  49. )
  50. ll_job.train(train_data)
  51. def run():
  52. estimator = Estimator(num_class=int(Context.get_parameters("num_class", 24)),
  53. epochs=int(Context.get_parameters("epoches", 1)))
  54. train_dataset_url = BaseConfig.train_dataset_url
  55. train_data = TxtDataParse(data_type="train", func=_load_txt_dataset)
  56. train_data.parse(train_dataset_url, use_raw=False)
  57. train(estimator, train_data)
  58. if __name__ == '__main__':
  59. run()