| 89 | } |
| 90 | |
| 91 | bool ModelServer::Predict(const features_t& features, float* prob) const { |
| 92 | if (!graph_ || !model_) { |
| 93 | return false; |
| 94 | } |
| 95 | |
| 96 | OpContext op_context; |
| 97 | op_context.Init(graph_.get(), model_->mutable_param()); |
| 98 | if (!op_context.InitOp({target_name_}, -1)) { |
| 99 | return false; |
| 100 | } |
| 101 | |
| 102 | Instance* inst = op_context.mutable_inst(); |
| 103 | auto& X = inst->insert<csr_t>(deepx_core::X_NAME); |
| 104 | EmplaceRow(features, &X); |
| 105 | inst->set_batch(X.row()); |
| 106 | |
| 107 | op_context.InitPredict(); |
| 108 | op_context.Predict(); |
| 109 | const auto& P = op_context.hidden().get<tsr_t>(target_name_); |
| 110 | DXASSERT(P.is_rank(2)); |
| 111 | DXASSERT(P.same_shape(X.row(), 1)); |
| 112 | *prob = (float)P.data(0); |
| 113 | return true; |
| 114 | } |
| 115 | |
| 116 | bool ModelServer::Predict(const features_t& features, |
| 117 | std::vector<float>* probs) const { |
no test coverage detected