开发者您好,请参考如下代码获取yolov3的结果数据:
std::vector<std::vector<std::vector<float>>> GetResults(const float *bbox_data,
const int *bbox_num_data,
int batch_size) {
std::vector<std::vector<std::vector<float>>> detections;
const float max_limit = 1.0; // maximum coordinate value
const float min_limit = 0.0; // minimum coordinate value
const size_t max_bbox = 2048; // the maximum number of bboxes per image
const size_t per_bbox_info_count = 7; // batchid, classid, score, x, y, w, h
size_t count = max_bbox * per_bbox_info_count;
for (size_t i = 0; i < batch_size; ++i) {
auto num_boxes = bbox_num_data[i];
std::vector<std::vector<float>> batch_box;
for (size_t k = 0; k < num_boxes; ++k) {
auto index = i * count + k * per_bbox_info_count;
std::vector<float> single_box;
auto bl = std::max(min_limit, std::min(max_limit, bbox_data[index + 3])); // x1
auto br = std::max(min_limit, std::min(max_limit, bbox_data[index + 5])); // x2
auto bt = std::max(min_limit, std::min(max_limit, bbox_data[index + 4])); // y1
auto bb = std::max(min_limit, std::min(max_limit, bbox_data[index + 6])); // y2
single_box.push_back(bl);
single_box.push_back(bt);
single_box.push_back(br);
single_box.push_back(bb);
single_box.push_back(bbox_data[index + 2]);
single_box.push_back(bbox_data[index + 1]);
if ((br - bl) > 0 && (bb - bt) > 0) {
batch_box.push_back(single_box);
}
}
detections.push_back(batch_box);
}
return detections;
}