mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-28 10:51:39 +08:00
[Benchmark]Compare diff for OCR (#1415)
* avoid mem copy for cpp benchmark * set CMAKE_BUILD_TYPE to Release * Add SegmentationDiff * change pointer to reference * fixed bug * cast uint8 to int32 * Add diff compare for OCR * Add diff compare for OCR * rm ppocr pipeline * Add yolov5 diff compare * Add yolov5 diff compare * deal with comments * deal with comments * fixed bug * fixed bug
This commit is contained in:
73
fastdeploy/benchmark/utils.cc
Normal file → Executable file
73
fastdeploy/benchmark/utils.cc
Normal file → Executable file
@@ -474,6 +474,34 @@ bool ResultManager::SaveSegmentationResult(
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ResultManager::SaveOCRDetResult(const std::vector<std::array<int, 8>>& res,
|
||||
const std::string& path) {
|
||||
if (res.empty()) {
|
||||
FDERROR << "OCRDetResult can not be empty!" << std::endl;
|
||||
return false;
|
||||
}
|
||||
std::ofstream fs(path, std::ios::out);
|
||||
if (!fs.is_open()) {
|
||||
FDERROR << "Fail to open file:" << path << std::endl;
|
||||
return false;
|
||||
}
|
||||
fs.precision(20);
|
||||
// boxes
|
||||
fs << "boxes" << KEY_VALUE_SEP;
|
||||
for (int i = 0; i < res.size(); ++i) {
|
||||
for (int j = 0; j < 8; ++j) {
|
||||
if ((i == res.size() - 1) && (j == 7)) {
|
||||
fs << res[i][j];
|
||||
} else {
|
||||
fs << res[i][j] << VALUE_SEP;
|
||||
}
|
||||
}
|
||||
}
|
||||
fs << "\n";
|
||||
fs.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ResultManager::LoadDetectionResult(vision::DetectionResult* res,
|
||||
const std::string& path) {
|
||||
if (!CheckFileExists(path)) {
|
||||
@@ -556,6 +584,26 @@ bool ResultManager::LoadSegmentationResult(vision::SegmentationResult* res,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ResultManager::LoadOCRDetResult(std::vector<std::array<int, 8>>* res,
|
||||
const std::string& path) {
|
||||
if (!CheckFileExists(path)) {
|
||||
FDERROR << "Can't found file from" << path << std::endl;
|
||||
return false;
|
||||
}
|
||||
auto lines = ReadLines(path);
|
||||
std::map<std::string, std::vector<std::string>> data;
|
||||
// boxes
|
||||
data = SplitDataLine(lines[0]);
|
||||
int boxes_num = data.begin()->second.size() / 8;
|
||||
res->resize(boxes_num);
|
||||
for (int i = 0; i < boxes_num; ++i) {
|
||||
for (int j = 0; j < 8; ++j) {
|
||||
(*res)[i][j] = std::stoi(data.begin()->second[i * 8 + j]);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
DetectionDiff ResultManager::CalculateDiffStatis(
|
||||
const vision::DetectionResult& lhs, const vision::DetectionResult& rhs,
|
||||
const float& score_threshold) {
|
||||
@@ -643,6 +691,31 @@ SegmentationDiff ResultManager::CalculateDiffStatis(
|
||||
return diff;
|
||||
}
|
||||
|
||||
OCRDetDiff ResultManager::CalculateDiffStatis(
|
||||
const std::vector<std::array<int, 8>>& lhs,
|
||||
const std::vector<std::array<int, 8>>& rhs) {
|
||||
const int boxes_nums = std::min(lhs.size(), rhs.size());
|
||||
std::vector<std::array<int, 8>> lhs_sort = lhs;
|
||||
std::vector<std::array<int, 8>> rhs_sort = rhs;
|
||||
// lex sort by x(w) & y(h)
|
||||
vision::utils::LexSortOCRDetResultByXY(&lhs_sort);
|
||||
vision::utils::LexSortOCRDetResultByXY(&rhs_sort);
|
||||
// get value diff
|
||||
const int boxes_num = std::min(lhs_sort.size(), rhs_sort.size());
|
||||
std::vector<float> boxes_diff;
|
||||
for (int i = 0; i < boxes_num; ++i) {
|
||||
for (int j = 0; j < 8; ++j) {
|
||||
boxes_diff.push_back(lhs_sort[i][j] - rhs_sort[i][j]);
|
||||
}
|
||||
}
|
||||
|
||||
OCRDetDiff diff;
|
||||
CalculateStatisInfo<float>(boxes_diff.data(), boxes_diff.size(),
|
||||
&(diff.boxes.mean), &(diff.boxes.max),
|
||||
&(diff.boxes.min));
|
||||
return diff;
|
||||
}
|
||||
|
||||
#endif // ENABLE_VISION
|
||||
#endif // ENABLE_BENCHMARK
|
||||
|
||||
|
||||
Reference in New Issue
Block a user