PaddlePaddle / Paddle-Lite

PaddlePaddle High Performance Deep Learning Inference Engine for Mobile and Edge (飞桨高性能深度学习端侧推理引擎)
https://www.paddlepaddle.org.cn/lite
Apache License 2.0
6.89k stars 1.6k forks source link

PPOCRv4模型的opencl部署支持 #10468

Closed renshujiajia closed 3 months ago

renshujiajia commented 3 months ago

当前paddle-lite是否能够支持基于opencl的PPOCRv4和v3的模型部署?看到paddle-lite的opencl文档中只描述支持到v2

MuShangCC commented 3 months ago

opencl文档里的模型是已经验证过了的,paddle-lite 现在的版本是否支持 PPOCRv4 并没有验证过。

renshujiajia commented 3 months ago

opencl文档里的模型是已经验证过了的,paddle-lite 现在的版本是否支持 PPOCRv4 并没有验证过。

是否能转opencl类型的nb模型成功就证明能够使用对应版本pddle-lite引擎进行opencl加速呢

MuShangCC commented 3 months ago

opencl文档里的模型是已经验证过了的,paddle-lite 现在的版本是否支持 PPOCRv4 并没有验证过。

是否能转opencl类型的nb模型成功就证明能够使用对应版本pddle-lite引擎进行opencl加速呢

不一定,具体看算子在opencl后端是否支持:https://www.paddlepaddle.org.cn/lite/develop/user_guides/opt/opt_bin.html

renshujiajia commented 3 months ago

opencl文档里的模型是已经验证过了的,paddle-lite 现在的版本是否支持 PPOCRv4 并没有验证过。

是否能转opencl类型的nb模型成功就证明能够使用对应版本pddle-lite引擎进行opencl加速呢

不一定,具体看算子在opencl后端是否支持:https://www.paddlepaddle.org.cn/lite/develop/user_guides/opt/opt_bin.html

