[Doc]Add English version of documents in examples/ (#1042)

* 第一次提交

* 补充一处漏翻译

* deleted:    docs/en/quantize.md

* Update one translation

* Update en version

* Update one translation in code

* Standardize one writing

* Standardize one writing

* Update some en version

* Fix a grammer problem

* Update en version for api/vision result

* Merge branch 'develop' of https://github.com/charl-u/FastDeploy into develop

* Checkout the link in README in vision_results/ to the en documents

* Modify a title

* Add link to serving/docs/

* Finish translation of demo.md

* Update english version of serving/docs/

* Update title of readme

* Update some links

* Modify a title

* Update some links

* Update en version of java android README

* Modify some titles

* Modify some titles

* Modify some titles

* modify article to document

* update some english version of documents in examples

* Add english version of documents in examples/visions

* Sync to current branch

* Add english version of documents in examples
This commit is contained in:
charl-u
2023-01-06 09:35:12 +08:00
committed by GitHub
parent bb96a6fe8f
commit 1135d33dd7
74 changed files with 2312 additions and 575 deletions

View File

@@ -1,22 +1,23 @@
English | [简体中文](README_CN.md)
# C++推理
在运行demo前需确认以下两个步骤
Before running demo, the following two steps need to be confirmed:
- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../docs/cn/build_and_install/download_prebuilt_libraries.md)
- 2. 根据开发环境下载预编译部署库和samples代码参考[FastDeploy预编译库](../../../docs/cn/build_and_install/download_prebuilt_libraries.md)
- 1. Hardware and software environment meets the requirements. Please refer to [Environment requirements for FastDeploy](../../../docs/en/build_and_install/download_prebuilt_libraries.md).
- 2. Download pre-compiled libraries and samples according to the development environment. Please refer to [FastDeploy pre-compiled libraries](../../../docs/cn/build_and_install/download_prebuilt_libraries.md).
本文档以 PaddleClas 分类模型 MobileNetV2 为例展示CPU上的推理示例
This document shows an inference example on the CPU using the PaddleClas classification model MobileNetV2 as an example.
## 1. 获取模型
## 1. Obtaining the Model
```bash
wget https://bj.bcebos.com/fastdeploy/models/mobilenetv2.tgz
tar xvf mobilenetv2.tgz
```
## 2. 配置后端
## 2. Backend Configuration
如下C++代码保存为`infer_paddle_onnxruntime.cc`
The following C++ code is saved as `infer_paddle_onnxruntime.cc`.
``` c++
#include "fastdeploy/runtime.h"
@@ -66,35 +67,35 @@ int main(int argc, char* argv[]) {
return 0;
}
```
加载完成,会输出提示如下,说明初始化的后端,以及运行的硬件设备
When loading is complete, the following prompt will be output, indicating the initialized backend, and the running hardware devices.
```
[INFO] fastdeploy/fastdeploy_runtime.cc(283)::Init Runtime initialized with Backend::OrtBackend in device Device::CPU.
```
## 3. 准备CMakeLists.txt
## 3. Prepare for CMakeLists.txt
FastDeploy中包含多个依赖库,直接采用`g++`或编译器编译较为繁杂推荐使用cmake进行编译配置。示例配置如下
FastDeploy contains several dependencies, it is complicated to compile directly with `g++` or compiler, so we recommend using cmake for compiling configuration. The sample configuration is as follows:
```cmake
PROJECT(runtime_demo C CXX)
CMAKE_MINIMUM_REQUIRED (VERSION 3.12)
# 指定下载解压后的fastdeploy库路径
# Specify the path to the fastdeploy library after downloading and unpacking.
option(FASTDEPLOY_INSTALL_DIR "Path of downloaded fastdeploy sdk.")
include(${FASTDEPLOY_INSTALL_DIR}/FastDeploy.cmake)
# 添加FastDeploy依赖头文件
# Add FastDeploy dependency headers.
include_directories(${FASTDEPLOY_INCS})
add_executable(runtime_demo ${PROJECT_SOURCE_DIR}/infer_onnx_openvino.cc)
# 添加FastDeploy库依赖
# Adding FastDeploy library dependencies.
target_link_libraries(runtime_demo ${FASTDEPLOY_LIBS})
```
## 4. 编译可执行程序
## 4. Compile executable program
打开命令行终端,进入`infer_paddle_onnxruntime.cc``CMakeLists.txt`所在的目录,执行如下命令
Open the terminal, go to the directory where `infer_paddle_onnxruntime.cc` and `CMakeLists.txt` are located, and run the following command:
```bash
mkdir build & cd build
@@ -102,20 +103,20 @@ cmake .. -DFASTDEPLOY_INSTALL_DIR=$fastdeploy_cpp_sdk
make -j
```
```fastdeploy_cpp_sdk``` FastDeploy C++部署库路径
```fastdeploy_cpp_sdk``` is path to FastDeploy C++ deployment libraries.
编译完成后,使用如下命令执行可得到预测结果
After compiling, run the following command and get the results.
```bash
./runtime_demo
```
执行时如提示`error while loading shared libraries: libxxx.so: cannot open shared object file: No such file...`说明程序执行时没有找到FastDeploy的库路径可通过执行如下命令将FastDeploy的库路径添加到环境变量之后重新执行二进制程序。
If you are prompted with `error while loading shared libraries: libxxx.so: cannot open shared object file: No such file... `, it means that the path to FastDeploy libraries is not found, you can run the program again after adding the path to the environment variable by executing the following command.
```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)
This sample code is common on all platforms (Windows/Linux/Mac), but the compilation process is only supported on (Linux/Mac),while using msbuild to compile on Windows. Please refer to [FastDeploy C++ SDK on Windows](../../../docs/en/faq/use_sdk_on_windows.md).
## 其它文档
## Other Documents
- [Runtime Python 示例](../python)
- [切换模型推理的硬件和后端](../../../docs/cn/faq/how_to_change_backend.md)
- [A Python example for Runtime](../python)
- [Switching hardware and backend for model inference](../../../docs/en/faq/how_to_change_backend.md)

View File

@@ -0,0 +1,122 @@
简体中文 [English](README.md)
# 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)