[Bug Fix] change reused_input_tensors&&reused_output_tensors name (#534)

* add paddle_trt in benchmark

* update benchmark in device

* update benchmark

* update result doc

* fixed for CI

* update python api_docs

* update index.rst

* add runtime cpp examples

* deal with comments

* Update infer_paddle_tensorrt.py

* Add runtime quick start

* deal with comments

* fixed reused_input_tensors&&reused_output_tensors

Co-authored-by: Jason <928090362@qq.com>
This commit is contained in:
WJJ1995
2022-11-09 00:33:33 +08:00
committed by GitHub
parent 6962921556
commit d259952224
17 changed files with 247 additions and 64 deletions

14
examples/runtime/README.md Normal file → Executable file
View File

@@ -1,5 +1,9 @@
# FastDeploy Runtime examples # FastDeploy Runtime examples
FastDeploy Runtime C++ 推理示例如下
## Python 示例
| Example Code | Program Language | Description | | Example Code | Program Language | Description |
| :------- | :------- | :---- | | :------- | :------- | :---- |
| python/infer_paddle_paddle_inference.py | Python | Deploy Paddle model with Paddle Inference(CPU/GPU) | | python/infer_paddle_paddle_inference.py | Python | Deploy Paddle model with Paddle Inference(CPU/GPU) |
@@ -8,9 +12,19 @@
| python/infer_paddle_onnxruntime.py | Python | Deploy Paddle model with ONNX Runtime(CPU/GPU) | | python/infer_paddle_onnxruntime.py | Python | Deploy Paddle model with ONNX Runtime(CPU/GPU) |
| python/infer_onnx_openvino.py | Python | Deploy ONNX model with OpenVINO(CPU) | | python/infer_onnx_openvino.py | Python | Deploy ONNX model with OpenVINO(CPU) |
| python/infer_onnx_tensorrt.py | Python | Deploy ONNX model with TensorRT(GPU) | | python/infer_onnx_tensorrt.py | Python | Deploy ONNX model with TensorRT(GPU) |
## C++ 示例
| Example Code | Program Language | Description |
| :------- | :------- | :---- |
| cpp/infer_paddle_paddle_inference.cc | C++ | Deploy Paddle model with Paddle Inference(CPU/GPU) | | cpp/infer_paddle_paddle_inference.cc | C++ | Deploy Paddle model with Paddle Inference(CPU/GPU) |
| cpp/infer_paddle_tensorrt.cc | C++ | Deploy Paddle model with TensorRT(GPU) | | cpp/infer_paddle_tensorrt.cc | C++ | Deploy Paddle model with TensorRT(GPU) |
| cpp/infer_paddle_openvino.cc | C++ | Deploy Paddle model with OpenVINO(CPU | | cpp/infer_paddle_openvino.cc | C++ | Deploy Paddle model with OpenVINO(CPU |
| cpp/infer_paddle_onnxruntime.cc | C++ | Deploy Paddle model with ONNX Runtime(CPU/GPU) | | cpp/infer_paddle_onnxruntime.cc | C++ | Deploy Paddle model with ONNX Runtime(CPU/GPU) |
| cpp/infer_onnx_openvino.cc | C++ | Deploy ONNX model with OpenVINO(CPU) | | cpp/infer_onnx_openvino.cc | C++ | Deploy ONNX model with OpenVINO(CPU) |
| cpp/infer_onnx_tensorrt.cc | C++ | Deploy ONNX model with TensorRT(GPU) | | cpp/infer_onnx_tensorrt.cc | C++ | Deploy ONNX model with TensorRT(GPU) |
## 详细部署文档
- [Python部署](python)
- [C++部署](cpp)

View File

@@ -0,0 +1,121 @@
# C++推理
在运行demo前需确认以下两个步骤
- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md)
- 2. 根据开发环境下载预编译部署库和samples代码参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md)
本文档以 PaddleClas 分类模型 MobileNetV2 为例展示CPU上的推理示例
## 1. 获取模型
```bash
wget https://bj.bcebos.com/fastdeploy/models/mobilenetv2.tgz
tar xvf mobilenetv2.tgz
```
## 2. 配置后端
如下C++代码保存为`infer_paddle_onnxruntime.cc`
``` c++
#include "fastdeploy/runtime.h"
namespace fd = fastdeploy;
int main(int argc, char* argv[]) {
std::string model_file = "mobilenetv2/inference.pdmodel";
std::string params_file = "mobilenetv2/inference.pdiparams";
// setup option
fd::RuntimeOption runtime_option;
runtime_option.SetModelPath(model_file, params_file, fd::ModelFormat::PADDLE);
runtime_option.UseOrtBackend();
runtime_option.SetCpuThreadNum(12);
// init runtime
std::unique_ptr<fd::Runtime> runtime =
std::unique_ptr<fd::Runtime>(new fd::Runtime());
if (!runtime->Init(runtime_option)) {
std::cerr << "--- Init FastDeploy Runitme Failed! "
<< "\n--- Model: " << model_file << std::endl;
return -1;
} else {
std::cout << "--- Init FastDeploy Runitme Done! "
<< "\n--- Model: " << model_file << std::endl;
}
// init input tensor shape
fd::TensorInfo info = runtime->GetInputInfo(0);
info.shape = {1, 3, 224, 224};
std::vector<fd::FDTensor> input_tensors(1);
std::vector<fd::FDTensor> output_tensors(1);
std::vector<float> inputs_data;
inputs_data.resize(1 * 3 * 224 * 224);
for (size_t i = 0; i < inputs_data.size(); ++i) {
inputs_data[i] = std::rand() % 1000 / 1000.0f;
}
input_tensors[0].SetExternalData({1, 3, 224, 224}, fd::FDDataType::FP32, inputs_data.data());
//get input name
input_tensors[0].name = info.name;
runtime->Infer(input_tensors, &output_tensors);
output_tensors[0].PrintInfo();
return 0;
}
```
加载完成,会输出提示如下,说明初始化的后端,以及运行的硬件设备
```
[INFO] fastdeploy/fastdeploy_runtime.cc(283)::Init Runtime initialized with Backend::OrtBackend in device Device::CPU.
```
## 3. 准备CMakeLists.txt
FastDeploy中包含多个依赖库直接采用`g++`或编译器编译较为繁杂推荐使用cmake进行编译配置。示例配置如下
```cmake
PROJECT(runtime_demo C CXX)
CMAKE_MINIMUM_REQUIRED (VERSION 3.12)
# 指定下载解压后的fastdeploy库路径
option(FASTDEPLOY_INSTALL_DIR "Path of downloaded fastdeploy sdk.")
include(${FASTDEPLOY_INSTALL_DIR}/FastDeploy.cmake)
# 添加FastDeploy依赖头文件
include_directories(${FASTDEPLOY_INCS})
add_executable(runtime_demo ${PROJECT_SOURCE_DIR}/infer_onnx_openvino.cc)
# 添加FastDeploy库依赖
target_link_libraries(runtime_demo ${FASTDEPLOY_LIBS})
```
## 4. 编译可执行程序
打开命令行终端,进入`infer_paddle_onnxruntime.cc`和`CMakeLists.txt`所在的目录,执行如下命令
```bash
mkdir build & cd build
cmake .. -DFASTDEPLOY_INSTALL_DIR=$fastdeploy_cpp_sdk
make -j
```
```fastdeploy_cpp_sdk``` 为FastDeploy C++部署库路径
编译完成后,使用如下命令执行可得到预测结果
```bash
./runtime_demo
```
执行时如提示`error while loading shared libraries: libxxx.so: cannot open shared object file: No such file...`说明程序执行时没有找到FastDeploy的库路径可通过执行如下命令将FastDeploy的库路径添加到环境变量之后重新执行二进制程序。
```bash
source /Path/to/fastdeploy_cpp_sdk/fastdeploy_init.sh
```
本示例代码在各平台(Windows/Linux/Mac)上通用,但编译过程仅支持(Linux/Mac)Windows上使用msbuild进行编译具体使用方式参考[Windows平台使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md)
## 其它文档
- [Runtime Python 示例](../python)
- [切换模型推理的硬件和后端](../../../../../docs/cn/faq/how_to_change_backend.md)

View File

@@ -0,0 +1,53 @@
# Python推理
在运行demo前需确认以下两个步骤
- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md)
- 2. FastDeploy Python whl包安装参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md)
本文档以 PaddleClas 分类模型 MobileNetV2 为例展示 CPU 上的推理示例
## 1. 获取模型
``` python
import fastdeploy as fd
model_url = "https://bj.bcebos.com/fastdeploy/models/mobilenetv2.tgz"
fd.download_and_decompress(model_url, path=".")
```
## 2. 配置后端
``` python
option = fd.RuntimeOption()
option.set_model_path("mobilenetv2/inference.pdmodel",
"mobilenetv2/inference.pdiparams")
# **** CPU 配置 ****
option.use_cpu()
option.use_ort_backend()
option.set_cpu_thread_num(12)
# 初始化构造runtime
runtime = fd.Runtime(option)
# 获取模型输入名
input_name = runtime.get_input_info(0).name
# 构造随机数据进行推理
results = runtime.infer({
input_name: np.random.rand(1, 3, 224, 224).astype("float32")
})
print(results[0].shape)
```
加载完成,会输出提示如下,说明初始化的后端,以及运行的硬件设备
```
[INFO] fastdeploy/fastdeploy_runtime.cc(283)::Init Runtime initialized with Backend::OrtBackend in device Device::CPU.
```
## 其它文档
- [Runtime C++ 示例](../cpp)
- [切换模型推理的硬件和后端](../../../../../docs/cn/faq/how_to_change_backend.md)

