mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-12-24 13:28:13 +08:00
Delete redundant Chinese comments (#275)
This commit is contained in:
@@ -27,8 +27,8 @@ Classifier::Classifier(const std::string& model_file,
|
||||
const ModelFormat& model_format) {
|
||||
if (model_format == ModelFormat::ONNX) {
|
||||
valid_cpu_backends = {Backend::ORT,
|
||||
Backend::OPENVINO}; // 指定可用的CPU后端
|
||||
valid_gpu_backends = {Backend::ORT, Backend::TRT}; // 指定可用的GPU后端
|
||||
Backend::OPENVINO};
|
||||
valid_gpu_backends = {Backend::ORT, Backend::TRT};
|
||||
} else {
|
||||
valid_cpu_backends = {Backend::PDINFER, Backend::ORT, Backend::OPENVINO};
|
||||
valid_gpu_backends = {Backend::PDINFER, Backend::ORT, Backend::TRT};
|
||||
@@ -81,7 +81,6 @@ void OcrClassifierResizeImage(Mat* mat,
|
||||
}
|
||||
}
|
||||
|
||||
//预处理
|
||||
bool Classifier::Preprocess(Mat* mat, FDTensor* output) {
|
||||
// 1. cls resizes
|
||||
// 2. normalize
|
||||
@@ -99,7 +98,6 @@ bool Classifier::Preprocess(Mat* mat, FDTensor* output) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//后处理
|
||||
bool Classifier::Postprocess(FDTensor& infer_result,
|
||||
std::tuple<int, float>* cls_result) {
|
||||
std::vector<int64_t> output_shape = infer_result.shape;
|
||||
@@ -119,7 +117,6 @@ bool Classifier::Postprocess(FDTensor& infer_result,
|
||||
return true;
|
||||
}
|
||||
|
||||
//预测
|
||||
bool Classifier::Predict(cv::Mat* img, std::tuple<int, float>* cls_result) {
|
||||
Mat mat(*img);
|
||||
std::vector<FDTensor> input_tensors(1);
|
||||
|
||||
@@ -25,16 +25,12 @@ namespace ocr {
|
||||
class FASTDEPLOY_DECL Classifier : public FastDeployModel {
|
||||
public:
|
||||
Classifier();
|
||||
// 当model_format为ONNX时,无需指定params_file
|
||||
// 当model_format为Paddle时,则需同时指定model_file & params_file
|
||||
Classifier(const std::string& model_file, const std::string& params_file = "",
|
||||
const RuntimeOption& custom_option = RuntimeOption(),
|
||||
const ModelFormat& model_format = ModelFormat::PADDLE);
|
||||
|
||||
// 定义模型的名称
|
||||
std::string ModelName() const { return "ppocr/ocr_cls"; }
|
||||
|
||||
// 模型预测接口,即用户调用的接口
|
||||
virtual bool Predict(cv::Mat* img, std::tuple<int, float>* result);
|
||||
|
||||
// pre & post parameters
|
||||
@@ -47,15 +43,10 @@ class FASTDEPLOY_DECL Classifier : public FastDeployModel {
|
||||
bool is_scale;
|
||||
|
||||
private:
|
||||
// 初始化函数,包括初始化后端,以及其它模型推理需要涉及的操作
|
||||
bool Initialize();
|
||||
|
||||
// 输入图像预处理操作
|
||||
// FDTensor为预处理后的Tensor数据,传给后端进行推理
|
||||
bool Preprocess(Mat* img, FDTensor* output);
|
||||
|
||||
// 后端推理结果后处理,输出给用户
|
||||
// infer_result 为后端推理后的输出Tensor
|
||||
bool Postprocess(FDTensor& infer_result, std::tuple<int, float>* result);
|
||||
};
|
||||
|
||||
|
||||
@@ -27,8 +27,8 @@ DBDetector::DBDetector(const std::string& model_file,
|
||||
const ModelFormat& model_format) {
|
||||
if (model_format == ModelFormat::ONNX) {
|
||||
valid_cpu_backends = {Backend::ORT,
|
||||
Backend::OPENVINO}; // 指定可用的CPU后端
|
||||
valid_gpu_backends = {Backend::ORT, Backend::TRT}; // 指定可用的GPU后端
|
||||
Backend::OPENVINO};
|
||||
valid_gpu_backends = {Backend::ORT, Backend::TRT};
|
||||
} else {
|
||||
valid_cpu_backends = {Backend::PDINFER, Backend::ORT, Backend::OPENVINO};
|
||||
valid_gpu_backends = {Backend::PDINFER, Backend::ORT, Backend::TRT};
|
||||
@@ -91,7 +91,6 @@ void OcrDetectorResizeImage(Mat* img, int max_size_len, float* ratio_h,
|
||||
*ratio_w = float(resize_w) / float(w);
|
||||
}
|
||||
|
||||
//预处理
|
||||
bool DBDetector::Preprocess(
|
||||
Mat* mat, FDTensor* output,
|
||||
std::map<std::string, std::array<float, 2>>* im_info) {
|
||||
@@ -111,7 +110,6 @@ bool DBDetector::Preprocess(
|
||||
return true;
|
||||
}
|
||||
|
||||
//后处理
|
||||
bool DBDetector::Postprocess(
|
||||
FDTensor& infer_result, std::vector<std::array<int, 8>>* boxes_result,
|
||||
const std::map<std::string, std::array<float, 2>>& im_info) {
|
||||
@@ -166,7 +164,6 @@ bool DBDetector::Postprocess(
|
||||
return true;
|
||||
}
|
||||
|
||||
//预测
|
||||
bool DBDetector::Predict(cv::Mat* img,
|
||||
std::vector<std::array<int, 8>>* boxes_result) {
|
||||
Mat mat(*img);
|
||||
|
||||
@@ -30,10 +30,8 @@ class FASTDEPLOY_DECL DBDetector : public FastDeployModel {
|
||||
const RuntimeOption& custom_option = RuntimeOption(),
|
||||
const ModelFormat& model_format = ModelFormat::PADDLE);
|
||||
|
||||
// 定义模型的名称
|
||||
std::string ModelName() const { return "ppocr/ocr_det"; }
|
||||
|
||||
// 模型预测接口,即用户调用的接口
|
||||
virtual bool Predict(cv::Mat* im,
|
||||
std::vector<std::array<int, 8>>* boxes_result);
|
||||
|
||||
@@ -54,20 +52,15 @@ class FASTDEPLOY_DECL DBDetector : public FastDeployModel {
|
||||
bool is_scale;
|
||||
|
||||
private:
|
||||
// 初始化函数,包括初始化后端,以及其它模型推理需要涉及的操作
|
||||
bool Initialize();
|
||||
|
||||
// FDTensor为预处理后的Tensor数据,传给后端进行推理
|
||||
// im_info为预处理过程保存的数据,在后处理中需要用到
|
||||
bool Preprocess(Mat* mat, FDTensor* outputs,
|
||||
std::map<std::string, std::array<float, 2>>* im_info);
|
||||
|
||||
// 后端推理结果后处理,输出给用户
|
||||
bool Postprocess(FDTensor& infer_result,
|
||||
std::vector<std::array<int, 8>>* boxes_result,
|
||||
const std::map<std::string, std::array<float, 2>>& im_info);
|
||||
|
||||
// OCR后处理类
|
||||
PostProcessor post_processor_;
|
||||
};
|
||||
|
||||
|
||||
@@ -45,8 +45,8 @@ Recognizer::Recognizer(const std::string& model_file,
|
||||
const ModelFormat& model_format) {
|
||||
if (model_format == ModelFormat::ONNX) {
|
||||
valid_cpu_backends = {Backend::ORT,
|
||||
Backend::OPENVINO}; // 指定可用的CPU后端
|
||||
valid_gpu_backends = {Backend::ORT, Backend::TRT}; // 指定可用的GPU后端
|
||||
Backend::OPENVINO};
|
||||
valid_gpu_backends = {Backend::ORT, Backend::TRT};
|
||||
} else {
|
||||
valid_cpu_backends = {Backend::PDINFER, Backend::ORT, Backend::OPENVINO};
|
||||
valid_gpu_backends = {Backend::PDINFER, Backend::ORT, Backend::TRT};
|
||||
@@ -56,7 +56,6 @@ Recognizer::Recognizer(const std::string& model_file,
|
||||
runtime_option.model_format = model_format;
|
||||
runtime_option.model_file = model_file;
|
||||
runtime_option.params_file = params_file;
|
||||
// Recognizer在使用CPU推理,并把PaddleInference作为推理后端时,需要删除以下2个pass//
|
||||
runtime_option.DeletePaddleBackendPass("matmul_transpose_reshape_fuse_pass");
|
||||
runtime_option.DeletePaddleBackendPass(
|
||||
"matmul_transpose_reshape_mkldnn_fuse_pass");
|
||||
@@ -111,7 +110,6 @@ void OcrRecognizerResizeImage(Mat* mat, const float& wh_ratio,
|
||||
Pad::Run(mat, 0, 0, 0, int(imgW - mat->Width()), value);
|
||||
}
|
||||
|
||||
//预处理
|
||||
bool Recognizer::Preprocess(Mat* mat, FDTensor* output,
|
||||
const std::vector<int>& rec_image_shape) {
|
||||
int imgH = rec_image_shape[1];
|
||||
@@ -134,7 +132,6 @@ bool Recognizer::Preprocess(Mat* mat, FDTensor* output,
|
||||
return true;
|
||||
}
|
||||
|
||||
//后处理
|
||||
bool Recognizer::Postprocess(FDTensor& infer_result,
|
||||
std::tuple<std::string, float>* rec_result) {
|
||||
std::vector<int64_t> output_shape = infer_result.shape;
|
||||
@@ -174,7 +171,6 @@ bool Recognizer::Postprocess(FDTensor& infer_result,
|
||||
return true;
|
||||
}
|
||||
|
||||
//预测
|
||||
bool Recognizer::Predict(cv::Mat* img,
|
||||
std::tuple<std::string, float>* rec_result) {
|
||||
Mat mat(*img);
|
||||
|
||||
@@ -25,17 +25,13 @@ namespace ocr {
|
||||
class FASTDEPLOY_DECL Recognizer : public FastDeployModel {
|
||||
public:
|
||||
Recognizer();
|
||||
// 当model_format为ONNX时,无需指定params_file
|
||||
// 当model_format为Paddle时,则需同时指定model_file & params_file
|
||||
Recognizer(const std::string& model_file, const std::string& params_file = "",
|
||||
const std::string& label_path = "",
|
||||
const RuntimeOption& custom_option = RuntimeOption(),
|
||||
const ModelFormat& model_format = ModelFormat::PADDLE);
|
||||
|
||||
// 定义模型的名称
|
||||
std::string ModelName() const { return "ppocr/ocr_rec"; }
|
||||
|
||||
// 模型预测接口,即用户调用的接口
|
||||
virtual bool Predict(cv::Mat* img,
|
||||
std::tuple<std::string, float>* rec_result);
|
||||
|
||||
@@ -51,15 +47,11 @@ class FASTDEPLOY_DECL Recognizer : public FastDeployModel {
|
||||
bool is_scale;
|
||||
|
||||
private:
|
||||
// 初始化函数,包括初始化后端,以及其它模型推理需要涉及的操作
|
||||
bool Initialize();
|
||||
|
||||
// 输入图像预处理操作
|
||||
bool Preprocess(Mat* img, FDTensor* outputs,
|
||||
const std::vector<int>& rec_image_shape);
|
||||
|
||||
// 后端推理结果后处理,输出给用户
|
||||
// infer_result 为后端推理后的输出Tensor
|
||||
bool Postprocess(FDTensor& infer_result,
|
||||
std::tuple<std::string, float>* rec_result);
|
||||
};
|
||||
|
||||
@@ -31,7 +31,6 @@ cv::Mat GetRotateCropImage(const cv::Mat& srcimage,
|
||||
tmp.push_back(box[2 * i + 1]);
|
||||
points.push_back(tmp);
|
||||
}
|
||||
// box转points
|
||||
int x_collect[4] = {box[0], box[2], box[4], box[6]};
|
||||
int y_collect[4] = {box[1], box[3], box[5], box[7]};
|
||||
int left = int(*std::min_element(x_collect, x_collect + 4));
|
||||
@@ -39,7 +38,6 @@ cv::Mat GetRotateCropImage(const cv::Mat& srcimage,
|
||||
int top = int(*std::min_element(y_collect, y_collect + 4));
|
||||
int bottom = int(*std::max_element(y_collect, y_collect + 4));
|
||||
|
||||
//得到rect矩形
|
||||
cv::Mat img_crop;
|
||||
image(cv::Rect(left, top, right - left, bottom - top)).copyTo(img_crop);
|
||||
|
||||
@@ -65,14 +63,12 @@ cv::Mat GetRotateCropImage(const cv::Mat& srcimage,
|
||||
pointsf[2] = cv::Point2f(points[2][0], points[2][1]);
|
||||
pointsf[3] = cv::Point2f(points[3][0], points[3][1]);
|
||||
|
||||
//透视变换矩阵
|
||||
cv::Mat M = cv::getPerspectiveTransform(pointsf, pts_std);
|
||||
|
||||
cv::Mat dst_img;
|
||||
cv::warpPerspective(img_crop, dst_img, M,
|
||||
cv::Size(img_crop_width, img_crop_height),
|
||||
cv::BORDER_REPLICATE);
|
||||
//完成透视变换
|
||||
|
||||
if (float(dst_img.rows) >= float(dst_img.cols) * 1.5) {
|
||||
cv::Mat srcCopy = cv::Mat(dst_img.rows, dst_img.cols, dst_img.depth());
|
||||
|
||||
@@ -20,7 +20,6 @@ namespace fastdeploy {
|
||||
namespace vision {
|
||||
namespace ocr {
|
||||
|
||||
//获取轮廓区域
|
||||
void PostProcessor::GetContourArea(const std::vector<std::vector<float>> &box,
|
||||
float unclip_ratio, float &distance) {
|
||||
int pts_num = 4;
|
||||
@@ -71,7 +70,6 @@ cv::RotatedRect PostProcessor::UnClip(std::vector<std::vector<float>> box,
|
||||
return res;
|
||||
}
|
||||
|
||||
//将图像的矩阵转换为float类型的array数组返回
|
||||
float **PostProcessor::Mat2Vec(cv::Mat mat) {
|
||||
auto **array = new float *[mat.rows];
|
||||
for (int i = 0; i < mat.rows; ++i) array[i] = new float[mat.cols];
|
||||
@@ -84,8 +82,6 @@ float **PostProcessor::Mat2Vec(cv::Mat mat) {
|
||||
return array;
|
||||
}
|
||||
|
||||
//对点进行顺时针方向的排序(从左到右,从上到下) (order points
|
||||
// clockwise[顺时针方向])
|
||||
std::vector<std::vector<int>> PostProcessor::OrderPointsClockwise(
|
||||
std::vector<std::vector<int>> pts) {
|
||||
std::vector<std::vector<int>> box = pts;
|
||||
@@ -103,7 +99,6 @@ std::vector<std::vector<int>> PostProcessor::OrderPointsClockwise(
|
||||
return rect;
|
||||
}
|
||||
|
||||
//将图像的矩阵转换为float类型的vector数组返回
|
||||
std::vector<std::vector<float>> PostProcessor::Mat2Vector(cv::Mat mat) {
|
||||
std::vector<std::vector<float>> img_vec;
|
||||
std::vector<float> tmp;
|
||||
@@ -118,7 +113,6 @@ std::vector<std::vector<float>> PostProcessor::Mat2Vector(cv::Mat mat) {
|
||||
return img_vec;
|
||||
}
|
||||
|
||||
//判断元素为浮点数float的vector的精度,如果a中元素的精度不等于b中元素的精度,则返回false
|
||||
bool PostProcessor::XsortFp32(std::vector<float> a, std::vector<float> b) {
|
||||
if (a[0] != b[0]) return a[0] < b[0];
|
||||
return false;
|
||||
@@ -248,8 +242,6 @@ float PostProcessor::BoxScoreFast(std::vector<std::vector<float>> box_array,
|
||||
return score;
|
||||
}
|
||||
|
||||
//这个应该是DB(差分二值化)相关的内容,方法从 Bitmap 图中获取检测框
|
||||
//涉及到box_thresh(低于这个阈值的boxs不予显示)和det_db_unclip_ratio(文本框扩张的系数,关系到文本框的大小)
|
||||
std::vector<std::vector<std::vector<int>>> PostProcessor::BoxesFromBitmap(
|
||||
const cv::Mat pred, const cv::Mat bitmap, const float &box_thresh,
|
||||
const float &det_db_unclip_ratio, const std::string &det_db_score_mode) {
|
||||
|
||||
Reference in New Issue
Block a user