| 80 | } |
| 81 | |
| 82 | void PredictorClient::predict(const std::vector<std::vector<float>> &float_feed, |
| 83 | const std::vector<std::string> &float_feed_name, |
| 84 | const std::vector<std::vector<int64_t>> &int_feed, |
| 85 | const std::vector<std::string> &int_feed_name, |
| 86 | const std::vector<std::string> &fetch_name, |
| 87 | FetchedMap *fetch_result) { |
| 88 | _api.thrd_clear(); |
| 89 | _predictor = _api.fetch_predictor("general_model"); |
| 90 | Request req; |
| 91 | std::vector<Tensor *> tensor_vec; |
| 92 | FeedInst *inst = req.add_insts(); |
| 93 | for (auto &name : float_feed_name) { |
| 94 | tensor_vec.push_back(inst->add_tensor_array()); |
| 95 | } |
| 96 | |
| 97 | for (auto &name : int_feed_name) { |
| 98 | tensor_vec.push_back(inst->add_tensor_array()); |
| 99 | } |
| 100 | |
| 101 | int vec_idx = 0; |
| 102 | for (auto &name : float_feed_name) { |
| 103 | int idx = _feed_name_to_idx[name]; |
| 104 | Tensor *tensor = tensor_vec[idx]; |
| 105 | for (int j = 0; j < _shape[idx].size(); ++j) { |
| 106 | tensor->add_shape(_shape[idx][j]); |
| 107 | } |
| 108 | tensor->set_elem_type(1); |
| 109 | for (int j = 0; j < float_feed[vec_idx].size(); ++j) { |
| 110 | tensor->add_data((char *)(&(float_feed[vec_idx][j])), // NOLINT |
| 111 | sizeof(float)); |
| 112 | } |
| 113 | vec_idx++; |
| 114 | } |
| 115 | |
| 116 | vec_idx = 0; |
| 117 | for (auto &name : int_feed_name) { |
| 118 | int idx = _feed_name_to_idx[name]; |
| 119 | Tensor *tensor = tensor_vec[idx]; |
| 120 | for (int j = 0; j < _shape[idx].size(); ++j) { |
| 121 | tensor->add_shape(_shape[idx][j]); |
| 122 | } |
| 123 | tensor->set_elem_type(0); |
| 124 | for (int j = 0; j < int_feed[vec_idx].size(); ++j) { |
| 125 | tensor->add_data((char *)(&(int_feed[vec_idx][j])), // NOLINT |
| 126 | sizeof(int64_t)); |
| 127 | } |
| 128 | vec_idx++; |
| 129 | } |
| 130 | |
| 131 | // std::map<std::string, std::vector<float> > result; |
| 132 | Response res; |
| 133 | |
| 134 | res.Clear(); |
| 135 | if (_predictor->inference(&req, &res) != 0) { |
| 136 | LOG(ERROR) << "failed call predictor with req: " << req.ShortDebugString(); |
| 137 | exit(-1); |
| 138 | } else { |
| 139 | for (auto &name : fetch_name) { |
no test coverage detected