| 146 | } |
| 147 | |
| 148 | bool ModelServer::BatchPredict(const std::vector<features_t>& batch_features, |
| 149 | std::vector<float>* batch_prob) const { |
| 150 | if (batch_features.empty()) { |
| 151 | return false; |
| 152 | } |
| 153 | |
| 154 | if (!graph_ || !model_) { |
| 155 | return false; |
| 156 | } |
| 157 | |
| 158 | OpContext op_context; |
| 159 | op_context.Init(graph_.get(), model_->mutable_param()); |
| 160 | if (!op_context.InitOp({target_name_}, -1)) { |
| 161 | return false; |
| 162 | } |
| 163 | |
| 164 | Instance* inst = op_context.mutable_inst(); |
| 165 | auto& X = inst->insert<csr_t>(deepx_core::X_NAME); |
| 166 | for (const auto& features : batch_features) { |
| 167 | EmplaceRow(features, &X); |
| 168 | } |
| 169 | inst->set_batch(X.row()); |
| 170 | |
| 171 | op_context.InitPredict(); |
| 172 | op_context.Predict(); |
| 173 | const auto& P = op_context.hidden().get<tsr_t>(target_name_); |
| 174 | DXASSERT(P.is_rank(2)); |
| 175 | DXASSERT(P.same_shape(X.row(), 1)); |
| 176 | batch_prob->resize(X.row()); |
| 177 | const float_t* _P = P.data(); |
| 178 | for (int i = 0; i < X.row(); ++i) { |
| 179 | (*batch_prob)[i] = (float)*_P; |
| 180 | ++_P; |
| 181 | } |
| 182 | return true; |
| 183 | } |
| 184 | |
| 185 | bool ModelServer::BatchPredict( |
| 186 | const std::vector<features_t>& batch_features, |
nothing calls this directly
no test coverage detected