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

Method BatchPredict

src/tools/model_server.cc:148–183  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

146}
147
148bool 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
185bool ModelServer::BatchPredict(
186 const std::vector<features_t>& batch_features,

Callers

nothing calls this directly

Calls 4

EmplaceRowFunction · 0.85
InitMethod · 0.45
PredictMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected