更换文档检测模型
This commit is contained in:
14
paddle_detection/deploy/fastdeploy/sophgo/cpp/CMakeLists.txt
Normal file
14
paddle_detection/deploy/fastdeploy/sophgo/cpp/CMakeLists.txt
Normal file
@@ -0,0 +1,14 @@
|
||||
PROJECT(infer_demo C CXX)
|
||||
CMAKE_MINIMUM_REQUIRED (VERSION 3.10)
|
||||
option(FASTDEPLOY_INSTALL_DIR "Path of downloaded fastdeploy sdk.")
|
||||
|
||||
set(ENABLE_LITE_BACKEND OFF)
|
||||
#set(FDLIB ${FASTDEPLOY_INSTALL_DIR})
|
||||
|
||||
include(${FASTDEPLOY_INSTALL_DIR}/FastDeploy.cmake)
|
||||
|
||||
include_directories(${FASTDEPLOY_INCS})
|
||||
include_directories(${FastDeploy_INCLUDE_DIRS})
|
||||
|
||||
add_executable(infer_demo ${PROJECT_SOURCE_DIR}/infer.cc)
|
||||
target_link_libraries(infer_demo ${FASTDEPLOY_LIBS})
|
||||
57
paddle_detection/deploy/fastdeploy/sophgo/cpp/README.md
Normal file
57
paddle_detection/deploy/fastdeploy/sophgo/cpp/README.md
Normal file
@@ -0,0 +1,57 @@
|
||||
# PaddleDetection 算能 C++部署示例
|
||||
|
||||
本目录下提供`infer.cc`,`快速完成 PP-YOLOE ,在SOPHGO BM1684x板子上加速部署的示例。PP-YOLOV8和 PicoDet的部署逻辑类似,只需要切换模型即可。
|
||||
|
||||
## 1. 部署环境准备
|
||||
在部署前,需自行编译基于算能硬件的预测库,参考文档[算能硬件部署环境](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install#算能硬件部署环境)
|
||||
|
||||
## 2. 部署模型准备
|
||||
在部署前,请准备好您所需要运行的推理模型,你可以选择使用[预导出的推理模型](../README.md)或者[自行导出PaddleDetection部署模型](../README.md)。
|
||||
|
||||
## 3. 生成基本目录文件
|
||||
|
||||
该例程由以下几个部分组成
|
||||
```text
|
||||
.
|
||||
├── CMakeLists.txt
|
||||
├── fastdeploy-sophgo # 编译文件夹
|
||||
├── image # 存放图片的文件夹
|
||||
├── infer.cc
|
||||
└── model # 存放模型文件的文件夹
|
||||
```
|
||||
|
||||
## 4. 运行部署示例
|
||||
|
||||
### 4.1 编译并拷贝SDK到thirdpartys文件夹
|
||||
|
||||
请参考[SOPHGO部署库编译](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/sophgo.md)仓库编译SDK,编译完成后,将在build目录下生成fastdeploy-sophgo目录.
|
||||
|
||||
### 4.2 拷贝模型文件,以及配置文件至model文件夹
|
||||
将Paddle模型转换为SOPHGO bmodel模型,转换步骤参考[文档](../README.md)
|
||||
将转换后的SOPHGO bmodel模型文件拷贝至model中
|
||||
|
||||
### 4.3 准备测试图片至image文件夹
|
||||
```bash
|
||||
wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg
|
||||
cp 000000014439.jpg ./images
|
||||
```
|
||||
|
||||
### 4.4 编译example
|
||||
|
||||
```bash
|
||||
cd build
|
||||
cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-sophgo
|
||||
make
|
||||
```
|
||||
|
||||
## 4.5 运行例程
|
||||
|
||||
```bash
|
||||
#ppyoloe推理示例
|
||||
./infer_demo model images/000000014439.jpg
|
||||
```
|
||||
|
||||
## 5. 更多指南
|
||||
- [FastDeploy部署PaddleDetection模型概览](../../)
|
||||
- [Python部署](../python)
|
||||
- [模型转换](../README.md)
|
||||
60
paddle_detection/deploy/fastdeploy/sophgo/cpp/infer.cc
Normal file
60
paddle_detection/deploy/fastdeploy/sophgo/cpp/infer.cc
Normal file
@@ -0,0 +1,60 @@
|
||||
// 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.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "fastdeploy/vision.h"
|
||||
|
||||
void SophgoInfer(const std::string& model_dir, const std::string& image_file) {
|
||||
auto model_file = model_dir + "/ppyoloe_crn_s_300e_coco_1684x_f32.bmodel";
|
||||
auto params_file = "";
|
||||
auto config_file = model_dir + "/infer_cfg.yml";
|
||||
|
||||
auto option = fastdeploy::RuntimeOption();
|
||||
option.UseSophgo();
|
||||
|
||||
auto format = fastdeploy::ModelFormat::SOPHGO;
|
||||
|
||||
auto model = fastdeploy::vision::detection::PPYOLOE(
|
||||
model_file, params_file, config_file, option, format);
|
||||
|
||||
model.GetPostprocessor().ApplyNMS();
|
||||
|
||||
auto im = cv::imread(image_file);
|
||||
|
||||
fastdeploy::vision::DetectionResult res;
|
||||
if (!model.Predict(&im, &res)) {
|
||||
std::cerr << "Failed to predict." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
std::cout << res.Str() << std::endl;
|
||||
auto vis_im = fastdeploy::vision::VisDetection(im, res, 0.5);
|
||||
cv::imwrite("infer_sophgo.jpg", vis_im);
|
||||
std::cout << "Visualized result saved in ./infer_sophgo.jpg" << std::endl;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc < 3) {
|
||||
std::cout
|
||||
<< "Usage: infer_demo path/to/model_dir path/to/image, "
|
||||
"e.g ./infer_demo ./model_dir ./test.jpeg"
|
||||
<< std::endl;
|
||||
return -1;
|
||||
}
|
||||
SophgoInfer(argv[1], argv[2]);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user