更新example 和模型转换代码

This commit is contained in:
Zheng-Bicheng
2023-02-15 20:37:42 +08:00
parent f900199c02
commit 53333c5db6
3 changed files with 26 additions and 21 deletions

View File

@@ -15,9 +15,7 @@
```bash ```bash
mkdir build mkdir build
cd build cd build
# 下载FastDeploy预编译库用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用
wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz
tar xvf fastdeploy-linux-x64-x.x.x.tgz
cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x
make -j make -j
@@ -27,8 +25,8 @@ tar -xvf PP_TinyPose_256x192_infer.tgz
wget https://bj.bcebos.com/paddlehub/fastdeploy/hrnet_demo.jpg wget https://bj.bcebos.com/paddlehub/fastdeploy/hrnet_demo.jpg
# CPU推理 # NPU推理
./infer_tinypose_demo PP_TinyPose_256x192_infer hrnet_demo.jpg sudo ./infer_tinypose_demo ./PP_TinyPose_256x192_infer ./hrnet_demo.jpg
``` ```
运行完成可视化结果如下图所示 运行完成可视化结果如下图所示
@@ -79,7 +77,7 @@ PPTinyPose模型加载和初始化其中model_file为导出的Paddle模型格
#### 后处理参数 #### 后处理参数
> > * **use_dark**(bool): 是否使用DARK进行后处理[参考论文](https://arxiv.org/abs/1910.06278) > > * **use_dark**(bool): 是否使用DARK进行后处理[参考论文](https://arxiv.org/abs/1910.06278)
- [模型介绍](../../) - [模型介绍](../../../)
- [Python部署](../python) - [Python部署](../../python)
- [视觉模型预测结果](../../../../../docs/api/vision_results/) - [视觉模型预测结果](../../../../../../docs/api/vision_results/)
- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) - [如何切换模型推理后端引擎](../../../../../../docs/cn/faq/how_to_change_backend.md)

View File

@@ -17,13 +17,14 @@
void RKNPU2Infer(const std::string& tinypose_model_dir, void RKNPU2Infer(const std::string& tinypose_model_dir,
const std::string& image_file) { const std::string& image_file) {
auto tinypose_model_file = auto tinypose_model_file =
tinypose_model_dir + "/picodet_s_416_coco_lcnet_rk3588.rknn"; tinypose_model_dir + "/PP_TinyPose_256x192_infer_rk3588_unquantized.rknn";
auto tinypose_params_file = ""; auto tinypose_params_file = "";
auto tinypose_config_file = tinypose_model_dir + "infer_cfg.yml"; auto tinypose_config_file = tinypose_model_dir + "/infer_cfg.yml";
auto option = fastdeploy::RuntimeOption(); auto option = fastdeploy::RuntimeOption();
option.UseRKNPU2(); option.UseRKNPU2();
auto tinypose_model = fastdeploy::vision::keypointdetection::PPTinyPose( auto tinypose_model = fastdeploy::vision::keypointdetection::PPTinyPose(
tinypose_model_file, tinypose_params_file, tinypose_config_file, option); tinypose_model_file, tinypose_params_file, tinypose_config_file, option,
fastdeploy::RKNN);
if (!tinypose_model.Initialized()) { if (!tinypose_model.Initialized()) {
std::cerr << "TinyPose Model Failed to initialize." << std::endl; std::cerr << "TinyPose Model Failed to initialize." << std::endl;
@@ -51,20 +52,14 @@ void RKNPU2Infer(const std::string& tinypose_model_dir,
} }
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
if (argc < 4) { if (argc < 3) {
std::cout << "Usage: infer_demo path/to/pptinypose_model_dir path/to/image " std::cout << "Usage: infer_demo path/to/pptinypose_model_dir path/to/image "
"run_option, " "run_option, "
"e.g ./infer_model ./pptinypose_model_dir ./test.jpeg 0" "e.g ./infer_model ./pptinypose_model_dir ./test.jpeg"
<< std::endl;
std::cout << "The data type of run_option is int, 0: run with cpu; 1: run "
"with gpu; 2: run with gpu and use tensorrt backend; 3: run "
"with kunlunxin."
<< std::endl; << std::endl;
return -1; return -1;
} }
if (std::atoi(argv[3]) == 0) {
RKNPU2Infer(argv[1], argv[2]); RKNPU2Infer(argv[1], argv[2]);
}
return 0; return 0;
} }

View File

@@ -139,6 +139,18 @@ bool PPTinyPose::Postprocess(std::vector<FDTensor>& infer_result,
"Only support batch = 1 in FastDeploy now."); "Only support batch = 1 in FastDeploy now.");
result->Clear(); result->Clear();
if (infer_result.size() == 1) {
FDTensor result_copy = infer_result[0];
std::cout << "Reshape result_copy!" << std::endl;
result_copy.Reshape({result_copy.shape[0], result_copy.shape[1],
result_copy.shape[2] * result_copy.shape[3]});
std::cout << "Resize infer_result!" << std::endl;
infer_result.resize(2);
std::cout << "Do ArgMax!" << std::endl;
function::ArgMax(result_copy,&infer_result[1],-1);
std::cout << "Done!" << std::endl;
}
// Calculate output length // Calculate output length
int outdata_size = int outdata_size =
std::accumulate(infer_result[0].shape.begin(), std::accumulate(infer_result[0].shape.begin(),