general_model.h 2.7 KB
Newer Older
G
guru4elephant 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
// Copyright (c) 2019 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.
#pragma once

#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

#include <fstream>
B
barrierye 已提交
21
#include <map>
G
guru4elephant 已提交
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
#include <string>
#include <vector>

#include "sdk-cpp/builtin_format.pb.h"
#include "sdk-cpp/general_model_service.pb.h"
#include "sdk-cpp/include/common.h"
#include "sdk-cpp/include/predictor_sdk.h"

using baidu::paddle_serving::sdk_cpp::Predictor;
using baidu::paddle_serving::sdk_cpp::PredictorApi;

// given some input data, pack into pb, and send request
namespace baidu {
namespace paddle_serving {
namespace general_model {

typedef std::map<std::string, std::vector<float>> FetchedMap;

class PredictorClient {
 public:
  PredictorClient() {}
  ~PredictorClient() {}

B
barrierye 已提交
45 46 47
  void init(const std::string& client_conf);
  void set_predictor_conf(const std::string& conf_path,
                          const std::string& conf_file);
G
guru4elephant 已提交
48 49
  int create_predictor();

B
barrierye 已提交
50 51 52 53 54 55
  void predict(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* result_map);
G
guru4elephant 已提交
56

B
barrierye 已提交
57 58 59 60 61 62
  void predict_with_profile(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* result_map);
G
guru4elephant 已提交
63 64 65

 private:
  PredictorApi _api;
B
barrierye 已提交
66
  Predictor* _predictor;
G
guru4elephant 已提交
67 68 69
  std::string _predictor_conf;
  std::string _predictor_path;
  std::string _conf_file;
G
guru4elephant 已提交
70 71
  std::map<std::string, int> _feed_name_to_idx;
  std::map<std::string, int> _fetch_name_to_idx;
G
guru4elephant 已提交
72
  std::map<std::string, std::string> _fetch_name_to_var_name;
B
barrierye 已提交
73
  std::vector<std::vector<int>> _shape;
G
guru4elephant 已提交
74 75 76 77 78 79 80
};

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

/* vim: set expandtab ts=4 sw=4 sts=4 tw=100: */