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_session.h 1.9 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /**
  2. * Copyright 2020 Huawei Technologies Co., Ltd
  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. #ifndef MINDSPORE_LITE_INCLUDE_TRAIN_SESSION_H_
  17. #define MINDSPORE_LITE_INCLUDE_TRAIN_SESSION_H_
  18. #include <vector>
  19. #include <string>
  20. #include <unordered_map>
  21. #include "src/lite_session.h"
  22. namespace mindspore {
  23. namespace lite {
  24. struct Model;
  25. }
  26. namespace session {
  27. class TrainSession : public lite::LiteSession {
  28. public:
  29. TrainSession();
  30. ~TrainSession();
  31. int RunGraph(const session::KernelCallBack &before = nullptr,
  32. const session::KernelCallBack &after = nullptr) override;
  33. int CompileGraph(lite::Model *model) override;
  34. virtual void ReplaceOps();
  35. virtual void* ExportToBuf(lite::Model *model, void* buf, size_t* len) const;
  36. // todo: output tensors by tensor name
  37. std::unordered_map<std::string, std::vector<mindspore::tensor::MSTensor *>> GetOutputMap() const;
  38. std::vector<tensor::MSTensor *> GetOutputsByName(const std::string &node_name) const;
  39. virtual void train();
  40. bool is_train() { return train_mode_ == true; }
  41. virtual void eval();
  42. bool is_eval() { return train_mode_ == false; }
  43. protected:
  44. bool train_mode_ = false;
  45. lite::Model *model_ = nullptr;
  46. std::unordered_map<std::string, std::vector<mindspore::tensor::MSTensor *>> ext_output_map_;
  47. // private:
  48. };
  49. } // namespace session
  50. } // namespace mindspore
  51. #endif // MINDSPORE_LITE_INCLUDE_TRAIN_SESSION_H_