diff --git a/mindspore/lite/src/cxx_api/model/model.cc b/mindspore/lite/src/cxx_api/model/model.cc index 1548e6a132..f249c8b6e3 100644 --- a/mindspore/lite/src/cxx_api/model/model.cc +++ b/mindspore/lite/src/cxx_api/model/model.cc @@ -23,6 +23,10 @@ namespace mindspore { Status Model::Build(GraphCell graph, const std::shared_ptr &model_context) { + if (impl_ != nullptr) { + MS_LOG(DEBUG) << "Model has been already built."; + return kSuccess; + } impl_ = std::shared_ptr(new (std::nothrow) ModelImpl()); if (impl_ == nullptr) { MS_LOG(ERROR) << "Model implement is null."; diff --git a/mindspore/lite/src/cxx_api/model/model_impl.cc b/mindspore/lite/src/cxx_api/model/model_impl.cc index 51c3054735..f005a6f304 100644 --- a/mindspore/lite/src/cxx_api/model/model_impl.cc +++ b/mindspore/lite/src/cxx_api/model/model_impl.cc @@ -37,10 +37,6 @@ using mindspore::lite::RET_OK; Status ModelImpl::Build() { MS_LOG(DEBUG) << "Start build model."; - if (session_ != nullptr) { - MS_LOG(DEBUG) << "Model has been already built."; - return kSuccess; - } auto model = graph_->graph_data_->lite_model(); if (graph_ == nullptr || graph_->graph_data_ == nullptr || model == nullptr) { MS_LOG(ERROR) << "Invalid graph."; diff --git a/mindspore/lite/src/cxx_api/tensor/tensor_impl.cc b/mindspore/lite/src/cxx_api/tensor/tensor_impl.cc index a5c40304a6..471bc37589 100644 --- a/mindspore/lite/src/cxx_api/tensor/tensor_impl.cc +++ b/mindspore/lite/src/cxx_api/tensor/tensor_impl.cc @@ -67,14 +67,14 @@ MSTensor::Impl *MSTensor::Impl::StringsToTensorImpl(const std::string &name, con delete lite_tensor; return nullptr; } - auto impl = new (std::nothrow) Impl(); + auto impl = new (std::nothrow) Impl(lite_tensor); if (impl == nullptr) { delete lite_tensor; MS_LOG(ERROR) << "Failed to allocate tensor impl."; return nullptr; } - impl->set_lite_tensor(lite_tensor); impl->set_own_data(true); + impl->set_from_session(false); return impl; }