-
Notifications
You must be signed in to change notification settings - Fork 473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Hackthon_4th 177] Support PP-YOLOE-R with BM1684 #1809
Conversation
…into bm1684x_yoloe_r
…into bm1684x_yoloe_r
@DefTruth 巨佬,麻烦指导一下 |
LGTM~ |
@thunder95 辛苦提供下预测后的可视化结果图哈,直接贴到PR的comments即可 |
|
@DefTruth 老师 已贴图 |
benchmark/cpp/benchmark_ppyoloe_r.cc
Outdated
res.emplace_back(std::stof(s.substr(pos1))); | ||
} | ||
|
||
void showDiffStats(const std::vector<float>& data, const std::string& title) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
函数首字母大写
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已完成
benchmark/cpp/benchmark_ppyoloe_r.cc
Outdated
} | ||
double sum = accumulate(begin(data), end(data), 0.0); | ||
double mean = sum / data.size(); | ||
max = *max_element(data.begin(), data.end()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
标准库的使用均使用std限制,类型转换采用c++的风格 static_cast
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已完成
benchmark/cpp/benchmark_ppyoloe_r.cc
Outdated
<< ", mean: " << average << std::endl; | ||
} | ||
|
||
void sortBoxes(vision::DetectionResult* result, std::vector<int>* indices) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已完成
benchmark/cpp/benchmark_ppyoloe_r.cc
Outdated
auto params_file = FLAGS_model + sep + params_name; | ||
auto config_file = FLAGS_model + sep + config_name; | ||
|
||
auto model_ppyoloe_r = vision::detection::PPYOLOE_R( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c++类名不采用下划线分隔,需要修改成 PPYOLOER
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已完成
benchmark/cpp/benchmark_ppyoloe_r.cc
Outdated
model_file, params_file, config_file, option, model_format); | ||
|
||
vision::DetectionResult res; | ||
if (config_info["precision_compare"] == "true") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这段精度验证的逻辑可以先删除或留空,后续FD这边会统一增加这段精度的逻辑。将该精度验证代码在PR中说明即可。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已完成
@@ -264,6 +264,57 @@ bool PaddleDetPostprocessor::ProcessSolov2( | |||
return true; | |||
} | |||
|
|||
bool PaddleDetPostprocessor::ProcessPPYOLOE_R( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
函数名ProcessPPYOLOE_R->ProcessPPYOLOE_R
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已完成
@@ -91,6 +96,10 @@ class FASTDEPLOY_DECL PaddleDetPostprocessor { | |||
bool ProcessSolov2(const std::vector<FDTensor>& tensors, | |||
std::vector<DetectionResult>* results); | |||
|
|||
// Process PPYOLOE_R |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
参考SetNMSOption,需要增加SetNMSRotatedOption方法
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已完成
@@ -125,6 +164,45 @@ cv::Mat VisDetection(const cv::Mat& im, const DetectionResult& result, | |||
int h = im.rows; | |||
int w = im.cols; | |||
auto vis_im = im.clone(); | |||
for (size_t i = 0; i < result.rotated_boxes.size(); ++i) { | |||
printf("result score: %f, %f\n", result.scores[i], score_threshold); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这句log删除
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已完成
@@ -38,6 +38,45 @@ cv::Mat VisDetection(const cv::Mat& im, const DetectionResult& result, | |||
int h = im.rows; | |||
int w = im.cols; | |||
auto vis_im = im.clone(); | |||
for (size_t i = 0; i < result.rotated_boxes.size(); ++i) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这段逻辑看起来和后边的新增的是一样的,处理的是有什么区别吗?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DefTruth 逻辑是相同的,这里参考boxes简单拷贝了一份逻辑在两个不同的函数里。下面的函数支持传自定义标签const std::vectorstd::string& labels
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的
@@ -781,3 +781,40 @@ def __init__(self, | |||
config_file, self._runtime_option, | |||
model_format) | |||
assert self.initialized, "GFL model initialize failed." | |||
|
|||
|
|||
class PPYOLOE_R(PPYOLOE): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
类名 PPYOLOE_R -> PPYOLOER
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已完成
关于benchmark耗时为0的问题,是因为fd目前还没支持sophgo后端的benchmark功能。可以参考Paddle Lite后端中的写法,增加推理benchmark宏,对推理块进行包裹。
更详细的说明,还可以参考这个PR: 编译带benchmark功能的SDK,需要-DENABLE_BENCHMARK=ON |
@DefTruth 在sophgo设备上运行成功benchmark |
LGTM~ |
@@ -55,6 +58,12 @@ class FASTDEPLOY_DECL PaddleDetPostprocessor { | |||
/// only available for those model exported without box decoding and nms. | |||
void ApplyNMS() { with_nms_ = false; } | |||
|
|||
/// If you do not want to modify the Yaml configuration file, | |||
/// you can use this function to set rotated NMS parameters. | |||
void SetNMSRotatedOption(const NMSRotatedOption& option) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个接口需要在ppdet_pybind中绑定下,以便在python中调用。同理NMSRotatedOption,也需要在pybind中绑定下。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DefTruth 已完成
@thunder95 CI似乎都挂了,需要检查下pybind的逻辑,看起来是命名空间没索引正确。 |
@DefTruth 已完成修改 |
@@ -272,6 +323,10 @@ bool PaddleDetPostprocessor::Run(const std::vector<FDTensor>& tensors, | |||
// The fourth output of solov2 is mask | |||
return ProcessMask(tensors[3], results); | |||
} else { | |||
if (tensors[0].Shape()[2] == 8) { // PPYOLOER |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个shape是否一定是3维度?picodet等的输出tensor一般是2个维度,索引2会取到一个随机值
@thunder95 您好,请问下您使用的ppyoloe_r模型提交到算能model_zoo了吗,我找了好久没找到,您方便发我一下吗?发邮箱(851532562@qq.com)也行。非常感谢! |
@851532562 您好,我试着找了下,没有找到该模型,之前借的设备也还了。这个转模型过程相对也比较简单,先导出onnx,然后用最新版mlir转bmodel,老版本的可能会遇到部分算子不支持。 |
嗯,我按照文档指示能完成模型转换过程,在bm1684x上也能跑起来,不过结果有一些问题,该识别出来的没识别到,有些不对的框置信度还挺高,您遇到过这样的问题吗? |
@thunder95 麻烦帮忙看看哦,感谢! |
@851532562 这是自己训练的模型吗,有跟python跑出的结果进行对比吗?之前我测试官网的模型,是有轻微的差别,主要原因是模型移植过程中模型本身会有轻微精度损失,另外,旋转框后处理的实现上也有差别,官网原始实现是有一个cuda算子,具体名称忘记了,我参考的是deploy里numpy处理的逻辑进行移植到fastdeploy。 |
@thunder95 您说的python跑的结果是指用paddledetection跑的吗,我等下对比一下。我这个用的是paddledetection导出的,不是自己训练的,导出的时候去掉了最后的multiclass_nms算子,其他的都是按fastdeploy sophgo文档操作的 |
PR types(PR类型)
Model
Description
将PP-YOLOE-R在算能BM1684部署