From dd2bd8e35f04e412040180a0c602c92529129e92 Mon Sep 17 00:00:00 2001 From: Chunwei Date: Thu, 11 Apr 2019 12:19:49 +0800 Subject: [PATCH] update --- paddle/fluid/lite/core/tensor.h | 1 + paddle/fluid/lite/model_parser/model_parser.cc | 6 ++++++ paddle/fluid/lite/model_parser/model_parser.h | 5 +++++ 3 files changed, 12 insertions(+) diff --git a/paddle/fluid/lite/core/tensor.h b/paddle/fluid/lite/core/tensor.h index 62e4301fa..15a2ba3ae 100644 --- a/paddle/fluid/lite/core/tensor.h +++ b/paddle/fluid/lite/core/tensor.h @@ -15,6 +15,7 @@ #pragma once #include #include +#include #include "memory.h" namespace paddle { diff --git a/paddle/fluid/lite/model_parser/model_parser.cc b/paddle/fluid/lite/model_parser/model_parser.cc index 9b5e676fa..fb3b1e9ac 100644 --- a/paddle/fluid/lite/model_parser/model_parser.cc +++ b/paddle/fluid/lite/model_parser/model_parser.cc @@ -132,6 +132,12 @@ std::unique_ptr LoadProgram( void LoadParams(const std::string &path) {} +// Load directly to CPU, and latter transfer to other devices. +void LoadParam(const std::string &path, Variable *out) { + std::ifstream fin(path, std::ios::binary); + LoadLoDTensor(fin, out); +} + void LoadModel(const std::string &model_dir, Scope *scope) { const std::string prog_path = model_dir + "/__model__"; auto prog = LoadProgram(prog_path); diff --git a/paddle/fluid/lite/model_parser/model_parser.h b/paddle/fluid/lite/model_parser/model_parser.h index f65edabb3..358bb9a1a 100644 --- a/paddle/fluid/lite/model_parser/model_parser.h +++ b/paddle/fluid/lite/model_parser/model_parser.h @@ -19,6 +19,8 @@ #include #include #include "paddle/fluid/framework/framework.pb.h" +#include "paddle/fluid/lite/core/tensor.h" +#include "paddle/fluid/lite/core/variable.h" namespace paddle { namespace lite { @@ -30,6 +32,9 @@ std::unique_ptr LoadProgram( // Read a single file containing all the parameters. void LoadParams(const std::string& path); +// Load a single parameter to an output tensor. +void LoadParam(const std::string& path, Variable* out); + // Read a model and files of parameters. void LoadModel(const std::string& model_dir); -- GitLab