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

Function extract_res

tools/cpp_examples/demo-client/src/ximage_press.cpp:103–135  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

101}
102
103void extract_res(const Request& req, const Response& res) {
104 uint32_t sample_size = res.predictions_size();
105 std::string err_string;
106 for (uint32_t si = 0; si < sample_size; ++si) {
107 DensePrediction json_msg;
108 std::string json = res.predictions(si).response_json();
109 butil::IOBuf buf;
110 buf.clear();
111 buf.append(json);
112 butil::IOBufAsZeroCopyInputStream wrapper(buf);
113 if (!JsonToProtoMessage(&wrapper, &json_msg, &err_string)) {
114 LOG(ERROR) << "Failed parse json from str:" << json;
115 return;
116 }
117
118 uint32_t csize = json_msg.categories_size();
119 if (csize <= 0) {
120 LOG(ERROR) << "sample-" << si << "has no"
121 << "categories props";
122 continue;
123 }
124 float max_prop = json_msg.categories(0);
125 uint32_t max_idx = 0;
126 for (uint32_t ci = 1; ci < csize; ++ci) {
127 if (json_msg.categories(ci) > max_prop) {
128 max_prop = json_msg.categories(ci);
129 max_idx = ci;
130 }
131 }
132
133 LOG(INFO) << "instance " << si << "has class " << max_idx;
134 } // end for
135}
136
137void thread_worker(PredictorApi* api, int thread_id) {
138 Request req;

Callers 1

thread_workerFunction · 0.70

Calls 2

appendMethod · 0.80
clearMethod · 0.45

Tested by

no test coverage detected