使用官方提供的2.12版本opt_linux,以及官方发布的v3识别infer模型进行查看,如下打印说supports, 但是实际拿去运行连kernel的bin文件都生成不了,直接报错,对比v2识别infer模型转nb后去运行,能够生成bin文件且推理正常(程序是基于lite的demo改的,加载模型过程中添加了配置opencl的代码:

bool is_opencl_backend_valid =
::IsOpenCLBackendValid(/check_fp16_valid = false/);
std::cout << "is_opencl_backend_valid:"
<< (is_opencl_backend_valid ? "true" : "false") << std::endl;
if (is_opencl_backend_valid)
{
std::cout << "det check: opencl envrioment is avaliable" << std::endl;

// 进行opencl相关的配置
const std::string bin_path = "./binfile/";
const std::string bin_name = "lite_opencl_kernel_det.bin";
config.set_opencl_binary_path_name(bin_path, bin_name);

const std::string tuned_path = "./binfile/";
const std::string tuned_name = "lite_opencl_tuned_det.bin";
config.set_opencl_tune(CL_TUNE_NORMAL, tuned_path, tuned_name);

config.set_opencl_precision(CL_PRECISION_FP16);
} 

v4识别infer模型也打印说supports,所以这个到底具有参考性没有 企业微信截图_17110115029735 企业微信截图_17110115329627

MuShangCC commented 3 months ago

opencl文档里的模型是已经验证过了的,paddle-lite 现在的版本是否支持 PPOCRv4 并没有验证过。

是否能转opencl类型的nb模型成功就证明能够使用对应版本pddle-lite引擎进行opencl加速呢

不一定,具体看算子在opencl后端是否支持:https://www.paddlepaddle.org.cn/lite/develop/user_guides/opt/opt_bin.html

使用官方提供的2.12版本opt_linux,以及官方发布的v3识别infer模型进行查看,如下打印说supports, 但是实际拿去运行连kernel的bin文件都生成不了,直接报错,对比v2识别infer模型转nb后去运行,能够生成bin文件且推理正常(程序是基于lite的demo改的,加载模型过程中添加了配置opencl的代码:

bool is_opencl_backend_valid =
::IsOpenCLBackendValid(/check_fp16_valid = false/);
std::cout << "is_opencl_backend_valid:"
<< (is_opencl_backend_valid ? "true" : "false") << std::endl;
if (is_opencl_backend_valid)
{
std::cout << "det check: opencl envrioment is avaliable" << std::endl;

// 进行opencl相关的配置
const std::string bin_path = "./binfile/";
const std::string bin_name = "lite_opencl_kernel_det.bin";
config.set_opencl_binary_path_name(bin_path, bin_name);

const std::string tuned_path = "./binfile/";
const std::string tuned_name = "lite_opencl_tuned_det.bin";
config.set_opencl_tune(CL_TUNE_NORMAL, tuned_path, tuned_name);

config.set_opencl_precision(CL_PRECISION_FP16);
} 

v4识别infer模型也打印说supports,所以这个到底具有参考性没有 企业微信截图_17110115029735 企业微信截图_17110115329627

opt这个只统计算子支持的信息,你的报错信息是某个算子不支持还是别的什么?

renshujiajia commented 3 months ago

opencl文档里的模型是已经验证过了的,paddle-lite 现在的版本是否支持 PPOCRv4 并没有验证过。

是否能转opencl类型的nb模型成功就证明能够使用对应版本pddle-lite引擎进行opencl加速呢

不一定,具体看算子在opencl后端是否支持:https://www.paddlepaddle.org.cn/lite/develop/user_guides/opt/opt_bin.html

使用官方提供的2.12版本opt_linux,以及官方发布的v3识别infer模型进行查看,如下打印说supports, 但是实际拿去运行连kernel的bin文件都生成不了,直接报错,对比v2识别infer模型转nb后去运行,能够生成bin文件且推理正常(程序是基于lite的demo改的,加载模型过程中添加了配置opencl的代码:

bool is_opencl_backend_valid =
::IsOpenCLBackendValid(/check_fp16_valid = false/);
std::cout << "is_opencl_backend_valid:"
<< (is_opencl_backend_valid ? "true" : "false") << std::endl;
if (is_opencl_backend_valid)
{
std::cout << "det check: opencl envrioment is avaliable" << std::endl;

// 进行opencl相关的配置
const std::string bin_path = "./binfile/";
const std::string bin_name = "lite_opencl_kernel_det.bin";
config.set_opencl_binary_path_name(bin_path, bin_name);

const std::string tuned_path = "./binfile/";
const std::string tuned_name = "lite_opencl_tuned_det.bin";
config.set_opencl_tune(CL_TUNE_NORMAL, tuned_path, tuned_name);

config.set_opencl_precision(CL_PRECISION_FP16);
} 

v4识别infer模型也打印说supports,所以这个到底具有参考性没有 企业微信截图_17110115029735 企业微信截图_17110115329627

opt这个只统计算子支持的信息,你的报错信息是某个算子不支持还是别的什么?

没有报错,检测结果正确但是识别结果不正确。我使用det_v2 + cls_v2 + recv4模型进行opencl推理,模型推理按照det + cls + rec结束,然后发现只有det和cls模型生成了opencl的bin文件,rec模型没有生成bin文件,并且rec模型没有生成bin文件。这个现象还挺特殊的,并没有提示什么错误,就好像我导出的是一个arm8的模型一样,但是我确实导出了opencl模型且没有生成bin。

renshujiajia commented 3 months ago

opencl文档里的模型是已经验证过了的,paddle-lite 现在的版本是否支持 PPOCRv4 并没有验证过。

是否能转opencl类型的nb模型成功就证明能够使用对应版本pddle-lite引擎进行opencl加速呢

不一定,具体看算子在opencl后端是否支持:https://www.paddlepaddle.org.cn/lite/develop/user_guides/opt/opt_bin.html

使用官方提供的2.12版本opt_linux,以及官方发布的v3识别infer模型进行查看,如下打印说supports, 但是实际拿去运行连kernel的bin文件都生成不了,直接报错,对比v2识别infer模型转nb后去运行,能够生成bin文件且推理正常(程序是基于lite的demo改的,加载模型过程中添加了配置opencl的代码:

bool is_opencl_backend_valid =
::IsOpenCLBackendValid(/check_fp16_valid = false/);
std::cout << "is_opencl_backend_valid:"
<< (is_opencl_backend_valid ? "true" : "false") << std::endl;
if (is_opencl_backend_valid)
{
std::cout << "det check: opencl envrioment is avaliable" << std::endl;

// 进行opencl相关的配置
const std::string bin_path = "./binfile/";
const std::string bin_name = "lite_opencl_kernel_det.bin";
config.set_opencl_binary_path_name(bin_path, bin_name);

const std::string tuned_path = "./binfile/";
const std::string tuned_name = "lite_opencl_tuned_det.bin";
config.set_opencl_tune(CL_TUNE_NORMAL, tuned_path, tuned_name);

config.set_opencl_precision(CL_PRECISION_FP16);
} 

v4识别infer模型也打印说supports,所以这个到底具有参考性没有 企业微信截图_17110115029735 企业微信截图_17110115329627

对于这个测试,v3的opencl检测模型会直接在Neon加速之后报错,对比v2的opencl检测模型能够正常推理

terminating with uncaught exception of type std::exception: std::exception
MuShangCC commented 3 months ago

opencl文档里的模型是已经验证过了的,paddle-lite 现在的版本是否支持 PPOCRv4 并没有验证过。

是否能转opencl类型的nb模型成功就证明能够使用对应版本pddle-lite引擎进行opencl加速呢

不一定,具体看算子在opencl后端是否支持:https://www.paddlepaddle.org.cn/lite/develop/user_guides/opt/opt_bin.html

使用官方提供的2.12版本opt_linux,以及官方发布的v3识别infer模型进行查看,如下打印说supports, 但是实际拿去运行连kernel的bin文件都生成不了,直接报错,对比v2识别infer模型转nb后去运行,能够生成bin文件且推理正常(程序是基于lite的demo改的,加载模型过程中添加了配置opencl的代码:

bool is_opencl_backend_valid =
::IsOpenCLBackendValid(/check_fp16_valid = false/);
std::cout << "is_opencl_backend_valid:"
<< (is_opencl_backend_valid ? "true" : "false") << std::endl;
if (is_opencl_backend_valid)
{
std::cout << "det check: opencl envrioment is avaliable" << std::endl;

// 进行opencl相关的配置
const std::string bin_path = "./binfile/";
const std::string bin_name = "lite_opencl_kernel_det.bin";
config.set_opencl_binary_path_name(bin_path, bin_name);

const std::string tuned_path = "./binfile/";
const std::string tuned_name = "lite_opencl_tuned_det.bin";
config.set_opencl_tune(CL_TUNE_NORMAL, tuned_path, tuned_name);

config.set_opencl_precision(CL_PRECISION_FP16);
} 

v4识别infer模型也打印说supports,所以这个到底具有参考性没有 企业微信截图_17110115029735 企业微信截图_17110115329627

对于这个测试,v3的opencl检测模型会直接在Neon加速之后报错,对比v2的opencl检测模型能够正常推理

terminating with uncaught exception of type std::exception: std::exception

Neon加速也是使用的Lite吗?

renshujiajia commented 3 months ago

opencl文档里的模型是已经验证过了的,paddle-lite 现在的版本是否支持 PPOCRv4 并没有验证过。

是否能转opencl类型的nb模型成功就证明能够使用对应版本pddle-lite引擎进行opencl加速呢

不一定,具体看算子在opencl后端是否支持:https://www.paddlepaddle.org.cn/lite/develop/user_guides/opt/opt_bin.html

使用官方提供的2.12版本opt_linux,以及官方发布的v3识别infer模型进行查看,如下打印说supports, 但是实际拿去运行连kernel的bin文件都生成不了,直接报错,对比v2识别infer模型转nb后去运行,能够生成bin文件且推理正常(程序是基于lite的demo改的,加载模型过程中添加了配置opencl的代码:

bool is_opencl_backend_valid =
::IsOpenCLBackendValid(/check_fp16_valid = false/);
std::cout << "is_opencl_backend_valid:"
<< (is_opencl_backend_valid ? "true" : "false") << std::endl;
if (is_opencl_backend_valid)
{
std::cout << "det check: opencl envrioment is avaliable" << std::endl;

// 进行opencl相关的配置
const std::string bin_path = "./binfile/";
const std::string bin_name = "lite_opencl_kernel_det.bin";
config.set_opencl_binary_path_name(bin_path, bin_name);

const std::string tuned_path = "./binfile/";
const std::string tuned_name = "lite_opencl_tuned_det.bin";
config.set_opencl_tune(CL_TUNE_NORMAL, tuned_path, tuned_name);

config.set_opencl_precision(CL_PRECISION_FP16);
} 

v4识别infer模型也打印说supports,所以这个到底具有参考性没有 企业微信截图_17110115029735 企业微信截图_17110115329627

对于这个测试,v3的opencl检测模型会直接在Neon加速之后报错,对比v2的opencl检测模型能够正常推理

terminating with uncaught exception of type std::exception: std::exception

Neon加速也是使用的Lite吗?

是的,Neon加速也是使用的Lite的demo,经过测试v2.12的paddle-lite支持v2rec与v2det,支持v3和v4的det,v3和v4的rec识别结果是乱的,模型的后处理逻辑是没更改的valid_targets=arm时是正常的,考虑应该是这两个版本的模型内部存在不同实现方式的算子导致输出不匹配,期待后续兼容吧。