View File

@@ -17,8 +17,6 @@
| [YOLOv5x-cls](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5x-cls.onnx) | 184MB | 79.0% | 94.4% | | [YOLOv5x-cls](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5x-cls.onnx) | 184MB | 79.0% | 94.4% |
## 详细部署文档 ## 详细部署文档
- [Python部署](python) - [Python部署](python)

2
fastdeploy/fastdeploy_model.cc Normal file → Executable file
View File

@@ -239,7 +239,7 @@ bool FastDeployModel::Infer(std::vector<FDTensor>& input_tensors,
} }
bool FastDeployModel::Infer() { bool FastDeployModel::Infer() {
return Infer(reused_input_tensors, &reused_output_tensors); return Infer(reused_input_tensors_, &reused_output_tensors_);
} }
std::map<std::string, float> FastDeployModel::PrintStatisInfoOfRuntime() { std::map<std::string, float> FastDeployModel::PrintStatisInfoOfRuntime() {

19
fastdeploy/fastdeploy_model.h Normal file → Executable file
View File

@@ -28,7 +28,7 @@ class FASTDEPLOY_DECL FastDeployModel {
virtual bool Infer(std::vector<FDTensor>& input_tensors, virtual bool Infer(std::vector<FDTensor>& input_tensors,
std::vector<FDTensor>* output_tensors); std::vector<FDTensor>* output_tensors);
/** \brief Inference the model by the runtime. This interface is using class member reused_input_tensors to do inference and writing results to reused_output_tensors /** \brief Inference the model by the runtime. This interface is using class member reused_input_tensors_ to do inference and writing results to reused_output_tensors_
*/ */
virtual bool Infer(); virtual bool Infer();
@@ -107,17 +107,10 @@ class FASTDEPLOY_DECL FastDeployModel {
/** \brief Release reused input/output buffers /** \brief Release reused input/output buffers
*/ */
virtual void ReleaseReusedBuffer() { virtual void ReleaseReusedBuffer() {
std::vector<FDTensor>().swap(reused_input_tensors); std::vector<FDTensor>().swap(reused_input_tensors_);
std::vector<FDTensor>().swap(reused_output_tensors); std::vector<FDTensor>().swap(reused_output_tensors_);
} }
/** \brief Reused input tensors
*/
std::vector<FDTensor> reused_input_tensors;
/** \brief Reused output tensors
*/
std::vector<FDTensor> reused_output_tensors;
protected: protected:
virtual bool InitRuntime(); virtual bool InitRuntime();
virtual bool CreateCpuBackend(); virtual bool CreateCpuBackend();
@@ -126,7 +119,11 @@ class FASTDEPLOY_DECL FastDeployModel {
virtual bool CreateRKNPUBackend(); virtual bool CreateRKNPUBackend();
bool initialized = false; bool initialized = false;
std::vector<Backend> valid_external_backends; std::vector<Backend> valid_external_backends_;
// Reused input tensors
std::vector<FDTensor> reused_input_tensors_;
// Reused output tensors
std::vector<FDTensor> reused_output_tensors_;
private: private:
std::shared_ptr<Runtime> runtime_; std::shared_ptr<Runtime> runtime_;

8
fastdeploy/vision/classification/ppcls/model.cc Normal file → Executable file
View File

@@ -60,18 +60,18 @@ bool PaddleClasModel::Predict(const cv::Mat& im, ClassifyResult* result) {
bool PaddleClasModel::BatchPredict(const std::vector<cv::Mat>& images, std::vector<ClassifyResult>* results) { bool PaddleClasModel::BatchPredict(const std::vector<cv::Mat>& images, std::vector<ClassifyResult>* results) {
std::vector<FDMat> fd_images = WrapMat(images); std::vector<FDMat> fd_images = WrapMat(images);
if (!preprocessor_.Run(&fd_images, &reused_input_tensors)) { if (!preprocessor_.Run(&fd_images, &reused_input_tensors_)) {
FDERROR << "Failed to preprocess the input image." << std::endl; FDERROR << "Failed to preprocess the input image." << std::endl;
return false; return false;
} }
reused_input_tensors[0].name = InputInfoOfRuntime(0).name; reused_input_tensors_[0].name = InputInfoOfRuntime(0).name;
if (!Infer(reused_input_tensors, &reused_output_tensors)) { if (!Infer(reused_input_tensors_, &reused_output_tensors_)) {
FDERROR << "Failed to inference by runtime." << std::endl; FDERROR << "Failed to inference by runtime." << std::endl;
return false; return false;
} }
if (!postprocessor_.Run(reused_output_tensors, results)) { if (!postprocessor_.Run(reused_output_tensors_, results)) {
FDERROR << "Failed to postprocess the inference results by runtime." << std::endl; FDERROR << "Failed to postprocess the inference results by runtime." << std::endl;
return false; return false;
} }

8
fastdeploy/vision/detection/contrib/scaledyolov4.cc Normal file → Executable file
View File

@@ -84,7 +84,7 @@ bool ScaledYOLOv4::Initialize() {
is_scale_up = false; is_scale_up = false;
stride = 32; stride = 32;
max_wh = 7680.0; max_wh = 7680.0;
reused_input_tensors.resize(1); reused_input_tensors_.resize(1);
if (!InitRuntime()) { if (!InitRuntime()) {
FDERROR << "Failed to initialize fastdeploy backend." << std::endl; FDERROR << "Failed to initialize fastdeploy backend." << std::endl;
@@ -230,17 +230,17 @@ bool ScaledYOLOv4::Predict(cv::Mat* im, DetectionResult* result,
im_info["output_shape"] = {static_cast<float>(mat.Height()), im_info["output_shape"] = {static_cast<float>(mat.Height()),
static_cast<float>(mat.Width())}; static_cast<float>(mat.Width())};
if (!Preprocess(&mat, &reused_input_tensors[0], &im_info)) { if (!Preprocess(&mat, &reused_input_tensors_[0], &im_info)) {
FDERROR << "Failed to preprocess input image." << std::endl; FDERROR << "Failed to preprocess input image." << std::endl;
return false; return false;
} }
reused_input_tensors[0].name = InputInfoOfRuntime(0).name; reused_input_tensors_[0].name = InputInfoOfRuntime(0).name;
if (!Infer()) { if (!Infer()) {
FDERROR << "Failed to inference." << std::endl; FDERROR << "Failed to inference." << std::endl;
return false; return false;
} }
if (!Postprocess(reused_output_tensors[0], result, im_info, conf_threshold, if (!Postprocess(reused_output_tensors_[0], result, im_info, conf_threshold,
nms_iou_threshold)) { nms_iou_threshold)) {
FDERROR << "Failed to post process." << std::endl; FDERROR << "Failed to post process." << std::endl;
return false; return false;

8
fastdeploy/vision/detection/contrib/yolor.cc Normal file → Executable file
View File

@@ -83,7 +83,7 @@ bool YOLOR::Initialize() {
is_scale_up = false; is_scale_up = false;
stride = 32; stride = 32;
max_wh = 7680.0; max_wh = 7680.0;
reused_input_tensors.resize(1); reused_input_tensors_.resize(1);
if (!InitRuntime()) { if (!InitRuntime()) {
FDERROR << "Failed to initialize fastdeploy backend." << std::endl; FDERROR << "Failed to initialize fastdeploy backend." << std::endl;
@@ -227,18 +227,18 @@ bool YOLOR::Predict(cv::Mat* im, DetectionResult* result, float conf_threshold,
im_info["output_shape"] = {static_cast<float>(mat.Height()), im_info["output_shape"] = {static_cast<float>(mat.Height()),
static_cast<float>(mat.Width())}; static_cast<float>(mat.Width())};
if (!Preprocess(&mat, &reused_input_tensors[0], &im_info)) { if (!Preprocess(&mat, &reused_input_tensors_[0], &im_info)) {
FDERROR << "Failed to preprocess input image." << std::endl; FDERROR << "Failed to preprocess input image." << std::endl;
return false; return false;
} }
reused_input_tensors[0].name = InputInfoOfRuntime(0).name; reused_input_tensors_[0].name = InputInfoOfRuntime(0).name;
if (!Infer()) { if (!Infer()) {
FDERROR << "Failed to inference." << std::endl; FDERROR << "Failed to inference." << std::endl;
return false; return false;
} }
if (!Postprocess(reused_output_tensors[0], result, im_info, conf_threshold, if (!Postprocess(reused_output_tensors_[0], result, im_info, conf_threshold,
nms_iou_threshold)) { nms_iou_threshold)) {
FDERROR << "Failed to post process." << std::endl; FDERROR << "Failed to post process." << std::endl;
return false; return false;

10
fastdeploy/vision/detection/contrib/yolov5.cc Normal file → Executable file
View File

@@ -93,7 +93,7 @@ bool YOLOv5::Initialize() {
stride_ = 32; stride_ = 32;
max_wh_ = 7680.0; max_wh_ = 7680.0;
multi_label_ = true; multi_label_ = true;
reused_input_tensors.resize(1); reused_input_tensors_.resize(1);
if (!InitRuntime()) { if (!InitRuntime()) {
FDERROR << "Failed to initialize fastdeploy backend." << std::endl; FDERROR << "Failed to initialize fastdeploy backend." << std::endl;
@@ -350,14 +350,14 @@ bool YOLOv5::Predict(cv::Mat* im, DetectionResult* result, float conf_threshold,
std::map<std::string, std::array<float, 2>> im_info; std::map<std::string, std::array<float, 2>> im_info;
if (use_cuda_preprocessing_) { if (use_cuda_preprocessing_) {
if (!CudaPreprocess(&mat, &reused_input_tensors[0], &im_info, size_, if (!CudaPreprocess(&mat, &reused_input_tensors_[0], &im_info, size_,
padding_value_, is_mini_pad_, is_no_pad_, is_scale_up_, padding_value_, is_mini_pad_, is_no_pad_, is_scale_up_,
stride_, max_wh_, multi_label_)) { stride_, max_wh_, multi_label_)) {
FDERROR << "Failed to preprocess input image." << std::endl; FDERROR << "Failed to preprocess input image." << std::endl;
return false; return false;
} }
} else { } else {
if (!Preprocess(&mat, &reused_input_tensors[0], &im_info, size_, if (!Preprocess(&mat, &reused_input_tensors_[0], &im_info, size_,
padding_value_, is_mini_pad_, is_no_pad_, is_scale_up_, padding_value_, is_mini_pad_, is_no_pad_, is_scale_up_,
stride_, max_wh_, multi_label_)) { stride_, max_wh_, multi_label_)) {
FDERROR << "Failed to preprocess input image." << std::endl; FDERROR << "Failed to preprocess input image." << std::endl;
@@ -365,13 +365,13 @@ bool YOLOv5::Predict(cv::Mat* im, DetectionResult* result, float conf_threshold,
} }
} }
reused_input_tensors[0].name = InputInfoOfRuntime(0).name; reused_input_tensors_[0].name = InputInfoOfRuntime(0).name;
if (!Infer()) { if (!Infer()) {
FDERROR << "Failed to inference." << std::endl; FDERROR << "Failed to inference." << std::endl;
return false; return false;
} }
if (!Postprocess(reused_output_tensors, result, im_info, conf_threshold, if (!Postprocess(reused_output_tensors_, result, im_info, conf_threshold,
nms_iou_threshold, multi_label_)) { nms_iou_threshold, multi_label_)) {
FDERROR << "Failed to post process." << std::endl; FDERROR << "Failed to post process." << std::endl;
return false; return false;

12
fastdeploy/vision/detection/contrib/yolov5lite.cc Normal file → Executable file
View File

@@ -123,7 +123,7 @@ bool YOLOv5Lite::Initialize() {
anchor_config = {{10.0, 13.0, 16.0, 30.0, 33.0, 23.0}, anchor_config = {{10.0, 13.0, 16.0, 30.0, 33.0, 23.0},
{30.0, 61.0, 62.0, 45.0, 59.0, 119.0}, {30.0, 61.0, 62.0, 45.0, 59.0, 119.0},
{116.0, 90.0, 156.0, 198.0, 373.0, 326.0}}; {116.0, 90.0, 156.0, 198.0, 373.0, 326.0}};
reused_input_tensors.resize(1); reused_input_tensors_.resize(1);
if (!InitRuntime()) { if (!InitRuntime()) {
FDERROR << "Failed to initialize fastdeploy backend." << std::endl; FDERROR << "Failed to initialize fastdeploy backend." << std::endl;
@@ -426,31 +426,31 @@ bool YOLOv5Lite::Predict(cv::Mat* im, DetectionResult* result,
static_cast<float>(mat.Width())}; static_cast<float>(mat.Width())};
if (use_cuda_preprocessing_) { if (use_cuda_preprocessing_) {
if (!CudaPreprocess(&mat, &reused_input_tensors[0], &im_info)) { if (!CudaPreprocess(&mat, &reused_input_tensors_[0], &im_info)) {
FDERROR << "Failed to preprocess input image." << std::endl; FDERROR << "Failed to preprocess input image." << std::endl;
return false; return false;
} }
} else { } else {
if (!Preprocess(&mat, &reused_input_tensors[0], &im_info)) { if (!Preprocess(&mat, &reused_input_tensors_[0], &im_info)) {
FDERROR << "Failed to preprocess input image." << std::endl; FDERROR << "Failed to preprocess input image." << std::endl;
return false; return false;
} }
} }
reused_input_tensors[0].name = InputInfoOfRuntime(0).name; reused_input_tensors_[0].name = InputInfoOfRuntime(0).name;
if (!Infer()) { if (!Infer()) {
FDERROR << "Failed to inference." << std::endl; FDERROR << "Failed to inference." << std::endl;
return false; return false;
} }
if (is_decode_exported) { if (is_decode_exported) {
if (!Postprocess(reused_output_tensors[0], result, im_info, conf_threshold, if (!Postprocess(reused_output_tensors_[0], result, im_info, conf_threshold,
nms_iou_threshold)) { nms_iou_threshold)) {
FDERROR << "Failed to post process." << std::endl; FDERROR << "Failed to post process." << std::endl;
return false; return false;
} }
} else { } else {
if (!PostprocessWithDecode(reused_output_tensors[0], result, im_info, if (!PostprocessWithDecode(reused_output_tensors_[0], result, im_info,
conf_threshold, nms_iou_threshold)) { conf_threshold, nms_iou_threshold)) {
FDERROR << "Failed to post process." << std::endl; FDERROR << "Failed to post process." << std::endl;
return false; return false;

10
fastdeploy/vision/detection/contrib/yolov6.cc Normal file → Executable file
View File

@@ -96,7 +96,7 @@ bool YOLOv6::Initialize() {
is_scale_up = false; is_scale_up = false;
stride = 32; stride = 32;
max_wh = 4096.0f; max_wh = 4096.0f;
reused_input_tensors.resize(1); reused_input_tensors_.resize(1);
if (!InitRuntime()) { if (!InitRuntime()) {
FDERROR << "Failed to initialize fastdeploy backend." << std::endl; FDERROR << "Failed to initialize fastdeploy backend." << std::endl;
@@ -311,24 +311,24 @@ bool YOLOv6::Predict(cv::Mat* im, DetectionResult* result, float conf_threshold,
static_cast<float>(mat.Width())}; static_cast<float>(mat.Width())};
if (use_cuda_preprocessing_) { if (use_cuda_preprocessing_) {
if (!CudaPreprocess(&mat, &reused_input_tensors[0], &im_info)) { if (!CudaPreprocess(&mat, &reused_input_tensors_[0], &im_info)) {
FDERROR << "Failed to preprocess input image." << std::endl; FDERROR << "Failed to preprocess input image." << std::endl;
return false; return false;
} }
} else { } else {
if (!Preprocess(&mat, &reused_input_tensors[0], &im_info)) { if (!Preprocess(&mat, &reused_input_tensors_[0], &im_info)) {
FDERROR << "Failed to preprocess input image." << std::endl; FDERROR << "Failed to preprocess input image." << std::endl;
return false; return false;
} }
} }
reused_input_tensors[0].name = InputInfoOfRuntime(0).name; reused_input_tensors_[0].name = InputInfoOfRuntime(0).name;
if (!Infer()) { if (!Infer()) {
FDERROR << "Failed to inference." << std::endl; FDERROR << "Failed to inference." << std::endl;
return false; return false;
} }
if (!Postprocess(reused_output_tensors[0], result, im_info, conf_threshold, if (!Postprocess(reused_output_tensors_[0], result, im_info, conf_threshold,
nms_iou_threshold)) { nms_iou_threshold)) {
FDERROR << "Failed to post process." << std::endl; FDERROR << "Failed to post process." << std::endl;
return false; return false;

10
fastdeploy/vision/detection/contrib/yolov7.cc Normal file → Executable file
View File

@@ -94,7 +94,7 @@ bool YOLOv7::Initialize() {
is_scale_up = false; is_scale_up = false;
stride = 32; stride = 32;
max_wh = 7680.0; max_wh = 7680.0;
reused_input_tensors.resize(1); reused_input_tensors_.resize(1);
if (!InitRuntime()) { if (!InitRuntime()) {
FDERROR << "Failed to initialize fastdeploy backend." << std::endl; FDERROR << "Failed to initialize fastdeploy backend." << std::endl;
@@ -313,24 +313,24 @@ bool YOLOv7::Predict(cv::Mat* im, DetectionResult* result, float conf_threshold,
static_cast<float>(mat.Width())}; static_cast<float>(mat.Width())};
if (use_cuda_preprocessing_) { if (use_cuda_preprocessing_) {
if (!CudaPreprocess(&mat, &reused_input_tensors[0], &im_info)) { if (!CudaPreprocess(&mat, &reused_input_tensors_[0], &im_info)) {
FDERROR << "Failed to preprocess input image." << std::endl; FDERROR << "Failed to preprocess input image." << std::endl;
return false; return false;
} }
} else { } else {
if (!Preprocess(&mat, &reused_input_tensors[0], &im_info)) { if (!Preprocess(&mat, &reused_input_tensors_[0], &im_info)) {
FDERROR << "Failed to preprocess input image." << std::endl; FDERROR << "Failed to preprocess input image." << std::endl;
return false; return false;
} }
} }
reused_input_tensors[0].name = InputInfoOfRuntime(0).name; reused_input_tensors_[0].name = InputInfoOfRuntime(0).name;
if (!Infer()) { if (!Infer()) {
FDERROR << "Failed to inference." << std::endl; FDERROR << "Failed to inference." << std::endl;
return false; return false;
} }
if (!Postprocess(reused_output_tensors[0], result, im_info, conf_threshold, if (!Postprocess(reused_output_tensors_[0], result, im_info, conf_threshold,
nms_iou_threshold)) { nms_iou_threshold)) {
FDERROR << "Failed to post process." << std::endl; FDERROR << "Failed to post process." << std::endl;
return false; return false;

View File

@@ -86,7 +86,7 @@ bool YOLOv7End2EndORT::Initialize() {
is_no_pad = false; is_no_pad = false;
is_scale_up = false; is_scale_up = false;
stride = 32; stride = 32;
reused_input_tensors.resize(1); reused_input_tensors_.resize(1);
if (!InitRuntime()) { if (!InitRuntime()) {
FDERROR << "Failed to initialize fastdeploy backend." << std::endl; FDERROR << "Failed to initialize fastdeploy backend." << std::endl;
@@ -224,18 +224,18 @@ bool YOLOv7End2EndORT::Predict(cv::Mat* im, DetectionResult* result,
im_info["output_shape"] = {static_cast<float>(mat.Height()), im_info["output_shape"] = {static_cast<float>(mat.Height()),
static_cast<float>(mat.Width())}; static_cast<float>(mat.Width())};
if (!Preprocess(&mat, &reused_input_tensors[0], &im_info)) { if (!Preprocess(&mat, &reused_input_tensors_[0], &im_info)) {
FDERROR << "Failed to preprocess input image." << std::endl; FDERROR << "Failed to preprocess input image." << std::endl;
return false; return false;
} }
reused_input_tensors[0].name = InputInfoOfRuntime(0).name; reused_input_tensors_[0].name = InputInfoOfRuntime(0).name;
if (!Infer()) { if (!Infer()) {
FDERROR << "Failed to inference." << std::endl; FDERROR << "Failed to inference." << std::endl;
return false; return false;
} }
if (!Postprocess(reused_output_tensors[0], result, im_info, conf_threshold)) { if (!Postprocess(reused_output_tensors_[0], result, im_info, conf_threshold)) {
FDERROR << "Failed to post process." << std::endl; FDERROR << "Failed to post process." << std::endl;
return false; return false;
} }

View File

@@ -106,7 +106,7 @@ bool YOLOv7End2EndTRT::Initialize() {
is_no_pad = false; is_no_pad = false;
is_scale_up = false; is_scale_up = false;
stride = 32; stride = 32;
reused_input_tensors.resize(1); reused_input_tensors_.resize(1);
if (!InitRuntime()) { if (!InitRuntime()) {
FDERROR << "Failed to initialize fastdeploy backend." << std::endl; FDERROR << "Failed to initialize fastdeploy backend." << std::endl;
@@ -320,24 +320,24 @@ bool YOLOv7End2EndTRT::Predict(cv::Mat* im, DetectionResult* result,
static_cast<float>(mat.Width())}; static_cast<float>(mat.Width())};
if (use_cuda_preprocessing_) { if (use_cuda_preprocessing_) {
if (!CudaPreprocess(&mat, &reused_input_tensors[0], &im_info)) { if (!CudaPreprocess(&mat, &reused_input_tensors_[0], &im_info)) {
FDERROR << "Failed to preprocess input image." << std::endl; FDERROR << "Failed to preprocess input image." << std::endl;
return false; return false;
} }
} else { } else {
if (!Preprocess(&mat, &reused_input_tensors[0], &im_info)) { if (!Preprocess(&mat, &reused_input_tensors_[0], &im_info)) {
FDERROR << "Failed to preprocess input image." << std::endl; FDERROR << "Failed to preprocess input image." << std::endl;
return false; return false;
} }
} }
reused_input_tensors[0].name = InputInfoOfRuntime(0).name; reused_input_tensors_[0].name = InputInfoOfRuntime(0).name;
if (!Infer()) { if (!Infer()) {
FDERROR << "Failed to inference." << std::endl; FDERROR << "Failed to inference." << std::endl;
return false; return false;
} }
if (!Postprocess(reused_output_tensors, result, im_info, conf_threshold)) { if (!Postprocess(reused_output_tensors_, result, im_info, conf_threshold)) {
FDERROR << "Failed to post process." << std::endl; FDERROR << "Failed to post process." << std::endl;
return false; return false;
} }

10
fastdeploy/vision/detection/contrib/yolox.cc Normal file → Executable file
View File

@@ -96,7 +96,7 @@ bool YOLOX::Initialize() {
downsample_strides = {8, 16, 32}; downsample_strides = {8, 16, 32};
max_wh = 4096.0f; max_wh = 4096.0f;
is_decode_exported = false; is_decode_exported = false;
reused_input_tensors.resize(1); reused_input_tensors_.resize(1);
if (!InitRuntime()) { if (!InitRuntime()) {
FDERROR << "Failed to initialize fastdeploy backend." << std::endl; FDERROR << "Failed to initialize fastdeploy backend." << std::endl;
@@ -290,25 +290,25 @@ bool YOLOX::Predict(cv::Mat* im, DetectionResult* result, float conf_threshold,
im_info["output_shape"] = {static_cast<float>(mat.Height()), im_info["output_shape"] = {static_cast<float>(mat.Height()),
static_cast<float>(mat.Width())}; static_cast<float>(mat.Width())};
if (!Preprocess(&mat, &reused_input_tensors[0], &im_info)) { if (!Preprocess(&mat, &reused_input_tensors_[0], &im_info)) {
FDERROR << "Failed to preprocess input image." << std::endl; FDERROR << "Failed to preprocess input image." << std::endl;
return false; return false;
} }
reused_input_tensors[0].name = InputInfoOfRuntime(0).name; reused_input_tensors_[0].name = InputInfoOfRuntime(0).name;
if (!Infer()) { if (!Infer()) {
FDERROR << "Failed to inference." << std::endl; FDERROR << "Failed to inference." << std::endl;
return false; return false;
} }
if (is_decode_exported) { if (is_decode_exported) {
if (!Postprocess(reused_output_tensors[0], result, im_info, conf_threshold, if (!Postprocess(reused_output_tensors_[0], result, im_info, conf_threshold,
nms_iou_threshold)) { nms_iou_threshold)) {
FDERROR << "Failed to post process." << std::endl; FDERROR << "Failed to post process." << std::endl;
return false; return false;
} }
} else { } else {
if (!PostprocessWithDecode(reused_output_tensors[0], result, im_info, if (!PostprocessWithDecode(reused_output_tensors_[0], result, im_info,
conf_threshold, nms_iou_threshold)) { conf_threshold, nms_iou_threshold)) {
FDERROR << "Failed to post process." << std::endl; FDERROR << "Failed to post process." << std::endl;
return false; return false;

6
fastdeploy/vision/detection/ppdet/ppyoloe.cc Normal file → Executable file
View File

@@ -55,7 +55,7 @@ bool PPYOLOE::Initialize() {
FDERROR << "Failed to initialize fastdeploy backend." << std::endl; FDERROR << "Failed to initialize fastdeploy backend." << std::endl;
return false; return false;
} }
reused_input_tensors.resize(2); reused_input_tensors_.resize(2);
return true; return true;
} }
@@ -252,7 +252,7 @@ bool PPYOLOE::Postprocess(std::vector<FDTensor>& infer_result,
bool PPYOLOE::Predict(cv::Mat* im, DetectionResult* result) { bool PPYOLOE::Predict(cv::Mat* im, DetectionResult* result) {
Mat mat(*im); Mat mat(*im);
if (!Preprocess(&mat, &reused_input_tensors)) { if (!Preprocess(&mat, &reused_input_tensors_)) {
FDERROR << "Failed to preprocess input data while using model:" FDERROR << "Failed to preprocess input data while using model:"
<< ModelName() << "." << std::endl; << ModelName() << "." << std::endl;
return false; return false;
@@ -264,7 +264,7 @@ bool PPYOLOE::Predict(cv::Mat* im, DetectionResult* result) {
return false; return false;
} }
if (!Postprocess(reused_output_tensors, result)) { if (!Postprocess(reused_output_tensors_, result)) {
FDERROR << "Failed to postprocess while using model:" << ModelName() << "." FDERROR << "Failed to postprocess while using model:" << ModelName() << "."
<< std::endl; << std::endl;
return false; return false;