MCPcopy Create free account
hub / github.com/Tencent/embedx / Predict

Method Predict

src/tools/model_server.cc:91–114  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89}
90
91bool 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
116bool ModelServer::Predict(const features_t& features,
117 std::vector<float>* probs) const {

Callers 5

PredictBatchMethod · 0.45
BatchPredictMethod · 0.45
PredictUserEmbeddingMethod · 0.45

Calls 3

EmplaceRowFunction · 0.85
InitMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected