pybind_general_model.cpp 2.3 KB
Newer Older
B
barrierye 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

G
guru4elephant 已提交
15
#include <pybind11/pybind11.h>
B
barrierye 已提交
16
#include "general_model.h"  // NOLINT
G
guru4elephant 已提交
17

B
barrierye 已提交
18
#include <pybind11/stl.h>  // NOLINT
G
guru4elephant 已提交
19 20 21

namespace py = pybind11;

G
guru4elephant 已提交
22 23
using baidu::paddle_serving::general_model::FetchedMap;

G
guru4elephant 已提交
24 25 26 27 28 29 30 31 32 33
namespace baidu {
namespace paddle_serving {
namespace general_model {

PYBIND11_MODULE(paddle_serving_client, m) {
  m.doc() = R"pddoc(this is a practice
       )pddoc";
  py::class_<PredictorClient>(m, "PredictorClient", py::buffer_protocol())
      .def(py::init())
      .def("init",
B
barrierye 已提交
34
           [](PredictorClient &self, const std::string &conf) {
G
guru4elephant 已提交
35 36
             self.init(conf);
           })
G
guru4elephant 已提交
37
      .def("set_predictor_conf",
B
barrierye 已提交
38 39 40
           [](PredictorClient &self,
              const std::string &conf_path,
              const std::string &conf_file) {
G
guru4elephant 已提交
41 42 43
             self.set_predictor_conf(conf_path, conf_file);
           })
      .def("create_predictor",
B
barrierye 已提交
44
           [](PredictorClient &self) { self.create_predictor(); })
G
guru4elephant 已提交
45 46
      .def("predict",
           [](PredictorClient &self,
B
barrierye 已提交
47 48 49 50 51 52 53 54 55 56 57
              const std::vector<std::vector<float>> &float_feed,
              const std::vector<std::string> &float_feed_name,
              const std::vector<std::vector<int64_t>> &int_feed,
              const std::vector<std::string> &int_feed_name,
              const std::vector<std::string> &fetch_name,
              FetchedMap *fetch_result) {
             return self.predict(float_feed,
                                 float_feed_name,
                                 int_feed,
                                 int_feed_name,
                                 fetch_name,
G
guru4elephant 已提交
58
                                 fetch_result);
G
guru4elephant 已提交
59 60 61 62 63 64
           });
}

}  // namespace general_model
}  // namespace paddle_serving
}  // namespace baidu