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.

model.cc 2.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. #include "include/api/model.h"
  17. #include "include/api/context.h"
  18. #include "cxx_api/model/model_impl.h"
  19. #include "cxx_api/factory.h"
  20. #include "utils/utils.h"
  21. namespace mindspore::api {
  22. Status Model::Build(const std::map<std::string, std::string> &options) {
  23. MS_EXCEPTION_IF_NULL(impl_);
  24. return impl_->Build(options);
  25. }
  26. Status Model::Train(const DataSet &dataset, bool data_sink, std::map<std::string, Buffer> *outputs) {
  27. MS_EXCEPTION_IF_NULL(impl_);
  28. return impl_->Train(dataset, outputs);
  29. }
  30. Status Model::Eval(const DataSet &dataset, bool data_sink, std::map<std::string, Buffer> *outputs) {
  31. MS_EXCEPTION_IF_NULL(impl_);
  32. return impl_->Eval(dataset, outputs);
  33. }
  34. Status Model::Predict(const std::vector<Buffer> &inputs, std::vector<Buffer> *outputs) {
  35. MS_EXCEPTION_IF_NULL(impl_);
  36. return impl_->Predict(inputs, outputs);
  37. }
  38. Status Model::GetInputsInfo(std::vector<std::string> *names, std::vector<std::vector<int64_t>> *shapes,
  39. std::vector<DataType> *data_types, std::vector<size_t> *mem_sizes) const {
  40. MS_EXCEPTION_IF_NULL(impl_);
  41. return impl_->GetInputsInfo(names, shapes, data_types, mem_sizes);
  42. }
  43. Status Model::GetOutputsInfo(std::vector<std::string> *names, std::vector<std::vector<int64_t>> *shapes,
  44. std::vector<DataType> *data_types, std::vector<size_t> *mem_sizes) const {
  45. MS_EXCEPTION_IF_NULL(impl_);
  46. return impl_->GetOutputsInfo(names, shapes, data_types, mem_sizes);
  47. }
  48. Model::Model(const GraphCell &graph_cell)
  49. : impl_(Factory<ModelImpl>::Instance().Create(Context::Instance().GetDeviceTarget())) {
  50. if (impl_ == nullptr) {
  51. MS_LOG(EXCEPTION) << "Create session type " << Context::Instance().GetDeviceTarget() << " failed";
  52. }
  53. MS_EXCEPTION_IF_NULL(graph_cell.GetGraph());
  54. impl_->SetGraph(std::make_shared<Graph>(*graph_cell.GetGraph()));
  55. }
  56. Model::Model(const std::vector<Output> &network) { MS_LOG(EXCEPTION) << "Unsupported feature."; }
  57. Model::~Model() {}
  58. bool Model::CheckModelSupport(const std::string &device_type, ModelType) {
  59. return Factory<ModelImpl>::Instance().CheckModelSupport(device_type);
  60. }
  61. } // namespace mindspore::api