Skip to content

Commit

Permalink
Delete redundant Chinese comments (PaddlePaddle#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
DefTruth authored Sep 23, 2022
1 parent 5edd9fc commit efa7411
Show file tree
Hide file tree
Showing 50 changed files with 45 additions and 572 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ fastdeploy/pybind/main.cc
python/fastdeploy/libs/lib*
__pycache__
build_fastdeploy_android.sh
python/scripts/process_libraries.py
python/scripts/process_libraries.py
.vs
4 changes: 2 additions & 2 deletions fastdeploy/vision/detection/contrib/nanodet_plus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ NanoDetPlus::NanoDetPlus(const std::string& model_file,
const RuntimeOption& custom_option,
const ModelFormat& model_format) {
if (model_format == ModelFormat::ONNX) {
valid_cpu_backends = {Backend::ORT}; // 指定可用的CPU后端
valid_gpu_backends = {Backend::ORT, Backend::TRT}; // 指定可用的GPU后端
valid_cpu_backends = {Backend::ORT};
valid_gpu_backends = {Backend::ORT, Backend::TRT};
} else {
valid_cpu_backends = {Backend::PDINFER, Backend::ORT};
valid_gpu_backends = {Backend::PDINFER, Backend::ORT, Backend::TRT};
Expand Down
24 changes: 1 addition & 23 deletions fastdeploy/vision/detection/contrib/nanodet_plus.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,18 @@ namespace detection {

class FASTDEPLOY_DECL NanoDetPlus : public FastDeployModel {
public:
// 当model_format为ONNX时,无需指定params_file
// 当model_format为Paddle时,则需同时指定model_file & params_file
NanoDetPlus(const std::string& model_file,
const std::string& params_file = "",
const RuntimeOption& custom_option = RuntimeOption(),
const ModelFormat& model_format = ModelFormat::ONNX);

// 定义模型的名称
std::string ModelName() const { return "nanodet"; }

// 模型预测接口,即用户调用的接口
// im 为用户的输入数据,目前对于CV均定义为cv::Mat
// result 为模型预测的输出结构体
// conf_threshold 为后处理的参数
// nms_iou_threshold 为后处理的参数

virtual bool Predict(cv::Mat* im, DetectionResult* result,
float conf_threshold = 0.35f,
float nms_iou_threshold = 0.5f);

// 以下为模型在预测时的一些参数,基本是前后处理所需
// 用户在创建模型后,可根据模型的要求,以及自己的需求
// 对参数进行修改
// tuple of input size (width, height), e.g (320, 320)
std::vector<int> size;
// padding value, size should be same with Channels
Expand All @@ -64,27 +54,15 @@ class FASTDEPLOY_DECL NanoDetPlus : public FastDeployModel {
int reg_max;

private:
// 初始化函数,包括初始化后端,以及其它模型推理需要涉及的操作
bool Initialize();

// 输入图像预处理操作
// Mat为FastDeploy定义的数据结构
// FDTensor为预处理后的Tensor数据,传给后端进行推理
// im_info为预处理过程保存的数据,在后处理中需要用到
bool Preprocess(Mat* mat, FDTensor* output,
std::map<std::string, std::array<float, 2>>* im_info);

// 后端推理结果后处理,输出给用户
// infer_result 为后端推理后的输出Tensor
// result 为模型预测的结果
// im_info 为预处理记录的信息,后处理用于还原box
// conf_threshold 后处理时过滤box的置信度阈值
// nms_iou_threshold 后处理时NMS设定的iou阈值
bool Postprocess(FDTensor& infer_result, DetectionResult* result,
const std::map<std::string, std::array<float, 2>>& im_info,
float conf_threshold, float nms_iou_threshold);

// 查看输入是否为动态维度的 不建议直接使用 不同模型的逻辑可能不一致
bool IsDynamicInput() const { return is_dynamic_input_; }

// whether to inference with dynamic shape (e.g ONNX export with dynamic shape
Expand Down
4 changes: 2 additions & 2 deletions fastdeploy/vision/detection/contrib/scaledyolov4.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ ScaledYOLOv4::ScaledYOLOv4(const std::string& model_file,
const RuntimeOption& custom_option,
const ModelFormat& model_format) {
if (model_format == ModelFormat::ONNX) {
valid_cpu_backends = {Backend::ORT}; // 指定可用的CPU后端
valid_gpu_backends = {Backend::ORT, Backend::TRT}; // 指定可用的GPU后端
valid_cpu_backends = {Backend::ORT};
valid_gpu_backends = {Backend::ORT, Backend::TRT};
} else {
valid_cpu_backends = {Backend::PDINFER};
valid_gpu_backends = {Backend::PDINFER};
Expand Down
25 changes: 0 additions & 25 deletions fastdeploy/vision/detection/contrib/scaledyolov4.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,17 @@ namespace detection {

class FASTDEPLOY_DECL ScaledYOLOv4 : public FastDeployModel {
public:
// 当model_format为ONNX时,无需指定params_file
// 当model_format为Paddle时,则需同时指定model_file & params_file
ScaledYOLOv4(const std::string& model_file,
const std::string& params_file = "",
const RuntimeOption& custom_option = RuntimeOption(),
const ModelFormat& model_format = ModelFormat::ONNX);

// 定义模型的名称
virtual std::string ModelName() const { return "ScaledYOLOv4"; }

// 模型预测接口,即用户调用的接口
// im 为用户的输入数据,目前对于CV均定义为cv::Mat
// result 为模型预测的输出结构体
// conf_threshold 为后处理的参数
// nms_iou_threshold 为后处理的参数
virtual bool Predict(cv::Mat* im, DetectionResult* result,
float conf_threshold = 0.25,
float nms_iou_threshold = 0.5);

// 以下为模型在预测时的一些参数,基本是前后处理所需
// 用户在创建模型后,可根据模型的要求,以及自己的需求
// 对参数进行修改
// tuple of (width, height)
std::vector<int> size;
// padding value, size should be same with Channels
Expand All @@ -63,29 +52,15 @@ class FASTDEPLOY_DECL ScaledYOLOv4 : public FastDeployModel {
float max_wh;

private:
// 初始化函数,包括初始化后端,以及其它模型推理需要涉及的操作
bool Initialize();

// 输入图像预处理操作
// Mat为FastDeploy定义的数据结构
// FDTensor为预处理后的Tensor数据,传给后端进行推理
// im_info为预处理过程保存的数据,在后处理中需要用到
bool Preprocess(Mat* mat, FDTensor* output,
std::map<std::string, std::array<float, 2>>* im_info);

// 后端推理结果后处理,输出给用户
// infer_result 为后端推理后的输出Tensor
// result 为模型预测的结果
// im_info 为预处理记录的信息,后处理用于还原box
// conf_threshold 后处理时过滤box的置信度阈值
// nms_iou_threshold 后处理时NMS设定的iou阈值
bool Postprocess(FDTensor& infer_result, DetectionResult* result,
const std::map<std::string, std::array<float, 2>>& im_info,
float conf_threshold, float nms_iou_threshold);

// 对图片进行LetterBox处理
// mat 为读取到的原图
// size 为输入模型的图像尺寸
void LetterBox(Mat* mat, const std::vector<int>& size,
const std::vector<float>& color, bool _auto,
bool scale_fill = false, bool scale_up = true,
Expand Down
5 changes: 2 additions & 3 deletions fastdeploy/vision/detection/contrib/yolor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ YOLOR::YOLOR(const std::string& model_file, const std::string& params_file,
const RuntimeOption& custom_option,
const ModelFormat& model_format) {
if (model_format == ModelFormat::ONNX) {
valid_cpu_backends = {Backend::ORT}; // 指定可用的CPU后端
valid_gpu_backends = {Backend::ORT, Backend::TRT}; // 指定可用的GPU后端
valid_cpu_backends = {Backend::ORT};
valid_gpu_backends = {Backend::ORT, Backend::TRT};
} else {
valid_cpu_backends = {Backend::PDINFER};
valid_gpu_backends = {Backend::PDINFER};
Expand Down Expand Up @@ -192,7 +192,6 @@ bool YOLOR::Postprocess(
float pad_h = (out_h - ipt_h * scale) / 2.0f;
float pad_w = (out_w - ipt_w * scale) / 2.0f;
if (is_mini_pad) {
// 和 LetterBox中_auto=true的处理逻辑对应
pad_h = static_cast<float>(static_cast<int>(pad_h) % stride);
pad_w = static_cast<float>(static_cast<int>(pad_w) % stride);
}
Expand Down
27 changes: 1 addition & 26 deletions fastdeploy/vision/detection/contrib/yolor.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -23,27 +23,16 @@ namespace detection {

class FASTDEPLOY_DECL YOLOR : public FastDeployModel {
public:
// 当model_format为ONNX时,无需指定params_file
// 当model_format为Paddle时,则需同时指定model_file & params_file
YOLOR(const std::string& model_file, const std::string& params_file = "",
const RuntimeOption& custom_option = RuntimeOption(),
const ModelFormat& model_format = ModelFormat::ONNX);

// 定义模型的名称
virtual std::string ModelName() const { return "YOLOR"; }

// 模型预测接口,即用户调用的接口
// im 为用户的输入数据,目前对于CV均定义为cv::Mat
// result 为模型预测的输出结构体
// conf_threshold 为后处理的参数
// nms_iou_threshold 为后处理的参数
virtual bool Predict(cv::Mat* im, DetectionResult* result,
float conf_threshold = 0.25,
float nms_iou_threshold = 0.5);

// 以下为模型在预测时的一些参数,基本是前后处理所需
// 用户在创建模型后,可根据模型的要求,以及自己的需求
// 对参数进行修改
// tuple of (width, height)
std::vector<int> size;
// padding value, size should be same with Channels
Expand All @@ -62,29 +51,15 @@ class FASTDEPLOY_DECL YOLOR : public FastDeployModel {
float max_wh;

private:
// 初始化函数,包括初始化后端,以及其它模型推理需要涉及的操作
bool Initialize();

// 输入图像预处理操作
// Mat为FastDeploy定义的数据结构
// FDTensor为预处理后的Tensor数据,传给后端进行推理
// im_info为预处理过程保存的数据,在后处理中需要用到
bool Preprocess(Mat* mat, FDTensor* output,
std::map<std::string, std::array<float, 2>>* im_info);

// 后端推理结果后处理,输出给用户
// infer_result 为后端推理后的输出Tensor
// result 为模型预测的结果
// im_info 为预处理记录的信息,后处理用于还原box
// conf_threshold 后处理时过滤box的置信度阈值
// nms_iou_threshold 后处理时NMS设定的iou阈值
bool Postprocess(FDTensor& infer_result, DetectionResult* result,
const std::map<std::string, std::array<float, 2>>& im_info,
float conf_threshold, float nms_iou_threshold);

// 对图片进行LetterBox处理
// mat 为读取到的原图
// size 为输入模型的图像尺寸
void LetterBox(Mat* mat, const std::vector<int>& size,
const std::vector<float>& color, bool _auto,
bool scale_fill = false, bool scale_up = true,
Expand Down
26 changes: 1 addition & 25 deletions fastdeploy/vision/detection/contrib/yolov5.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -23,28 +23,16 @@ namespace detection {

class FASTDEPLOY_DECL YOLOv5 : public FastDeployModel {
public:
// 当model_format为ONNX时,无需指定params_file
// 当model_format为Paddle时,则需同时指定model_file & params_file
YOLOv5(const std::string& model_file, const std::string& params_file = "",
const RuntimeOption& custom_option = RuntimeOption(),
const ModelFormat& model_format = ModelFormat::ONNX);

// 定义模型的名称
std::string ModelName() const { return "yolov5"; }

// 模型预测接口,即用户调用的接口
// im 为用户的输入数据,目前对于CV均定义为cv::Mat
// result 为模型预测的输出结构体
// conf_threshold 为后处理的参数
// nms_iou_threshold 为后处理的参数
virtual bool Predict(cv::Mat* im, DetectionResult* result,
float conf_threshold = 0.25,
float nms_iou_threshold = 0.5);

// 输入图像预处理操作
// Mat为FastDeploy定义的数据结构
// FDTensor为预处理后的Tensor数据,传给后端进行推理
// im_info为预处理过程保存的数据,在后处理中需要用到
static bool Preprocess(Mat* mat, FDTensor* output,
std::map<std::string, std::array<float, 2>>* im_info,
const std::vector<int>& size = {640, 640},
Expand All @@ -54,22 +42,12 @@ class FASTDEPLOY_DECL YOLOv5 : public FastDeployModel {
bool is_scale_up = false, int stride = 32,
float max_wh = 7680.0, bool multi_label = true);

// 后端推理结果后处理,输出给用户
// infer_result 为后端推理后的输出Tensor
// result 为模型预测的结果
// im_info 为预处理记录的信息,后处理用于还原box
// conf_threshold 后处理时过滤box的置信度阈值
// nms_iou_threshold 后处理时NMS设定的iou阈值
// multi_label 后处理时box选取是否采用多标签方式
static bool Postprocess(
std::vector<FDTensor>& infer_results, DetectionResult* result,
const std::map<std::string, std::array<float, 2>>& im_info,
float conf_threshold, float nms_iou_threshold, bool multi_label,
float max_wh = 7680.0);

// 以下为模型在预测时的一些参数,基本是前后处理所需
// 用户在创建模型后,可根据模型的要求,以及自己的需求
// 对参数进行修改
// tuple of (width, height)
std::vector<int> size_;
// padding value, size should be same with Channels
Expand All @@ -90,10 +68,8 @@ class FASTDEPLOY_DECL YOLOv5 : public FastDeployModel {
bool multi_label_;

private:
// 初始化函数,包括初始化后端,以及其它模型推理需要涉及的操作
bool Initialize();

// 查看输入是否为动态维度的 不建议直接使用 不同模型的逻辑可能不一致
bool IsDynamicInput() const { return is_dynamic_input_; }

static void LetterBox(Mat* mat, std::vector<int> size,
Expand Down
6 changes: 2 additions & 4 deletions fastdeploy/vision/detection/contrib/yolov5lite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ YOLOv5Lite::YOLOv5Lite(const std::string& model_file,
const RuntimeOption& custom_option,
const ModelFormat& model_format) {
if (model_format == ModelFormat::ONNX) {
valid_cpu_backends = {Backend::ORT}; // 指定可用的CPU后端
valid_gpu_backends = {Backend::ORT, Backend::TRT}; // 指定可用的GPU后端
valid_cpu_backends = {Backend::ORT};
valid_gpu_backends = {Backend::ORT, Backend::TRT};
} else {
valid_cpu_backends = {Backend::PDINFER, Backend::ORT};
valid_gpu_backends = {Backend::PDINFER, Backend::ORT, Backend::TRT};
Expand Down Expand Up @@ -244,7 +244,6 @@ bool YOLOv5Lite::PostprocessWithDecode(
float pad_h = (out_h - ipt_h * scale) / 2.0f;
float pad_w = (out_w - ipt_w * scale) / 2.0f;
if (is_mini_pad) {
// 和 LetterBox中_auto=true的处理逻辑对应
pad_h = static_cast<float>(static_cast<int>(pad_h) % stride);
pad_w = static_cast<float>(static_cast<int>(pad_w) % stride);
}
Expand Down Expand Up @@ -314,7 +313,6 @@ bool YOLOv5Lite::Postprocess(
float pad_h = (out_h - ipt_h * scale) / 2.0f;
float pad_w = (out_w - ipt_w * scale) / 2.0f;
if (is_mini_pad) {
// 和 LetterBox中_auto=true的处理逻辑对应
pad_h = static_cast<float>(static_cast<int>(pad_h) % stride);
pad_w = static_cast<float>(static_cast<int>(pad_w) % stride);
}
Expand Down
Loading

0 comments on commit efa7411

Please sign in to comment.