Improve ALPR_OCR peformance
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <chrono>
|
||||
|
||||
namespace ANSCENTER {
|
||||
namespace onnxocr {
|
||||
@@ -15,6 +16,12 @@ ONNXOCRDetector::ONNXOCRDetector(const std::string& onnx_path, unsigned int num_
|
||||
: BasicOrtHandler(onnx_path, num_threads) {
|
||||
}
|
||||
|
||||
ONNXOCRDetector::ONNXOCRDetector(const std::string& onnx_path,
|
||||
const OrtHandlerOptions& options,
|
||||
unsigned int num_threads)
|
||||
: BasicOrtHandler(onnx_path, options, num_threads) {
|
||||
}
|
||||
|
||||
Ort::Value ONNXOCRDetector::transform(const cv::Mat& mat) {
|
||||
// Not used directly - detection uses custom Preprocess + manual tensor creation
|
||||
// Provided to satisfy BasicOrtHandler pure virtual
|
||||
@@ -308,5 +315,41 @@ std::vector<cv::Point2f> ONNXOCRDetector::UnclipPolygon(const std::array<cv::Poi
|
||||
return result;
|
||||
}
|
||||
|
||||
void ONNXOCRDetector::Warmup() {
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
if (_warmedUp || !ort_session) return;
|
||||
|
||||
// 320x320 covers the typical license-plate ROI after LPD crop +
|
||||
// multiple-of-32 rounding. cuDNN caches the algorithm for this
|
||||
// shape so the first real inference doesn't pay the picker cost.
|
||||
constexpr int kWarmupSide = 320;
|
||||
try {
|
||||
cv::Mat dummy(kWarmupSide, kWarmupSide, CV_8UC3, cv::Scalar(128, 128, 128));
|
||||
cv::Mat dummyF;
|
||||
dummy.convertTo(dummyF, CV_32FC3);
|
||||
auto inputData = NormalizeAndPermute(dummyF);
|
||||
|
||||
std::array<int64_t, 4> inputShape = { 1, 3, kWarmupSide, kWarmupSide };
|
||||
Ort::Value inputTensor = Ort::Value::CreateTensor<float>(
|
||||
*memory_info_handler, inputData.data(), inputData.size(),
|
||||
inputShape.data(), inputShape.size());
|
||||
|
||||
auto t0 = std::chrono::high_resolution_clock::now();
|
||||
(void)ort_session->Run(
|
||||
Ort::RunOptions{ nullptr },
|
||||
input_node_names.data(), &inputTensor, 1,
|
||||
output_node_names.data(), num_outputs);
|
||||
auto t1 = std::chrono::high_resolution_clock::now();
|
||||
double ms = std::chrono::duration<double, std::milli>(t1 - t0).count();
|
||||
std::cout << "[ONNXOCRDetector] Warmup [1,3,"
|
||||
<< kWarmupSide << "," << kWarmupSide << "] "
|
||||
<< ms << " ms" << std::endl;
|
||||
}
|
||||
catch (const Ort::Exception& e) {
|
||||
std::cerr << "[ONNXOCRDetector] Warmup failed: " << e.what() << std::endl;
|
||||
}
|
||||
_warmedUp = true;
|
||||
}
|
||||
|
||||
} // namespace onnxocr
|
||||
} // namespace ANSCENTER
|
||||
|
||||
Reference in New Issue
Block a user