MCPcopy Create free account
hub / github.com/PaddlePaddle/Serving / ParseProto

Method ParseProto

core/general-client/src/client.cpp:369–445  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

367}
368
369int PredictorOutputs::ParseProto(const Response& res,
370 const std::vector<std::string>& fetch_name,
371 std::map<std::string, int>& fetch_name_to_type,
372 PredictorOutputs& outputs) {
373 VLOG(2) << "get model output num";
374 uint32_t model_num = res.outputs_size();
375 VLOG(2) << "model num: " << model_num;
376 for (uint32_t m_idx = 0; m_idx < model_num; ++m_idx) {
377 VLOG(2) << "process model output index: " << m_idx;
378 auto& output = res.outputs(m_idx);
379 std::shared_ptr<PredictorOutputs::PredictorOutput> predictor_output =
380 std::make_shared<PredictorOutputs::PredictorOutput>();
381 predictor_output->engine_name = output.engine_name();
382
383 PredictorData& predictor_data = predictor_output->data;
384 std::map<std::string, std::vector<float>>& float_data_map = *predictor_output->data.mutable_float_data_map();
385 std::map<std::string, std::vector<int64_t>>& int64_data_map = *predictor_output->data.mutable_int64_data_map();
386 std::map<std::string, std::vector<int32_t>>& int32_data_map = *predictor_output->data.mutable_int_data_map();
387 std::map<std::string, std::string>& string_data_map = *predictor_output->data.mutable_string_data_map();
388 std::map<std::string, std::vector<int>>& shape_map = *predictor_output->data.mutable_shape_map();
389 std::map<std::string, std::vector<int>>& lod_map = *predictor_output->data.mutable_lod_map();
390
391 int idx = 0;
392 for (auto &name : fetch_name) {
393 // int idx = _fetch_name_to_idx[name];
394 int shape_size = output.tensor(idx).shape_size();
395 VLOG(2) << "fetch var " << name << " index " << idx << " shape size "
396 << shape_size;
397 shape_map[name].resize(shape_size);
398 for (int i = 0; i < shape_size; ++i) {
399 shape_map[name][i] = output.tensor(idx).shape(i);
400 }
401 int lod_size = output.tensor(idx).lod_size();
402 if (lod_size > 0) {
403 lod_map[name].resize(lod_size);
404 for (int i = 0; i < lod_size; ++i) {
405 lod_map[name][i] = output.tensor(idx).lod(i);
406 }
407 }
408 idx += 1;
409 }
410 idx = 0;
411
412 for (auto &name : fetch_name) {
413 // int idx = _fetch_name_to_idx[name];
414 if (fetch_name_to_type[name] == P_INT64) {
415 VLOG(2) << "fetch var " << name << "type int64";
416 int size = output.tensor(idx).int64_data_size();
417 int64_data_map[name] = std::vector<int64_t>(
418 output.tensor(idx).int64_data().begin(),
419 output.tensor(idx).int64_data().begin() + size);
420 } else if (fetch_name_to_type[name] == P_FLOAT32) {
421 VLOG(2) << "fetch var " << name << "type float";
422 int size = output.tensor(idx).float_data_size();
423 float_data_map[name] = std::vector<float>(
424 output.tensor(idx).float_data().begin(),
425 output.tensor(idx).float_data().begin() + size);
426 } else if (fetch_name_to_type[name] == P_INT32) {

Callers

nothing calls this directly

Calls 10

mutable_int_data_mapMethod · 0.80
mutable_shape_mapMethod · 0.80
mutable_lod_mapMethod · 0.80
beginMethod · 0.80
set_datatypeMethod · 0.80
add_dataMethod · 0.80
resizeMethod · 0.45

Tested by

no test coverage detected