未验证 提交 11357c0f 编写于 作者: T Tingquan Gao 提交者: GitHub

Modify the "cls_model_dir" to "cls_model_path" and "cls_params_path" (#411)

* Modify the "cls_model_dir" to "cls_model_path" and "cls_params_path"
上级 99549178
...@@ -36,7 +36,8 @@ namespace PaddleClas { ...@@ -36,7 +36,8 @@ namespace PaddleClas {
class Classifier { class Classifier {
public: public:
explicit Classifier(const std::string &model_dir, const bool &use_gpu, explicit Classifier(const std::string &model_path,
const std::string &params_path, const bool &use_gpu,
const int &gpu_id, const int &gpu_mem, const int &gpu_id, const int &gpu_mem,
const int &cpu_math_library_num_threads, const int &cpu_math_library_num_threads,
const bool &use_mkldnn, const int &resize_short_size, const bool &use_mkldnn, const int &resize_short_size,
...@@ -50,11 +51,11 @@ public: ...@@ -50,11 +51,11 @@ public:
this->resize_short_size_ = resize_short_size; this->resize_short_size_ = resize_short_size;
this->crop_size_ = crop_size; this->crop_size_ = crop_size;
LoadModel(model_dir); LoadModel(model_path, params_path);
} }
// Load Paddle inference model // Load Paddle inference model
void LoadModel(const std::string &model_dir); void LoadModel(const std::string &model_path, const std::string &params_path);
// Run predictor // Run predictor
void Run(cv::Mat &img); void Run(cv::Mat &img);
......
...@@ -41,7 +41,9 @@ public: ...@@ -41,7 +41,9 @@ public:
this->use_mkldnn = bool(stoi(config_map_["use_mkldnn"])); this->use_mkldnn = bool(stoi(config_map_["use_mkldnn"]));
this->cls_model_dir.assign(config_map_["cls_model_dir"]); this->cls_model_path.assign(config_map_["cls_model_path"]);
this->cls_params_path.assign(config_map_["cls_params_path"]);
this->resize_short_size = stoi(config_map_["resize_short_size"]); this->resize_short_size = stoi(config_map_["resize_short_size"]);
...@@ -58,7 +60,9 @@ public: ...@@ -58,7 +60,9 @@ public:
bool use_mkldnn = false; bool use_mkldnn = false;
std::string cls_model_dir; std::string cls_model_path;
std::string cls_params_path;
int resize_short_size = 256; int resize_short_size = 256;
int crop_size = 224; int crop_size = 224;
......
...@@ -120,13 +120,13 @@ build/fluid_inference_install_dir/ ...@@ -120,13 +120,13 @@ build/fluid_inference_install_dir/
#### 1.2.2 直接下载安装 #### 1.2.2 直接下载安装
* [Paddle预测库官网](https://www.paddlepaddle.org.cn/documentation/docs/zh/advanced_guide/inference_deployment/inference/build_and_install_lib_cn.html)上提供了不同cuda版本的Linux预测库,可以在官网查看并选择合适的预测库版本。 * [Paddle预测库官网](https://www.paddlepaddle.org.cn/documentation/docs/zh/advanced_guide/inference_deployment/inference/build_and_install_lib_cn.html)上提供了不同cuda版本的Linux预测库,可以在官网查看并选择合适的预测库版本,注意必须选择`develop`版本
`ubuntu14.04_cuda9.0_cudnn7_avx_mkl``1.8.4`版本为例,使用下述命令下载并解压: `ubuntu14.04_cuda9.0_cudnn7_avx_mkl``develop`版本为例,使用下述命令下载并解压:
```shell ```shell
wget https://paddle-inference-lib.bj.bcebos.com/1.8.4-gpu-cuda9-cudnn7-avx-mkl/fluid_inference.tgz wget https://paddle-inference-lib.bj.bcebos.com/latest-gpu-cuda9-cudnn7-avx-mkl/fluid_inference.tgz
tar -xvf fluid_inference.tgz tar -xvf fluid_inference.tgz
``` ```
...@@ -143,11 +143,10 @@ tar -xvf fluid_inference.tgz ...@@ -143,11 +143,10 @@ tar -xvf fluid_inference.tgz
``` ```
inference/ inference/
|--model |--cls_infer.pdmodel
|--params |--cls_infer.pdiparams
``` ```
**注意**:上述文件中,`model`文件存储了模型结构信息,`params`文件存储了模型参数信息。因此,在使用模型导出时,需将导出的`cls_infer.pdmodel`文件重命名为`model``cls_infer.pdiparams`文件重命名为`params` **注意**:上述文件中,`cls_infer.pdmodel`文件存储了模型结构信息,`cls_infer.pdiparams`文件存储了模型参数信息。注意两个文件的路径需要与配置文件`tools/config.txt`中的`cls_model_path``cls_params_path`参数对应一致。
### 2.2 编译PaddleClas C++预测demo ### 2.2 编译PaddleClas C++预测demo
......
...@@ -131,6 +131,7 @@ Among them, `paddle` is the Paddle library required for C++ prediction later, an ...@@ -131,6 +131,7 @@ Among them, `paddle` is the Paddle library required for C++ prediction later, an
* Different cuda versions of the Linux inference library (based on GCC 4.8.2) are provided on the * Different cuda versions of the Linux inference library (based on GCC 4.8.2) are provided on the
[Paddle Inference Library official website](https://www.paddlepaddle.org.cn/documentation/docs/en/advanced_guide/inference_deployment/inference/build_and_install_lib_en.html). You can view and select the appropriate version of the inference library on the official website. [Paddle Inference Library official website](https://www.paddlepaddle.org.cn/documentation/docs/en/advanced_guide/inference_deployment/inference/build_and_install_lib_en.html). You can view and select the appropriate version of the inference library on the official website.
* Please select the `develop` version.
* After downloading, use the following method to uncompress. * After downloading, use the following method to uncompress.
...@@ -149,11 +150,11 @@ Finally you can see the following files in the folder of `fluid_inference/`. ...@@ -149,11 +150,11 @@ Finally you can see the following files in the folder of `fluid_inference/`.
``` ```
inference/ inference/
|--model |--cls_infer.pdmodel
|--params |--cls_infer.pdiparams
``` ```
**NOTICE**: Among them, `model` file stores the model structure information and the `params` file stores the model parameter information.Therefore, you could rename the files name exported by [Model inference](../../tools/export_model.py). **NOTICE**: Among them, `cls_infer.pdmodel` file stores the model structure information and the `cls_infer.pdiparams` file stores the model parameter information.The paths of the two files need to correspond to the parameters of `cls_model_path` and `cls_params_path` in the configuration file `tools/config.txt`.
### 2.2 Compile PaddleClas C++ inference demo ### 2.2 Compile PaddleClas C++ inference demo
......
...@@ -16,9 +16,10 @@ ...@@ -16,9 +16,10 @@
namespace PaddleClas { namespace PaddleClas {
void Classifier::LoadModel(const std::string &model_dir) { void Classifier::LoadModel(const std::string &model_path,
const std::string &params_path) {
paddle_infer::Config config; paddle_infer::Config config;
config.SetModel(model_dir + "/model", model_dir + "/params"); config.SetModel(model_path, params_path);
if (this->use_gpu_) { if (this->use_gpu_) {
config.EnableUseGpu(this->gpu_mem_, this->gpu_id_); config.EnableUseGpu(this->gpu_mem_, this->gpu_id_);
......
...@@ -59,10 +59,10 @@ int main(int argc, char **argv) { ...@@ -59,10 +59,10 @@ int main(int argc, char **argv) {
std::cout << "img_file_list length: " << img_files_list.size() << std::endl; std::cout << "img_file_list length: " << img_files_list.size() << std::endl;
Classifier classifier(config.cls_model_dir, config.use_gpu, config.gpu_id, Classifier classifier(config.cls_model_path, config.cls_params_path,
config.gpu_mem, config.cpu_math_library_num_threads, config.use_gpu, config.gpu_id, config.gpu_mem,
config.use_mkldnn, config.resize_short_size, config.cpu_math_library_num_threads, config.use_mkldnn,
config.crop_size); config.resize_short_size, config.crop_size);
double elapsed_time = 0.0; double elapsed_time = 0.0;
int warmup_iter = img_files_list.size() > 5 ? 5 : 0; int warmup_iter = img_files_list.size() > 5 ? 5 : 0;
......
OPENCV_DIR=/PaddleClas/PaddleOCR/opencv-3.4.7/opencv3/ OPENCV_DIR=/PaddleClas/opencv-3.4.7/opencv3/
LIB_DIR=/PaddleClas/PaddleOCR/fluid_inference/ LIB_DIR=/PaddleClas/fluid_inference/
CUDA_LIB_DIR=/usr/local/cuda/lib64 CUDA_LIB_DIR=/usr/local/cuda/lib64
CUDNN_LIB_DIR=/usr/lib/x86_64-linux-gnu/ CUDNN_LIB_DIR=/usr/lib/x86_64-linux-gnu/
......
...@@ -6,6 +6,7 @@ cpu_math_library_num_threads 10 ...@@ -6,6 +6,7 @@ cpu_math_library_num_threads 10
use_mkldnn 1 use_mkldnn 1
# cls config # cls config
cls_model_dir ./inference/ cls_model_path /PaddleClas/inference/cls_infer.pdmodel
cls_params_path /PaddleClas/inference/cls_infer.pdiparams
resize_short_size 256 resize_short_size 256
crop_size 224 crop_size 224
./build/clas_system ./tools/config.txt ./docs/imgs/ILSVRC2012_val_00000666.JPEG ./build/clas_system ./tools/config.txt ./docs/imgs/ILSVRC2012_val_00000666.JPEG
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册