未验证 提交 0a7ca236 编写于 作者: W Walter 提交者: GitHub

Merge pull request #2245 from HydrogenSulfate/update_ShiTu_doc

Add&Update PP-ShiTuV2 docs
...@@ -22,7 +22,7 @@ PreProcess: ...@@ -22,7 +22,7 @@ PreProcess:
scale: 0.00392157 scale: 0.00392157
mean: [0.485, 0.456, 0.406] mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225] std: [0.229, 0.224, 0.225]
order: '' order: ""
channel_num: 3 channel_num: 3
- ToCHWImage: - ToCHWImage:
......
...@@ -6,7 +6,7 @@ Global: ...@@ -6,7 +6,7 @@ Global:
threshold: 0.2 threshold: 0.2
max_det_results: 1 max_det_results: 1
label_list: label_list:
- foreground - foreground
# inference engine config # inference engine config
use_gpu: True use_gpu: True
...@@ -30,5 +30,5 @@ DetPreProcess: ...@@ -30,5 +30,5 @@ DetPreProcess:
mean: [0.485, 0.456, 0.406] mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225] std: [0.229, 0.224, 0.225]
- DetPermute: {} - DetPermute: {}
DetPostProcess: {} DetPostProcess: {}
\ No newline at end of file
Global: Global:
infer_imgs: "./drink_dataset_v1.0/test_images/hongniu_1.jpg" infer_imgs: "./drink_dataset_v2.0/test_images/100.jpeg"
det_inference_model_dir: "./models/picodet_PPLCNet_x2_5_mainbody_lite_v1.0_infer" det_inference_model_dir: "./models/picodet_PPLCNet_x2_5_mainbody_lite_v1.0_infer"
rec_inference_model_dir: "./models/general_PPLCNet_x2_5_lite_v1.0_infer" rec_inference_model_dir: "./models/general_PPLCNetV2_base_pretrained_v1.0_infer"
rec_nms_thresold: 0.05 rec_nms_thresold: 0.05
batch_size: 1 batch_size: 1
...@@ -9,7 +9,7 @@ Global: ...@@ -9,7 +9,7 @@ Global:
threshold: 0.2 threshold: 0.2
max_det_results: 5 max_det_results: 5
label_list: label_list:
- foreground - foreground
use_gpu: True use_gpu: True
enable_mkldnn: False enable_mkldnn: False
...@@ -43,7 +43,7 @@ RecPreProcess: ...@@ -43,7 +43,7 @@ RecPreProcess:
scale: 0.00392157 scale: 0.00392157
mean: [0.485, 0.456, 0.406] mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225] std: [0.229, 0.224, 0.225]
order: '' order: ""
- ToCHWImage: - ToCHWImage:
RecPostProcess: null RecPostProcess: null
...@@ -51,13 +51,13 @@ RecPostProcess: null ...@@ -51,13 +51,13 @@ RecPostProcess: null
# indexing engine config # indexing engine config
IndexProcess: IndexProcess:
index_method: "HNSW32" # supported: HNSW32, IVF, Flat index_method: "HNSW32" # supported: HNSW32, IVF, Flat
image_root: "./drink_dataset_v1.0/gallery" image_root: "./drink_dataset_v2.0/gallery"
index_dir: "./drink_dataset_v1.0/index" index_dir: "./drink_dataset_v2.0/index"
data_file: "./drink_dataset_v1.0/gallery/drink_label.txt" data_file: "./drink_dataset_v2.0/gallery/drink_label.txt"
index_operation: "new" # suported: "append", "remove", "new" index_operation: "new" # suported: "append", "remove", "new"
delimiter: "\t" delimiter: "\t"
dist_type: "IP" dist_type: "IP"
embedding_size: 512 embedding_size: 512
batch_size: 32 batch_size: 32
return_k: 5 return_k: 5
score_thres: 0.4 score_thres: 0.4
\ No newline at end of file
Global: Global:
infer_imgs: "./drink_dataset_v1.0/test_images/nongfu_spring.jpeg" infer_imgs: "./drink_dataset_v2.0/test_images/100.jpeg"
det_inference_model_dir: "./models/picodet_PPLCNet_x2_5_mainbody_lite_v1.0_infer" det_inference_model_dir: "./models/picodet_PPLCNet_x2_5_mainbody_lite_v1.0_infer"
rec_inference_model_dir: "./models/general_PPLCNet_x2_5_lite_v1.0_infer" rec_inference_model_dir: "./models/general_PPLCNetV2_base_pretrained_v1.0_infer"
rec_nms_thresold: 0.05 rec_nms_thresold: 0.05
batch_size: 1 batch_size: 1
...@@ -9,7 +9,7 @@ Global: ...@@ -9,7 +9,7 @@ Global:
threshold: 0.2 threshold: 0.2
max_det_results: 5 max_det_results: 5
label_list: label_list:
- foreground - foreground
use_gpu: True use_gpu: True
enable_mkldnn: True enable_mkldnn: True
...@@ -38,12 +38,15 @@ DetPostProcess: {} ...@@ -38,12 +38,15 @@ DetPostProcess: {}
RecPreProcess: RecPreProcess:
transform_ops: transform_ops:
- ResizeImage: - ResizeImage:
size: 224 size: [224, 224]
return_numpy: False
interpolation: bilinear
backend: cv2
- NormalizeImage: - NormalizeImage:
scale: 0.00392157 scale: 1.0/255.0
mean: [0.485, 0.456, 0.406] mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225] std: [0.229, 0.224, 0.225]
order: '' order: hwc
- ToCHWImage: - ToCHWImage:
RecPostProcess: null RecPostProcess: null
...@@ -51,13 +54,13 @@ RecPostProcess: null ...@@ -51,13 +54,13 @@ RecPostProcess: null
# indexing engine config # indexing engine config
IndexProcess: IndexProcess:
index_method: "HNSW32" # supported: HNSW32, IVF, Flat index_method: "HNSW32" # supported: HNSW32, IVF, Flat
image_root: "./drink_dataset_v1.0/gallery/" image_root: "./drink_dataset_v2.0/gallery/"
index_dir: "./drink_dataset_v1.0/index" index_dir: "./drink_dataset_v2.0/index"
data_file: "./drink_dataset_v1.0/gallery/drink_label.txt" data_file: "./drink_dataset_v2.0/gallery/drink_label.txt"
index_operation: "new" # suported: "append", "remove", "new" index_operation: "new" # suported: "append", "remove", "new"
delimiter: "\t" delimiter: "\t"
dist_type: "IP" dist_type: "IP"
embedding_size: 512 embedding_size: 512
batch_size: 32 batch_size: 32
return_k: 5 return_k: 5
score_thres: 0.5 score_thres: 0.5
\ No newline at end of file
Global: Global:
infer_imgs: "./images/wangzai.jpg" infer_imgs: "./images/wangzai.jpg"
rec_inference_model_dir: "./models/product_ResNet50_vd_aliproduct_v1.0_infer" rec_inference_model_dir: "./models/general_PPLCNetV2_base_pretrained_v1.0_infer"
batch_size: 1 batch_size: 1
use_gpu: False use_gpu: False
enable_mkldnn: True enable_mkldnn: True
...@@ -22,7 +22,7 @@ RecPreProcess: ...@@ -22,7 +22,7 @@ RecPreProcess:
scale: 0.00392157 scale: 0.00392157
mean: [0.485, 0.456, 0.406] mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225] std: [0.229, 0.224, 0.225]
order: '' order: ""
- ToCHWImage: - ToCHWImage:
RecPostProcess: null RecPostProcess: null
\ No newline at end of file
# 服务器端C++预测 # 服务器端C++预测
本教程将介绍在服务器端部署PP-ShiTU的详细步骤。 本教程将介绍在服务器端部署PP-ShiTu的详细步骤。
## 目录 ## 目录
...@@ -30,39 +30,39 @@ ...@@ -30,39 +30,39 @@
- 下载最新版本cmake - 下载最新版本cmake
```shell ```shell
# 当前版本最新为3.22.0,根据实际情况自行下载,建议最新版本 # 当前版本最新为3.22.0,根据实际情况自行下载,建议最新版本
wget https://github.com/Kitware/CMake/releases/download/v3.22.0/cmake-3.22.0.tar.gz wget https://github.com/Kitware/CMake/releases/download/v3.22.0/cmake-3.22.0.tar.gz
tar xf cmake-3.22.0.tar.gz tar -xf cmake-3.22.0.tar.gz
``` ```
最终可以在当前目录下看到`cmake-3.22.0/`的文件夹。 最终可以在当前目录下看到`cmake-3.22.0/`的文件夹。
- 编译cmake,首先设置came源码路径(`root_path`)以及安装路径(`install_path`),`root_path`为下载的came源码路径,`install_path`为came的安装路径。在本例中,源码路径即为当前目录下的`cmake-3.22.0/` - 编译cmake,首先设置cmake源码路径(`root_path`)以及安装路径(`install_path`),`root_path`为下载的cmake源码路径,`install_path`为cmake的安装路径。在本例中,源码路径即为当前目录下的`cmake-3.22.0/`
```shell ```shell
cd ./cmake-3.22.0 cd ./cmake-3.22.0
export root_path=$PWD export root_path=$PWD
export install_path=${root_path}/cmake export install_path=${root_path}/cmake
``` ```
- 然后在cmake源码路径下,按照下面的方式进行编译 - 然后在cmake源码路径下,执行以下命令进行编译
```shell ```shell
./bootstrap --prefix=${install_path} ./bootstrap --prefix=${install_path}
make -j make -j
make install make install
``` ```
- 设置环境变量 - 编译安装cmake完成后,设置cmake的环境变量供后续程序使用
```shell ```shell
export PATH=${install_path}/bin:$PATH export PATH=${install_path}/bin:$PATH
#检查是否正常使用 #检查是否正常使用
cmake --version cmake --version
``` ```
此时,cmake就可以使用了 此时cmake就可以正常使用了
<a name="1.2"></a> <a name="1.2"></a>
...@@ -70,61 +70,66 @@ cmake --version ...@@ -70,61 +70,66 @@ cmake --version
* 首先需要从opencv官网上下载在Linux环境下源码编译的包,以3.4.7版本为例,下载及解压缩命令如下: * 首先需要从opencv官网上下载在Linux环境下源码编译的包,以3.4.7版本为例,下载及解压缩命令如下:
``` ```shell
wget https://github.com/opencv/opencv/archive/3.4.7.tar.gz wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/opencv-3.4.7.tar.gz
tar -xvf 3.4.7.tar.gz tar -xvf 3.4.7.tar.gz
``` ```
最终可以在当前目录下看到`opencv-3.4.7/`的文件夹。 最终可以在当前目录下看到`opencv-3.4.7/`的文件夹。
* 编译opencv,首先设置opencv源码路径(`root_path`)以及安装路径(`install_path`),`root_path`为下载的opencv源码路径,`install_path`为opencv的安装路径。在本例中,源码路径即为当前目录下的`opencv-3.4.7/` * 编译opencv,首先设置opencv源码路径(`root_path`)以及安装路径(`install_path`),`root_path`为下载的opencv源码路径,`install_path`为opencv的安装路径。在本例中,源码路径即为当前目录下的`opencv-3.4.7/`
```shell ```shell
cd ./opencv-3.4.7 # 进入deploy/cpp_shitu目录
export root_path=$PWD cd deploy/cpp_shitu
export install_path=${root_path}/opencv3
```
* 然后在opencv源码路径下,按照下面的方式进行编译。
```shell # 安装opencv
rm -rf build cd ./opencv-3.4.7
mkdir build export root_path=$PWD
cd build export install_path=${root_path}/opencv3
```
cmake .. \ * 然后在opencv源码路径下,按照下面的方式进行编译。
-DCMAKE_INSTALL_PREFIX=${install_path} \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=OFF \
-DWITH_IPP=OFF \
-DBUILD_IPP_IW=OFF \
-DWITH_LAPACK=OFF \
-DWITH_EIGEN=OFF \
-DCMAKE_INSTALL_LIBDIR=lib64 \
-DWITH_ZLIB=ON \
-DBUILD_ZLIB=ON \
-DWITH_JPEG=ON \
-DBUILD_JPEG=ON \
-DWITH_PNG=ON \
-DBUILD_PNG=ON \
-DWITH_TIFF=ON \
-DBUILD_TIFF=ON
make -j ```shell
make install rm -rf build
``` mkdir build
cd build
cmake .. \
-DCMAKE_INSTALL_PREFIX=${install_path} \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=OFF \
-DWITH_IPP=OFF \
-DBUILD_IPP_IW=OFF \
-DWITH_LAPACK=OFF \
-DWITH_EIGEN=OFF \
-DCMAKE_INSTALL_LIBDIR=lib64 \
-DWITH_ZLIB=ON \
-DBUILD_ZLIB=ON \
-DWITH_JPEG=ON \
-DBUILD_JPEG=ON \
-DWITH_PNG=ON \
-DBUILD_PNG=ON \
-DWITH_TIFF=ON \
-DBUILD_TIFF=ON
make -j
make install
```
* `make install`完成之后,会在该文件夹下生成opencv头文件和库文件,用于后面的PaddleClas代码编译。 * `make install`完成之后,会在该文件夹下生成opencv头文件和库文件,用于后面的PaddleClas代码编译。
以opencv3.4.7版本为例,最终在安装路径下的文件结构如下所示。**注意**:不同的opencv版本,下述的文件结构可能不同。 以opencv3.4.7版本为例,最终在安装路径下的文件结构如下所示。**注意**:不同的opencv版本,下述的文件结构可能不同。
``` ```log
opencv3/ opencv3/
|-- bin ├── bin
|-- include ├── include
|-- lib64 ├── lib
|-- share ├── lib64
``` └── share
```
<a name="1.3"></a> <a name="1.3"></a>
...@@ -139,44 +144,48 @@ opencv3/ ...@@ -139,44 +144,48 @@ opencv3/
* 如果希望获取最新预测库特性,可以从Paddle github上克隆最新代码,源码编译预测库。 * 如果希望获取最新预测库特性,可以从Paddle github上克隆最新代码,源码编译预测库。
* 可以参考[Paddle预测库官网](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/guides/05_inference_deployment/inference/build_and_install_lib_cn.html#id16)的说明,从github上获取Paddle代码,然后进行编译,生成最新的预测库。使用git获取代码方法如下。 * 可以参考[Paddle预测库官网](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/guides/05_inference_deployment/inference/build_and_install_lib_cn.html#id16)的说明,从github上获取Paddle代码,然后进行编译,生成最新的预测库。使用git获取代码方法如下。
```shell ```shell
git clone https://github.com/PaddlePaddle/Paddle.git # 进入deploy/cpp_shitu目录
``` cd deploy/cpp_shitu
* 进入Paddle目录后,使用如下方法编译。 git clone https://github.com/PaddlePaddle/Paddle.git
```
```shell * 进入Paddle目录后,使用如下方法编译。
rm -rf build
mkdir build
cd build
cmake .. \ ```shell
-DWITH_CONTRIB=OFF \ rm -rf build
-DWITH_MKL=ON \ mkdir build
-DWITH_MKLDNN=ON \ cd build
-DWITH_TESTING=OFF \
-DCMAKE_BUILD_TYPE=Release \ cmake .. \
-DWITH_INFERENCE_API_TEST=OFF \ -DWITH_CONTRIB=OFF \
-DON_INFER=ON \ -DWITH_MKL=ON \
-DWITH_PYTHON=ON -DWITH_MKLDNN=ON \
make -j -DWITH_TESTING=OFF \
make inference_lib_dist -DCMAKE_BUILD_TYPE=Release \
``` -DWITH_INFERENCE_API_TEST=OFF \
-DON_INFER=ON \
-DWITH_PYTHON=ON
make -j
make inference_lib_dist
```
更多编译参数选项可以参考[Paddle C++预测库官网](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/guides/05_inference_deployment/inference/build_and_install_lib_cn.html#id16) 更多编译参数选项可以参考[Paddle C++预测库官网](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/guides/05_inference_deployment/inference/build_and_install_lib_cn.html#id16)
* 编译完成之后,可以在`build/paddle_inference_install_dir/`文件下看到生成了以下文件及文件夹。 * 编译完成之后,可以在`build/paddle_inference_install_dir/`文件下看到生成了以下文件及文件夹。
``` ```log
build/paddle_inference_install_dir/ build/paddle_inference_install_dir/
|-- CMakeCache.txt ├── CMakeCache.txt
|-- paddle ├── paddle
|-- third_party ├── third_party
|-- version.txt └── version.txt
``` ```
其中`paddle`就是之后进行C++预测时所需的Paddle库,`version.txt`中包含当前预测库的版本信息。 其中`paddle`就是之后进行C++预测时所需的Paddle库,`version.txt`中包含当前预测库的版本信息。
<a name="1.3.2"></a> <a name="1.3.2"></a>
...@@ -187,33 +196,41 @@ build/paddle_inference_install_dir/ ...@@ -187,33 +196,41 @@ build/paddle_inference_install_dir/
`https://paddle-inference-lib.bj.bcebos.com/2.1.1-gpu-cuda10.2-cudnn8.1-mkl-gcc8.2/paddle_inference.tgz``develop`版本为例,使用下述命令下载并解压: `https://paddle-inference-lib.bj.bcebos.com/2.1.1-gpu-cuda10.2-cudnn8.1-mkl-gcc8.2/paddle_inference.tgz``develop`版本为例,使用下述命令下载并解压:
```shell ```shell
wget https://paddle-inference-lib.bj.bcebos.com/2.1.1-gpu-cuda10.2-cudnn8.1-mkl-gcc8.2/paddle_inference.tgz # 进入deploy/cpp_shitu目录
cd deploy/cpp_shitu
tar -xvf paddle_inference.tgz wget https://paddle-inference-lib.bj.bcebos.com/2.1.1-gpu-cuda10.2-cudnn8.1-mkl-gcc8.2/paddle_inference.tgz
```
tar -xvf paddle_inference.tgz
```
最终会在当前的文件夹中生成`paddle_inference/`的子文件夹。 最终会在当前的文件夹中生成`paddle_inference/`的子文件夹。
<a name="1.4"></a> <a name="1.4"></a>
### 1.4 安装faiss库 ### 1.4 安装faiss库
在安装`faiss`前,请安装`openblas``ubuntu`系统中安装命令如下:
```shell ```shell
# 下载 faiss apt-get install libopenblas-dev
git clone https://github.com/facebookresearch/faiss.git
cd faiss
export faiss_install_path=$PWD/faiss_install
cmake -B build . -DFAISS_ENABLE_PYTHON=OFF -DCMAKE_INSTALL_PREFIX=${faiss_install_path}
make -C build -j faiss
make -C build install
``` ```
在安装`faiss`前,请安装`openblas``ubuntu`系统中安装命令如下: 然后按照以下命令编译并安装faiss
```shell ```shell
apt-get install libopenblas-dev # 进入deploy/cpp_shitu目录
cd deploy/cpp_shitu
# 下载 faiss
git clone https://github.com/facebookresearch/faiss.git
cd faiss
export faiss_install_path=$PWD/faiss_install
cmake -B build . -DFAISS_ENABLE_PYTHON=OFF -DCMAKE_INSTALL_PREFIX=${faiss_install_path}
make -C build -j faiss
make -C build install
``` ```
注意本教程以安装faiss cpu版本为例,安装时请参考[faiss](https://github.com/facebookresearch/faiss)官网文档,根据需求自行安装。 注意本教程以安装faiss cpu版本为例,安装时请参考[faiss](https://github.com/facebookresearch/faiss)官网文档,根据需求自行安装。
...@@ -224,12 +241,14 @@ apt-get install libopenblas-dev ...@@ -224,12 +241,14 @@ apt-get install libopenblas-dev
编译命令如下,其中Paddle C++预测库、opencv等其他依赖库的地址需要换成自己机器上的实际地址。同时,编译过程中需要下载编译`yaml-cpp`等C++库,请保持联网环境。 编译命令如下,其中Paddle C++预测库、opencv等其他依赖库的地址需要换成自己机器上的实际地址。同时,编译过程中需要下载编译`yaml-cpp`等C++库,请保持联网环境。
```shell ```shell
# 进入deploy/cpp_shitu目录
cd deploy/cpp_shitu
sh tools/build.sh sh tools/build.sh
``` ```
具体地,`tools/build.sh`中内容如下,请根据具体路径修改。 具体地,`tools/build.sh`中内容如下,请根据具体路径和配置情况进行修改。
```shell ```shell
OPENCV_DIR=${opencv_install_dir} OPENCV_DIR=${opencv_install_dir}
...@@ -261,14 +280,13 @@ cd .. ...@@ -261,14 +280,13 @@ cd ..
上述命令中, 上述命令中,
* `OPENCV_DIR`为opencv编译安装的地址(本例中为`opencv-3.4.7/opencv3`文件夹的路径); * `OPENCV_DIR`:opencv编译安装的地址(本例中为`opencv-3.4.7/opencv3`文件夹的路径);
* `LIB_DIR`为下载的Paddle预测库(`paddle_inference`文件夹),或编译生成的Paddle预测库(`build/paddle_inference_install_dir`文件夹)的路径; * `LIB_DIR`:下载的Paddle预测库(`paddle_inference`文件夹),或编译生成的Paddle预测库(`build/paddle_inference_install_dir`文件夹)的路径;
* `CUDA_LIB_DIR`为cuda库文件地址,在docker中为`/usr/local/cuda/lib64` * `CUDA_LIB_DIR`:cuda库文件地址,在docker中为`/usr/local/cuda/lib64`
* `CUDNN_LIB_DIR`为cudnn库文件地址,在docker中为`/usr/lib/x86_64-linux-gnu/` * `CUDNN_LIB_DIR`:cudnn库文件地址,在docker中为`/usr/lib/x86_64-linux-gnu/`
* `TENSORRT_DIR`是tensorrt库文件地址,在dokcer中为`/usr/local/TensorRT6-cuda10.0-cudnn7/`,TensorRT需要结合GPU使用。 * `TENSORRT_DIR`:tensorrt库文件地址,在dokcer中为`/usr/local/TensorRT6-cuda10.0-cudnn7/`,TensorRT需要结合GPU使用。
* `FAISS_DIR`是faiss的安装地址 * `FAISS_DIR`:faiss的安装地址
* `FAISS_WITH_MKL`是指在编译faiss的过程中,是否使用了mkldnn,本文档中编译faiss,没有使用,而使用了openblas,故设置为`OFF`,若使用了mkldnn,则为`ON`. * `FAISS_WITH_MKL`:指在编译faiss的过程中是否使用mkldnn,本文档中编译faiss没有使用,而使用了openblas,故设置为`OFF`,若使用了mkldnn则为`ON`.
在执行上述命令,编译完成之后,会在当前路径下生成`build`文件夹,其中生成一个名为`pp_shitu`的可执行文件。 在执行上述命令,编译完成之后,会在当前路径下生成`build`文件夹,其中生成一个名为`pp_shitu`的可执行文件。
...@@ -276,60 +294,68 @@ cd .. ...@@ -276,60 +294,68 @@ cd ..
## 3. 运行demo ## 3. 运行demo
- 请参考[识别快速开始文档](../../docs/zh_CN/quick_start/quick_start_recognition.md),下载好相应的 轻量级通用主体检测模型、轻量级通用识别模型及瓶装饮料测试数据并解压。 - 按照如下命令下载好相应的轻量级通用主体检测模型、轻量级通用识别模型及瓶装饮料测试数据并解压。
```shell ```shell
# 进入deploy目录
cd deploy/
mkdir models mkdir models
cd models cd models
# 下载并解压主体检测模型
wget https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/models/inference/picodet_PPLCNet_x2_5_mainbody_lite_v1.0_infer.tar wget https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/models/inference/picodet_PPLCNet_x2_5_mainbody_lite_v1.0_infer.tar
tar -xf picodet_PPLCNet_x2_5_mainbody_lite_v1.0_infer.tar tar -xf picodet_PPLCNet_x2_5_mainbody_lite_v1.0_infer.tar
wget https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/models/inference/general_PPLCNet_x2_5_lite_v1.0_infer.tar
tar -xf general_PPLCNet_x2_5_lite_v1.0_infer.tar # 下载并解压特征提取模型
wget https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/models/inference/PP-ShiTuV2/general_PPLCNetV2_base_pretrained_v1.0_infer.tar
tar -xf general_PPLCNetV2_base_pretrained_v1.0_infer.tar
cd .. cd ..
mkdir data mkdir data
cd data cd data
wget https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/data/drink_dataset_v1.0.tar wget https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/data/drink_dataset_v2.0.tar
tar -xf drink_dataset_v1.0.tar tar -xf drink_dataset_v2.0.tar
cd .. cd ..
``` ```
- 将相应的yaml文件拷到当前文件夹下 - 将相应的yaml文件拷到当前文件夹下
```shell ```shell
cp ../configs/inference_drink.yaml . cp ../configs/inference_drink.yaml ./
``` ```
-`inference_drink.yaml`中的相对路径,改成基于本目录的路径或者绝对路径。涉及到的参数有 -`inference_drink.yaml`中的相对路径,改成基于 `deploy/cpp_shitu` 目录的相对路径或者绝对路径。涉及到的参数有
- Global.infer_imgs :此参数可以是具体的图像地址,也可以是图像集所在的目录 - `Global.infer_imgs` :此参数可以是具体的图像地址,也可以是图像集所在的目录
- Global.det_inference_model_dir : 检测模型存储目录 - `Global.det_inference_model_dir` : 检测模型存储目录
- Global.rec_inference_model_dir : 识别模型存储目录 - `Global.rec_inference_model_dir` : 识别模型存储目录
- IndexProcess.index_dir : 检索库的存储目录,在示例中,检索库在下载的demo数据中。 - `IndexProcess.index_dir` : 检索库的存储目录,在示例中,检索库在下载的demo数据中。
- 字典转换 - 标签文件转换
由于python的检索库的字典,使用`pickle`进行的序列化存储,导致C++不方便读取,因此进行转换 由于python的检索库的字典是使用`pickle`转换得到的序列化存储结果,导致C++不方便读取,因此需要先转换成普通的文本文件。
```shell ```shell
python tools/transform_id_map.py -c inference_drink.yaml python3.7 tools/transform_id_map.py -c inference_drink.yaml
``` ```
转换成功后,在`IndexProcess.index_dir`目录下生成`id_map.txt`方便c++ 读取。 转换成功后,在`IndexProcess.index_dir`目录下生成`id_map.txt`以便在C++推理时读取。
- 执行程序 - 执行程序
```shell ```shell
./build/pp_shitu -c inference_drink.yaml ./build/pp_shitu -c inference_drink.yaml
# or
./build/pp_shitu -config inference_drink.yaml
``` ```
若对图像集进行检索,则可能得到,如下结果。注意,此结果只做展示,具体以实际运行结果为准。 `drink_dataset_v2.0/test_images/nongfu_spring.jpeg` 作为输入图像,则执行上述推理命令可以得到如下结果
同时,需注意的是,由于opencv 版本问题,会导致图像在预处理的过程中,resize产生细微差别,导致python 和c++结果,轻微不同,如bbox相差几个像素,检索结果小数点后3位diff等。但不会改变最终检索label。 ```log
../../deploy/drink_dataset_v2.0/test_images/nongfu_spring.jpeg:
result0: bbox[0, 0, 729, 1094], score: 0.688691, label: 农夫山泉-饮用天然水
```
![](../../docs/images/quick_start/shitu_c++_result.png) 由于python和C++的opencv实现存在部分不同,可能导致python推理和C++推理结果有微小差异。但基本不影响最终的检索结果。
<a name="4"></a> <a name="4"></a>
......
...@@ -16,9 +16,8 @@ op: ...@@ -16,9 +16,8 @@ op:
#当op配置没有server_endpoints时,从local_service_conf读取本地服务配置 #当op配置没有server_endpoints时,从local_service_conf读取本地服务配置
local_service_conf: local_service_conf:
#uci模型路径 #uci模型路径
model_config: ../../models/general_PPLCNet_x2_5_lite_v1.0_serving model_config: ../../models/general_PPLCNetV2_base_pretrained_v1.0_serving
#计算硬件类型: 空缺时由devices决定(CPU/GPU),0=cpu, 1=gpu, 2=tensorRT, 3=arm cpu, 4=kunlun xpu #计算硬件类型: 空缺时由devices决定(CPU/GPU),0=cpu, 1=gpu, 2=tensorRT, 3=arm cpu, 4=kunlun xpu
device_type: 1 device_type: 1
...@@ -37,7 +36,7 @@ op: ...@@ -37,7 +36,7 @@ op:
local_service_conf: local_service_conf:
client_type: local_predictor client_type: local_predictor
device_type: 1 device_type: 1
devices: '0' devices: "0"
fetch_list: fetch_list:
- save_infer_model/scale_0.tmp_1 - save_infer_model/scale_0.tmp_1
model_config: ../../models/picodet_PPLCNet_x2_5_mainbody_lite_v1.0_serving/ model_config: ../../models/picodet_PPLCNet_x2_5_mainbody_lite_v1.0_serving/
import requests
import json
import base64 import base64
import json
import os import os
imgpath = "../../drink_dataset_v1.0/test_images/001.jpeg" import requests
imgpath = "../../drink_dataset_v2.0/test_images/001.jpeg"
def cv2_to_base64(image): def cv2_to_base64(image):
return base64.b64encode(image).decode('utf8') return base64.b64encode(image).decode('utf8')
if __name__ == "__main__": if __name__ == "__main__":
url = "http://127.0.0.1:18081/recognition/prediction" url = "http://127.0.0.1:18081/recognition/prediction"
with open(os.path.join(".", imgpath), 'rb') as file: with open(os.path.join(".", imgpath), 'rb') as file:
image_data1 = file.read() image_data1 = file.read()
image = cv2_to_base64(image_data1) image = cv2_to_base64(image_data1)
data = {"key": ["image"], "value": [image]} data = {"key": ["image"], "value": [image]}
......
...@@ -11,17 +11,24 @@ ...@@ -11,17 +11,24 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from paddle_serving_server.web_service import WebService, Op import base64
import json
import logging import logging
import numpy as np import os
import pickle
import sys import sys
import cv2 import cv2
from paddle_serving_app.reader import *
import base64
import os
import faiss import faiss
import pickle import numpy as np
import json from paddle_serving_app.reader import BGR2RGB
from paddle_serving_app.reader import Div
from paddle_serving_app.reader import Normalize
from paddle_serving_app.reader import RCNNPostprocess
from paddle_serving_app.reader import Resize
from paddle_serving_app.reader import Sequential
from paddle_serving_app.reader import Transpose
from paddle_serving_server.web_service import Op, WebService
class DetOp(Op): class DetOp(Op):
...@@ -101,8 +108,8 @@ class RecOp(Op): ...@@ -101,8 +108,8 @@ class RecOp(Op):
def init_op(self): def init_op(self):
self.seq = Sequential([ self.seq = Sequential([
BGR2RGB(), Resize((224, 224)), Div(255), BGR2RGB(), Resize((224, 224)), Div(255),
Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225], Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225], False),
False), Transpose((2, 0, 1)) Transpose((2, 0, 1))
]) ])
index_dir = "../../drink_dataset_v1.0/index" index_dir = "../../drink_dataset_v1.0/index"
...@@ -136,7 +143,7 @@ class RecOp(Op): ...@@ -136,7 +143,7 @@ class RecOp(Op):
}) })
self.det_boxes = boxes self.det_boxes = boxes
#construct batch images for rec # construct batch images for rec
imgs = [] imgs = []
for box in boxes: for box in boxes:
box = [int(x) for x in box["bbox"]] box = [int(x) for x in box["bbox"]]
...@@ -192,7 +199,7 @@ class RecOp(Op): ...@@ -192,7 +199,7 @@ class RecOp(Op):
pred["rec_scores"] = scores[i][0] pred["rec_scores"] = scores[i][0]
results.append(pred) results.append(pred)
#do nms # do NMS
results = self.nms_to_rec_results(results, self.rec_nms_thresold) results = self.nms_to_rec_results(results, self.rec_nms_thresold)
return {"result": str(results)}, None, "" return {"result": str(results)}, None, ""
......
docs/images/structure.jpg

98.7 KB | W: | H:

docs/images/structure.jpg

1.8 MB | W: | H:

docs/images/structure.jpg
docs/images/structure.jpg
docs/images/structure.jpg
docs/images/structure.jpg
  • 2-up
  • Swipe
  • Onion skin
## PP-ShiTuV2图像识别系统
## 目录
- [PP-ShiTuV2简介](#pp-shituv2简介)
- [数据集介绍](#数据集介绍)
- [模型训练](#模型训练)
- [模型评估](#模型评估)
- [模型推理](#模型推理)
- [模块介绍](#模块介绍)
- [主体检测模型](#主体检测模型)
- [特征提取模型](#特征提取模型)
- [训练数据集优化与扩充](#训练数据集优化与扩充)
- [骨干网络优化](#骨干网络优化)
- [网络结构优化](#网络结构优化)
- [数据增强优化](#数据增强优化)
- [参考文献](#参考文献)
## PP-ShiTuV2简介
PP-ShiTuV2 是基于 PP-ShiTuV1 改进的一个实用轻量级通用图像识别系统,相比 PP-ShiTuV1 具有更高的识别精度、更强的泛化能力以及相近的推理速度<sup>*</sup>。该系统主要针对**训练数据集**、特征提取两个部分进行优化,使用了更优的骨干网络、损失函数与训练策略。使得 PP-ShiTuV2 在多个实际应用场景上的检索性能有显著提升。
<div align="center">
<img src="../../images/structure.png" />
</div>
### 数据集介绍
我们将训练数据进行了合理扩充与优化,更多细节请参考 [PP-ShiTuV2 数据集](../image_recognition_pipeline/feature_extraction.md#42-pp-shituv2)
下面以 [PP-ShiTuV2](../image_recognition_pipeline/feature_extraction.md#42-pp-shituv2) 的数据集为例,介绍 PP-ShiTuV2 模型的训练、评估、推理流程。
### 模型训练
首先下载好 [PP-ShiTuV2 数据集](../image_recognition_pipeline/feature_extraction.md#42-pp-shituv2) 中的16个数据集并手动进行合并、生成标注文本文件 `train_reg_all_data_v2.txt`,最后放置到 `dataset` 目录下。
合并后的文件夹结构如下所示:
```python
dataset/
├── Aliproduct/ # Aliproduct数据集文件夹
├── SOP/ # SOPt数据集文件夹
├── ...
├── Products-10k/ # Products-10k数据集文件夹
├── ...
└── train_reg_all_data_v2.txt # 标注文本文件
```
生成的 `train_reg_all_data_v2.txt` 内容如下所示:
```log
...
Aliproduct/train/50029/1766228.jpg 50029
Aliproduct/train/50029/1764348.jpg 50029
...
Products-10k/train/88823.jpg 186440
Products-10k/train/88824.jpg 186440
...
```
然后在终端运行以下命令进行训练:
```shell
# 使用0号GPU进行单卡训练
export CUDA_VISIBLE_DEVICES=0
python3.7 tools/train.py \
-c ./ppcls/configs/GeneralRecognitionV2/GeneralRecognitionV2_PPLCNetV2_base.yaml
# 使用0,1,2,3,4,5,6,7号GPU进行8卡分布式训练
export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
python3.7 -m paddle.distributed.launch tools/train.py \
-c ./ppcls/configs/GeneralRecognitionV2/GeneralRecognitionV2_PPLCNetV2_base.yaml
```
**注:** 在训练时默认会开启`eval_during_train`,每训练完 `eval_interval` 个epoch就会在配置文件中 `Eval` 指定的数据集上(默认为 Aliproduct )进行模型评估并计算得到参考指标。
### 模型评估
参考 [模型评估](../image_recognition_pipeline/feature_extraction.md#53-模型评估)
### 模型推理
参考 [模型推理](../image_recognition_pipeline/feature_extraction.md#54-模型推理)
## 模块介绍
### 主体检测模型
主体检测模型使用 `PicoDet-LCNet_x2_5`,详细信息参考:[picodet_lcnet_x2_5_640_mainbody](../image_recognition_pipeline/mainbody_detection.md)
### 特征提取模型
#### 训练数据集优化与扩充
在 PP-ShiTuV1 所用训练数据集的基础上,我们去掉了使用范围较小的 iCartoonFace 数据集,同时加入了更多常见、使用范围更广的数据集,如 bird400、Cars、Products-10k、fruits-262。
#### 骨干网络优化
我们将骨干网络从 `PPLCNet_x2_5` 替换成了 [`PPLCNetV2_base`](../models/PP-LCNetV2.md),相比 `PPLCNet_x2_5``PPLCNetV2_base` 基本保持了较高的分类精度,并减少了40%的推理时间<sup>*</sup>
**注:** <sup>*</sup>推理环境基于 Intel(R) Xeon(R) Gold 6271C CPU @ 2.60GHz 硬件平台,OpenVINO 推理平台。
#### 网络结构优化
我们对 `PPLCNetV2_base` 结构做了微调,并加入了在行人重检测、地标检索、人脸识别等任务上较为通用有效的优化调整。主要包括以下几点:
1. `PPLCNetV2_base` 结构微调:实验发现网络末尾的 [`ReLU`](../../../ppcls/arch/backbone/legendary_models/pp_lcnet_v2.py#L322) 对检索性能有较大影响, [`FC`](../../../ppcls/arch/backbone/legendary_models/pp_lcnet_v2.py#L325) 也会导致检索性能轻微掉点,因此我们去掉了 BackBone 末尾的 `ReLU``FC`
2. `last stride=1`:只将最后一个 stage 的 stride 改为1,即不进行下采样,以此增加最后输出的特征图的语义信息,同时不对推理速度产生太大影响。
3. `BN Neck`:在全局池化层后加入一个 `BatchNorm1D` 结构,对特征向量的每个维度进行标准化,让 `CELoss``TripletAngularMarginLoss` 在不同的分布下进行优化,使得模型更快地收敛。
| 模型 | training data | recall@1%(mAP%) |
| :----------------------------------------------------------------- | :---------------- | :-------------- |
| PP-ShiTuV1 | PP-ShiTuV1 数据集 | 63.0(51.5) |
| PP-ShiTuV1+`PPLCNetV2_base`+`last_stride=1`+`BNNeck`+`TripletLoss` | PP-ShiTuV1 数据集 | 72.3(60.5) |
4. `TripletAngularMarginLoss`:我们基于原始的 `TripletLoss` (困难三元组损失)进行了改进,将优化目标从 L2 欧几里得空间更换成余弦空间,并额外加入了 anchor 与 positive/negtive 之间的硬性距离约束,让训练与测试的目标更加接近,提升模型的泛化能力。
| 模型 | training data | recall@1%(mAP%) |
| :------------------------------------------------------------------------------ | :---------------- | :-------------- |
| PP-ShiTuV1+`PPLCNetV2_base`+`last_stride=1`+`BNNeck`+`TripletLoss` | PP-ShiTuV2 数据集 | 71.9(60.2) |
| PP-ShiTuV1+`PPLCNetV2_base`+`last_stride=1`+`BNNeck`+`TripletAngularMarginLoss` | PP-ShiTuV2 数据集 | 73.7(61.0) |
#### 数据增强优化
我们考虑到实际相机拍摄时目标主体可能出现一定的旋转而不一定能保持正立状态,因此我们在数据增强中加入了适当的 [随机旋转增强](../../../ppcls/configs/GeneralRecognitionV2/GeneralRecognitionV2_PPLCNetV2_base.yaml#L117),以提升模型在真实场景中的检索能力。
结合以上3个优化点,最终在多个数据集的实验结果如下:
| 模型 | product<sup>*</sup> |
| :--------- | :------------------ |
| - | recall@1%(mAP%) |
| PP-ShiTuV1 | 63.0(51.5) |
| PP-ShiTuV2 | 73.7(61.0) |
| 模型 | Aliproduct | VeRI-Wild | LogoDet-3k | iCartoonFace | SOP | Inshop |
| :--------- | :-------------- | :-------------- | :-------------- | :-------------- | :-------------- | :-------------- |
| - | recall@1%(mAP%) | recall@1%(mAP%) | recall@1%(mAP%) | recall@1%(mAP%) | recall@1%(mAP%) | recall@1%(mAP%) |
| PP-ShiTuV1 | 83.9(83.2) | 88.7(60.1) | 86.1(73.6) | 84.1(72.3) | 79.7(58.6) | 89.1(69.4) |
| PP-ShiTuV2 | 84.2(83.3) | 87.8(68.8) | 88.0(63.2) | 53.6(27.5) | 77.6(55.3) | 90.8(74.3) |
| 模型 | gldv2 | imdb_face | iNat | instre | sketch | sop<sup>*</sup> |
| :--------- | :-------------- | :-------------- | :-------------- | :-------------- | :-------------- | :-------------- |
| - | recall@1%(mAP%) | recall@1%(mAP%) | recall@1%(mAP%) | recall@1%(mAP%) | recall@1%(mAP%) | recall@1%(mAP%) |
| PP-ShiTuV1 | 98.2(91.6) | 28.8(8.42) | 12.6(6.1) | 72.0(50.4) | 27.9(9.5) | 97.6(90.3) |
| PP-ShiTuV2 | 98.1(90.5) | 35.9(11.2) | 38.6(23.9) | 87.7(71.4) | 39.3(15.6) | 98.3(90.9) |
**注:** product数据集是为了验证PP-ShiTu的泛化性能而制作的数据集,所有的数据都没有在训练和测试集中出现。该数据包含8个大类(人脸、化妆品、地标、红酒、手表、车、运动鞋、饮料),299个小类。测试时,使用299个小类的标签进行测试;sop数据集来自[GPR1200: A Benchmark for General-Purpose Content-Based Image Retrieval](https://arxiv.org/abs/2111.13122),可视为“SOP”数据集的子集。
## 参考文献
1. Schall, Konstantin, et al. "GPR1200: A Benchmark for General-Purpose Content-Based Image Retrieval." International Conference on Multimedia Modeling. Springer, Cham, 2022.
2. Luo, Hao, et al. "A strong baseline and batch normalization neck for deep person re-identification." IEEE Transactions on Multimedia 22.10 (2019): 2597-2609.
...@@ -344,7 +344,7 @@ PaddleClas 提供了基于 Paddle2ONNX 来完成 inference 模型转换 ONNX 模 ...@@ -344,7 +344,7 @@ PaddleClas 提供了基于 Paddle2ONNX 来完成 inference 模型转换 ONNX 模
#### 5.1 方法总结与对比 #### 5.1 方法总结与对比
上述算法能快速地迁移至多数的ReID模型中,能进一步提升ReID模型的性能。 上述算法能快速地迁移至多数的ReID模型中(参考 [PP-ShiTuV2](../PPShiTu/PPShiTuV2_introduction.md) ),能进一步提升ReID模型的性能,
#### 5.2 使用建议/FAQ #### 5.2 使用建议/FAQ
......
...@@ -6,10 +6,10 @@ ...@@ -6,10 +6,10 @@
- [1. 摘要](#1-摘要) - [1. 摘要](#1-摘要)
- [2. 介绍](#2-介绍) - [2. 介绍](#2-介绍)
- [3. 方法](#3-方法) - [3. 方法](#3-方法)
- [3.1 Backbone](#31-backbone) - [3.1 Backbone](#31-backbone)
- [3.2 Neck](#32-neck) - [3.2 Neck](#32-neck)
- [3.3 Head](#33-head) - [3.3 Head](#33-head)
- [3.4 Loss](#34-loss) - [3.4 Loss](#34-loss)
- [4. 实验部分](#4-实验部分) - [4. 实验部分](#4-实验部分)
- [5. 自定义特征提取](#5-自定义特征提取) - [5. 自定义特征提取](#5-自定义特征提取)
- [5.1 数据准备](#51-数据准备) - [5.1 数据准备](#51-数据准备)
...@@ -35,56 +35,72 @@ ...@@ -35,56 +35,72 @@
![](../../images/feature_extraction_framework.png) ![](../../images/feature_extraction_framework.png)
图中各个模块的功能为: 图中各个模块的功能为:
- **Backbone**: 用于提取输入图像初步特征的骨干网络,一般由配置文件中的 [`Backbone`](../../../ppcls/configs/GeneralRecognition/GeneralRecognition_PPLCNet_x2_5.yaml#L26-L29) 以及 [`BackboneStopLayer`](../../../ppcls/configs/GeneralRecognition/GeneralRecognition_PPLCNet_x2_5.yaml#L30-L31) 字段共同指定。 - **Backbone**: 用于提取输入图像初步特征的骨干网络,一般由配置文件中的 [`B.//ppcls/configs/GeneralRecognitionV2/GeneralRecognitionV2_PPLCNetV2_base.yaml#L26-L29) 以及 [`B.//ppcls/configs/GeneralRecognitionV2/GeneralRecognitionV2_PPLCNetV2_base.yaml#L30-L31) 字段共同指定。
- **Neck**: 用以特征增强及特征维度变换。可以是一个简单的 FC Layer,用来做特征维度变换;也可以是较复杂的 FPN 结构,用以做特征增强,一般由配置文件中的 [`Neck`](../../../ppcls/configs/GeneralRecognition/GeneralRecognition_PPLCNet_x2_5.yaml#L32-L35)字段指定。 - **Neck**: 用以特征增强及特征维度变换。可以是一个简单的 FC Layer,用来做特征维度变换;也可以是较复杂的 FPN 结构,用以做特征增强,一般由配置文件中的 [`N.//ppcls/configs/GeneralRecognitionV2/GeneralRecognitionV2_PPLCNetV2_base.yaml#L32-L35)字段指定。
- **Head**: 用来将 feature 转化为 logits,让模型在训练阶段能以分类任务的形式进行训练。除了常用的 FC Layer 外,还可以替换为 cosmargin, arcmargin, circlemargin 等模块,一般由配置文件中的 [`Head`](../../../ppcls/configs/GeneralRecognition/GeneralRecognition_PPLCNet_x2_5.yaml#L36-L41)字段指定。 - **Head**: 用来将 `Neck` 的输出 feature 转化为 logits,让模型在训练阶段能以分类任务的形式进行训练。除了常用的 FC Layer 外,还可以替换为 [CosMargin](../../../ppcls/arch/gears/cosmargin.py), [ArcMargin](../../../ppcls/arch/gears/arcmargin.py), [CircleMargin](../../../ppcls/arch/gears/circlemargin.py) 等模块,一般由配置文件中的 [`H.//ppcls/configs/GeneralRecognitionV2/GeneralRecognitionV2_PPLCNetV2_base.yaml#L36-L41) 字段指定。
- **Loss**: 指定所使用的 Loss 函数。我们将 Loss 设计为组合 loss 的形式,可以方便地将 Classification Loss 和 Metric learning Loss 组合在一起,一般由配置文件中的 [`Loss`](../../../ppcls/configs/GeneralRecognition/GeneralRecognition_PPLCNet_x2_5.yaml#L44-L50)字段指定。 - **Loss**: 指定所使用的 Loss 函数。我们将 Loss 设计为组合 loss 的形式,可以方便地将 Classification Loss 和 Metric learning Loss 组合在一起,一般由配置文件中的 [`L.//ppcls/configs/GeneralRecognitionV2/GeneralRecognitionV2_PPLCNetV2_base.yaml#L44-L50) 字段指定。
<a name="3"></a> <a name="3"></a>
## 3. 方法 ## 3. 方法
### 3.1 Backbone #### 3.1 Backbone
Backbone 部分采用了 [PP_LCNet_x2_5](../models/PP-LCNet.md),其针对Intel CPU端的性能优化探索了多个有效的结构设计方案,最终实现了在不增加推理时间的情况下,进一步提升模型的性能,最终大幅度超越现有的 SOTA 模型。 Backbone 部分采用了 [PP-LCNetV2_base](../models/PP-LCNetV2.md),其针对Intel CPU端的性能优化探索了多个有效的结构设计方案,最终实现了在不增加推理时间的情况下,进一步提升模型的性能,最终大幅度超越现有的 SOTA 模型。
### 3.2 Neck #### 3.2 Neck
Neck 部分采用了 [FC Layer](../../../ppcls/arch/gears/fc.py),对 Backbone 抽取得到的特征进行降维,减少了特征存储的成本与计算量 Neck 部分采用了 [BN Neck](../../../ppcls/arch/gears/bnneck.py),对 Backbone 抽取得到的特征的每个维度进行标准化操作,减少了同时优化度量学习损失和分类损失的难度
### 3.3 Head #### 3.3 Head
Head 部分选用 [ArcMargin](../../../ppcls/arch/gears/arcmargin.py),在训练时通过指定margin,增大同类特征之间的角度差异再进行分类,进一步提升抽取特征的表征能力 Head 部分选用 [FC Layer](../../../ppcls/arch/gears/fc.py),使用分类头将 feature 转换成 logits 供后续计算分类损失
### 3.4 Loss #### 3.4 Loss
Loss 部分选用 [Cross entropy loss](../../../ppcls/loss/celoss.py),在训练时以分类任务的损失函数来指导网络进行优化。详细的配置文件见[通用识别配置文件](../../../ppcls/configs/GeneralRecognition/GeneralRecognition_PPLCNet_x2_5.yaml) Loss 部分选用 [Cross entropy loss](../../../ppcls/loss/celoss.py)[TripletAngularMarginLoss](../../../ppcls/loss/tripletangularmarginloss.py),在训练时以分类损失和基于角度的三元组损失来指导网络进行优化。详细的配置文件见[GeneralRecognitionV2_PPLCNetV2_base.yaml](../../../ppcls/configs/GeneralRecognitionV2/GeneralRecognitionV2_PPLCNetV2_base.yaml#L63-77)
<a name="4"></a> <a name="4"></a>
## 4. 实验部分 ## 4. 实验部分
训练数据为如下 7 个公开数据集的汇总: 我们对原有的训练数据进行了合理扩充与优化,最终使用如下 16 个公开数据集的汇总:
| 数据集 | 数据量 | 类别数 | 场景 | 数据集地址 | | 数据集 | 数据量 | 类别数 | 场景 | 数据集地址 |
| :----------: | :-----: | :------: | :------: | :--------------------------------------------------------------------------: | | :--------------------- | :-----: | :------: | :---: | :----------------------------------------------------------------------------------: |
| Aliproduct | 2498771 | 50030 | 商品 | [地址](https://retailvisionworkshop.github.io/recognition_challenge_2020/) | | Aliproduct | 2498771 | 50030 | 商品 | [地址](https://retailvisionworkshop.github.io/recognition_challenge_2020/) |
| GLDv2 | 1580470 | 81313 | 地标 | [地址](https://github.com/cvdfoundation/google-landmark) | | GLDv2 | 1580470 | 81313 | 地标 | [地址](https://github.com/cvdfoundation/google-landmark) |
| VeRI-Wild | 277797 | 30671 | 车辆 | [地址](https://github.com/PKU-IMRE/VERI-Wild) | | VeRI-Wild | 277797 | 30671 | 车辆 | [地址](https://github.com/PKU-IMRE/VERI-Wild) |
| LogoDet-3K | 155427 | 3000 | Logo | [地址](https://github.com/Wangjing1551/LogoDet-3K-Dataset) | | LogoDet-3K | 155427 | 3000 | Logo | [地址](https://github.com/Wangjing1551/LogoDet-3K-Dataset) |
| iCartoonFace | 389678 | 5013 | 动漫人物 | [地址](http://challenge.ai.iqiyi.com/detail?raceId=5def69ace9fcf68aef76a75d) | | SOP | 59551 | 11318 | 商品 | [地址](https://cvgl.stanford.edu/projects/lifted_struct/) |
| SOP | 59551 | 11318 | 商品 | [地址](https://cvgl.stanford.edu/projects/lifted_struct/) | | Inshop | 25882 | 3997 | 商品 | [地址](http://mmlab.ie.cuhk.edu.hk/projects/DeepFashion.html) |
| Inshop | 25882 | 3997 | 商品 | [地址](http://mmlab.ie.cuhk.edu.hk/projects/DeepFashion.html) | | bird400 | 58388 | 400 | 鸟类 | [地址](https://www.kaggle.com/datasets/gpiosenka/100-bird-species) |
| **Total** | **5M** | **185K** | ---- | ---- | | 104flows | 12753 | 104 | 花类 | [地址](https://www.robots.ox.ac.uk/~vgg/data/flowers/102/) |
| Cars | 58315 | 112 | 车辆 | [地址](https://ai.stanford.edu/~jkrause/cars/car_dataset.html) |
最终的模型效果如下表所示: | Fashion Product Images | 44441 | 47 | 商品 | [地址](https://www.kaggle.com/datasets/paramaggarwal/fashion-product-images-dataset) |
| flowerrecognition | 24123 | 59 | 花类 | [地址](https://www.kaggle.com/datasets/aymenktari/flowerrecognition) |
| 模型 | Aliproduct | VeRI-Wild | LogoDet-3K | iCartoonFace | SOP | Inshop | Latency(ms) | | food-101 | 101000 | 101 | 食物 | [地址](https://data.vision.ee.ethz.ch/cvl/datasets_extra/food-101/) |
| :-----------------------------: | :--------: | :-------: | :--------: | :----------: | :---: | :----: | :---------: | | fruits-262 | 225639 | 262 | 水果 | [地址](https://www.kaggle.com/datasets/aelchimminut/fruits262) |
| GeneralRecognition_PPLCNet_x2_5 | 0.839 | 0.888 | 0.861 | 0.841 | 0.793 | 0.892 | 5.0 | | inaturalist | 265213 | 1010 | 自然 | [地址](https://github.com/visipedia/inat_comp/tree/master/2017) |
| indoor-scenes | 15588 | 67 | 室内 | [地址](https://www.kaggle.com/datasets/itsahmad/indoor-scenes-cvpr-2019) |
* 预训练模型地址:[通用识别预训练模型](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/models/pretrain/general_PPLCNet_x2_5_pretrained_v1.0.pdparams) | Products-10k | 141931 | 9691 | 商品 | [地址](https://products-10k.github.io/) |
* 采用的评测指标为:`Recall@1` | CompCars | 16016 | 431 | 车辆 | [地址](http://​​​​​​http://ai.stanford.edu/~jkrause/cars/car_dataset.html​) |
| **Total** | **6M** | **192K** | - | - |
最终的模型精度指标如下表所示:
| 模型 | Aliproduct | VeRI-Wild | LogoDet-3k | iCartoonFace | SOP | Inshop |
| :--------- | :-------------- | :-------------- | :-------------- | :-------------- | :-------------- | :-------------- |
| - | recall@1%(mAP%) | recall@1%(mAP%) | recall@1%(mAP%) | recall@1%(mAP%) | recall@1%(mAP%) | recall@1%(mAP%) |
| PP-ShiTuV2 | 84.2(83.3) | 87.8(68.8) | 88.0(63.2) | 53.6(27.5) | 77.6(55.3) | 90.8(74.3) |
| 模型 | gldv2 | imdb_face | iNat | instre | sketch | sop<sup>*</sup> |
| :--------- | :-------------- | :-------------- | :-------------- | :-------------- | :-------------- | :-------------- |
| - | recall@1%(mAP%) | recall@1%(mAP%) | recall@1%(mAP%) | recall@1%(mAP%) | recall@1%(mAP%) | recall@1%(mAP%) |
| PP-ShiTuV2 | 98.1(90.5) | 35.9(11.2) | 38.6(23.9) | 87.7(71.4) | 39.3(15.6) | 98.3(90.9) |
* 预训练模型地址:[general_PPLCNetV2_base_pretrained_v1.0.pdparams](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/models/pretrain/PPShiTuV2/general_PPLCNetV2_base_pretrained_v1.0.pdparams)
* 采用的评测指标为:`Recall@1``mAP`
* 速度评测机器的 CPU 具体信息为:`Intel(R) Xeon(R) Gold 6148 CPU @ 2.40GHz` * 速度评测机器的 CPU 具体信息为:`Intel(R) Xeon(R) Gold 6148 CPU @ 2.40GHz`
* 速度指标的评测条件为: 开启 MKLDNN, 线程数设置为 10 * 速度指标的评测条件为: 开启 MKLDNN, 线程数设置为 10
...@@ -94,8 +110,7 @@ Loss 部分选用 [Cross entropy loss](../../../ppcls/loss/celoss.py),在训 ...@@ -94,8 +110,7 @@ Loss 部分选用 [Cross entropy loss](../../../ppcls/loss/celoss.py),在训
自定义特征提取,是指依据自己的任务,重新训练特征提取模型。 自定义特征提取,是指依据自己的任务,重新训练特征提取模型。
下面基于`GeneralRecognition_PPLCNet_x2_5.yaml`配置文件,介绍主要的四个步骤:1)数据准备;2)模型训练;3)模型评估;4)模型推理 下面基于 `GeneralRecognitionV2_PPLCNetV2_base.yaml` 配置文件,介绍主要的四个步骤:1)数据准备;2)模型训练;3)模型评估;4)模型推理
<a name="5.1"></a> <a name="5.1"></a>
...@@ -107,34 +122,40 @@ Loss 部分选用 [Cross entropy loss](../../../ppcls/loss/celoss.py),在训 ...@@ -107,34 +122,40 @@ Loss 部分选用 [Cross entropy loss](../../../ppcls/loss/celoss.py),在训
- 修改类别数: - 修改类别数:
```yaml ```yaml
Head: Head:
name: ArcMargin name: FC
embedding_size: 512 embedding_size: *feat_dim
class_num: 185341 # 此处表示类别数 class_num: 192612 # 此处表示类别数
weight_attr:
initializer:
name: Normal
std: 0.001
bias_attr: False
``` ```
- 修改训练数据集配置: - 修改训练数据集配置:
```yaml ```yaml
Train: Train:
dataset: dataset:
name: ImageNetDataset name: ImageNetDataset
image_root: ./dataset/ # 此处表示train数据所在的目录 image_root: ./dataset/ # 此处表示train数据所在的目录
cls_label_path: ./dataset/train_reg_all_data.txt # 此处表示train数据集label文件的地址 cls_label_path: ./dataset/train_reg_all_data.txt # 此处表示train数据集label文件的地址
relabel: True
``` ```
- 修改评估数据集中query数据配置: - 修改评估数据集中query数据配置:
```yaml ```yaml
Query: Query:
dataset: dataset:
name: VeriWild name: VeriWild
image_root: ./dataset/Aliproduct/ # 此处表示query数据集所在的目录 image_root: ./dataset/Aliproduct/ # 此处表示query数据集所在的目录
cls_label_path: ./dataset/Aliproduct/val_list.txt # 此处表示query数据集label文件的地址 cls_label_path: ./dataset/Aliproduct/val_list.txt # 此处表示query数据集label文件的地址
``` ```
- 修改评估数据集中gallery数据配置: - 修改评估数据集中gallery数据配置:
```yaml ```yaml
Gallery: Gallery:
dataset: dataset:
name: VeriWild name: VeriWild
image_root: ./dataset/Aliproduct/ # 此处表示gallery数据集所在的目录 image_root: ./dataset/Aliproduct/ # 此处表示gallery数据集所在的目录
cls_label_path: ./dataset/Aliproduct/val_list.txt # 此处表示gallery数据集label文件的地址 cls_label_path: ./dataset/Aliproduct/val_list.txt # 此处表示gallery数据集label文件的地址
``` ```
<a name="5.2"></a> <a name="5.2"></a>
...@@ -147,14 +168,14 @@ Loss 部分选用 [Cross entropy loss](../../../ppcls/loss/celoss.py),在训 ...@@ -147,14 +168,14 @@ Loss 部分选用 [Cross entropy loss](../../../ppcls/loss/celoss.py),在训
```shell ```shell
export CUDA_VISIBLE_DEVICES=0 export CUDA_VISIBLE_DEVICES=0
python3.7 tools/train.py \ python3.7 tools/train.py \
-c ppcls/configs/GeneralRecognition/GeneralRecognition_PPLCNet_x2_5.yaml -c ./ppcls/configs/GeneralRecognitionV2/GeneralRecognitionV2_PPLCNetV2_base.yaml
``` ```
- 单机多卡训练 - 单机多卡训练
```shell ```shell
export CUDA_VISIBLE_DEVICES=0,1,2,3 export CUDA_VISIBLE_DEVICES=0,1,2,3
python3.7 -m paddle.distributed.launch \ python3.7 -m paddle.distributed.launch \
--gpus="0,1,2,3" tools/train.py \ --gpus="0,1,2,3" tools/train.py \
-c ppcls/configs/GeneralRecognition/GeneralRecognition_PPLCNet_x2_5.yaml -c ./ppcls/configs/GeneralRecognitionV2/GeneralRecognitionV2_PPLCNetV2_base.yaml
``` ```
**注意:** **注意:**
配置文件中默认采用`在线评估`的方式,如果你想加快训练速度,可以关闭`在线评估`功能,只需要在上述命令的后面,增加 `-o Global.eval_during_train=False` 配置文件中默认采用`在线评估`的方式,如果你想加快训练速度,可以关闭`在线评估`功能,只需要在上述命令的后面,增加 `-o Global.eval_during_train=False`
...@@ -165,7 +186,7 @@ Loss 部分选用 [Cross entropy loss](../../../ppcls/loss/celoss.py),在训 ...@@ -165,7 +186,7 @@ Loss 部分选用 [Cross entropy loss](../../../ppcls/loss/celoss.py),在训
```shell ```shell
export CUDA_VISIBLE_DEVICES=0 export CUDA_VISIBLE_DEVICES=0
python3.7 tools/train.py \ python3.7 tools/train.py \
-c ppcls/configs/GeneralRecognition/GeneralRecognition_PPLCNet_x2_5.yaml \ -c ./ppcls/configs/GeneralRecognitionV2/GeneralRecognitionV2_PPLCNetV2_base.yaml \
-o Global.checkpoint="output/RecModel/latest" -o Global.checkpoint="output/RecModel/latest"
``` ```
- 单机多卡断点恢复训练 - 单机多卡断点恢复训练
...@@ -173,7 +194,7 @@ Loss 部分选用 [Cross entropy loss](../../../ppcls/loss/celoss.py),在训 ...@@ -173,7 +194,7 @@ Loss 部分选用 [Cross entropy loss](../../../ppcls/loss/celoss.py),在训
export CUDA_VISIBLE_DEVICES=0,1,2,3 export CUDA_VISIBLE_DEVICES=0,1,2,3
python3.7 -m paddle.distributed.launch \ python3.7 -m paddle.distributed.launch \
--gpus="0,1,2,3" tools/train.py \ --gpus="0,1,2,3" tools/train.py \
-c ppcls/configs/GeneralRecognition/GeneralRecognition_PPLCNet_x2_5.yaml \ -c ./ppcls/configs/GeneralRecognitionV2/GeneralRecognitionV2_PPLCNetV2_base.yaml \
-o Global.checkpoint="output/RecModel/latest" -o Global.checkpoint="output/RecModel/latest"
``` ```
...@@ -187,7 +208,7 @@ Loss 部分选用 [Cross entropy loss](../../../ppcls/loss/celoss.py),在训 ...@@ -187,7 +208,7 @@ Loss 部分选用 [Cross entropy loss](../../../ppcls/loss/celoss.py),在训
```shell ```shell
export CUDA_VISIBLE_DEVICES=0 export CUDA_VISIBLE_DEVICES=0
python3.7 tools/eval.py \ python3.7 tools/eval.py \
-c ppcls/configs/GeneralRecognition/GeneralRecognition_PPLCNet_x2_5.yaml \ -c ./ppcls/configs/GeneralRecognitionV2/GeneralRecognitionV2_PPLCNetV2_base.yaml \
-o Global.pretrained_model="output/RecModel/best_model" -o Global.pretrained_model="output/RecModel/best_model"
``` ```
...@@ -196,7 +217,7 @@ Loss 部分选用 [Cross entropy loss](../../../ppcls/loss/celoss.py),在训 ...@@ -196,7 +217,7 @@ Loss 部分选用 [Cross entropy loss](../../../ppcls/loss/celoss.py),在训
export CUDA_VISIBLE_DEVICES=0,1,2,3 export CUDA_VISIBLE_DEVICES=0,1,2,3
python3.7 -m paddle.distributed.launch \ python3.7 -m paddle.distributed.launch \
--gpus="0,1,2,3" tools/eval.py \ --gpus="0,1,2,3" tools/eval.py \
-c ppcls/configs/GeneralRecognition/GeneralRecognition_PPLCNet_x2_5.yaml \ -c ./ppcls/configs/GeneralRecognitionV2/GeneralRecognitionV2_PPLCNetV2_base.yaml \
-o Global.pretrained_model="output/RecModel/best_model" -o Global.pretrained_model="output/RecModel/best_model"
``` ```
**注:** 建议使用多卡评估。该方式可以利用多卡并行计算快速得到全部数据的特征,能够加速评估的过程。 **注:** 建议使用多卡评估。该方式可以利用多卡并行计算快速得到全部数据的特征,能够加速评估的过程。
...@@ -212,7 +233,7 @@ Loss 部分选用 [Cross entropy loss](../../../ppcls/loss/celoss.py),在训 ...@@ -212,7 +233,7 @@ Loss 部分选用 [Cross entropy loss](../../../ppcls/loss/celoss.py),在训
首先需要将 `*.pdparams` 模型文件转换成 inference 格式,转换命令如下。 首先需要将 `*.pdparams` 模型文件转换成 inference 格式,转换命令如下。
```shell ```shell
python3.7 tools/export_model.py \ python3.7 tools/export_model.py \
-c ppcls/configs/GeneralRecognition/GeneralRecognition_PPLCNet_x2_5.yaml \ -c ./ppcls/configs/GeneralRecognitionV2/GeneralRecognitionV2_PPLCNetV2_base.yaml \
-o Global.pretrained_model="output/RecModel/best_model" -o Global.pretrained_model="output/RecModel/best_model"
``` ```
生成的推理模型默认位于 `PaddleClas/inference` 目录,里面包含三个文件,分别为 `inference.pdmodel``inference.pdiparams``inference.pdiparams.info` 生成的推理模型默认位于 `PaddleClas/inference` 目录,里面包含三个文件,分别为 `inference.pdmodel``inference.pdiparams``inference.pdiparams.info`
...@@ -244,4 +265,4 @@ python3.7 python/predict_rec.py \ ...@@ -244,4 +265,4 @@ python3.7 python/predict_rec.py \
## 7. 参考文献 ## 7. 参考文献
1. [PP-LCNet: A Lightweight CPU Convolutional Neural Network](https://arxiv.org/pdf/2109.15099.pdf) 1. [PP-LCNet: A Lightweight CPU Convolutional Neural Network](https://arxiv.org/pdf/2109.15099.pdf)
2. [ArcFace: Additive Angular Margin Loss for Deep Face Recognition](https://arxiv.org/abs/1801.07698) 2. [Bag of Tricks and A Strong Baseline for Deep Person Re-identification](https://openaccess.thecvf.com/content_CVPRW_2019/papers/TRMTMCT/Luo_Bag_of_Tricks_and_a_Strong_Baseline_for_Deep_Person_CVPRW_2019_paper.pdf)
# Python 预测推理 # Python 预测推理
---
首先请参考文档[环境准备](../installation/install_paddleclas.md)配置运行环境。 首先请参考文档[环境准备](../installation/install_paddleclas.md)配置运行环境。
## 目录 ## 目录
...@@ -13,47 +11,50 @@ ...@@ -13,47 +11,50 @@
- [2.3 PP-ShiTu PipeLine推理](#2.3) - [2.3 PP-ShiTu PipeLine推理](#2.3)
<a name="1"></a> <a name="1"></a>
## 1. 图像分类推理 ## 1. 图像分类推理
首先请参考文档[模型导出](./export_model.md)准备 inference 模型,然后进入 PaddleClas 的 `deploy` 目录下: 首先请参考文档[模型导出](./export_model.md)准备 inference 模型,然后进入 PaddleClas 的 `deploy` 目录下:
```shell ```shell
cd /path/to/PaddleClas/deploy cd PaddleClas/deploy
``` ```
使用以下命令进行预测: 使用以下命令进行预测:
```shell ```shell
python python/predict_cls.py -c configs/inference_cls.yaml python3.7 python/predict_cls.py -c configs/inference_cls.yaml
``` ```
在配置文件 `configs/inference_cls.yaml` 中有以下字段用于配置预测参数: 在配置文件 `configs/inference_cls.yaml` 中有以下字段用于配置预测参数:
* `Global.infer_imgs`:待预测的图片文件路径; * `Global.infer_imgs`:待预测的图片文件(夹)路径;
* `Global.inference_model_dir`:inference 模型文件所在目录,该目录下需要有文件 `inference.pdmodel``inference.pdiparams` 两个文件; * `Global.inference_model_dir`:inference 模型文件所在文件夹的路径,该文件夹下需要有文件 `inference.pdmodel``inference.pdiparams` 两个文件;
* `Global.use_tensorrt`:是否使用 TesorRT 预测引擎,默认为 `False`
* `Global.use_gpu`:是否使用 GPU 预测,默认为 `True` * `Global.use_gpu`:是否使用 GPU 预测,默认为 `True`
* `Global.enable_mkldnn`:是否启用 `MKL-DNN` 加速库,默认为 `False`。注意 `enable_mkldnn``use_gpu` 同时为 `True` 时,将忽略 `enable_mkldnn`,而使用 GPU 预测; * `Global.enable_mkldnn`:是否启用 `MKL-DNN` 加速库,默认为 `False`。注意 `enable_mkldnn``use_gpu` 同时为 `True` 时,将忽略 `enable_mkldnn`,而使用 GPU 预测;
* `Global.use_fp16`:是否启用 `FP16`,默认为 `False` * `Global.use_fp16`:是否启用 `FP16`,默认为 `False`
* `Global.use_tensorrt`:是否使用 TesorRT 预测引擎,默认为 `False`
* `PreProcess`:用于数据预处理配置; * `PreProcess`:用于数据预处理配置;
* `PostProcess`:由于后处理配置; * `PostProcess`:由于后处理配置;
* `PostProcess.Topk.class_id_map_file`:数据集 label 的映射文件,默认为 `./utils/imagenet1k_label_list.txt`,该文件为 PaddleClas 所使用的 ImageNet 数据集 label 映射文件。 * `PostProcess.Topk.class_id_map_file`:数据集 label 的映射文件,默认为 `../ppcls/utils/imagenet1k_label_list.txt`,该文件为 PaddleClas 所使用的 ImageNet 数据集 label 映射文件。
**注意**: **注意**:
* 如果使用 VisionTransformer 系列模型,如 `DeiT_***_384`, `ViT_***_384` 等,请注意模型的输入数据尺寸,部分模型需要修改参数: `PreProcess.resize_short=384`, `PreProcess.resize=384` * 如果使用 VisionTransformer 系列模型,如 `DeiT_***_384`, `ViT_***_384` 等,请注意模型的输入数据尺寸,该类模型需要修改参数: `PreProcess.resize_short=384`, `PreProcess.resize=384`
* 如果你希望提升评测模型速度,使用 GPU 评测时,建议开启 TensorRT 加速预测,使用 CPU 评测时,建议开启 MKL-DNN 加速预测。 * 如果你希望提升评测模型速度,使用 GPU 评测时,建议开启 TensorRT 加速预测,使用 CPU 评测时,建议开启 MKL-DNN 加速预测。
<a name="2"></a> <a name="2"></a>
## 2. PP-ShiTu模型推理 ## 2. PP-ShiTu模型推理
PP-ShiTu整个Pipeline包含三部分:主体检测、特提取模型、特征检索。其中主体检测、特征模型可以单独推理使用。单独主体检测详见[2.1](#2.1),特征提取模型单独推理详见[2.2](#2.2), PP-ShiTu整体推理详见[2.3](#2.3) PP-ShiTu整个Pipeline包含三部分:主体检测、特征提取模型、特征检索。其中主体检测模型、特征提取模型可以单独推理使用。单独使用主体检测详见[主体检测模型推理](#2.1),特征提取模型单独推理详见[特征提取模型推理](#2.2), PP-ShiTu整体推理详见[PP-ShiTu PipeLine推理](#2.3)
<a name="2.1"></a> <a name="2.1"></a>
### 2.1 主体检测模型推理 ### 2.1 主体检测模型推理
进入 PaddleClas 的 `deploy` 目录下: 进入 PaddleClas 的 `deploy` 目录下:
```shell ```shell
cd /path/to/PaddleClas/deploy cd PaddleClas/deploy
``` ```
准备 PaddleClas 提供的主体检测 inference 模型: 准备 PaddleClas 提供的主体检测 inference 模型:
...@@ -61,28 +62,28 @@ cd /path/to/PaddleClas/deploy ...@@ -61,28 +62,28 @@ cd /path/to/PaddleClas/deploy
```shell ```shell
mkdir -p models mkdir -p models
# 下载通用检测 inference 模型并解压 # 下载通用检测 inference 模型并解压
wget -P ./models/ https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/models/inference/ppyolov2_r50vd_dcn_mainbody_v1.0_infer.tar wget -nc -P ./models/ https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/models/inference/picodet_PPLCNet_x2_5_mainbody_lite_v1.0_infer.tar
tar -xf ./models/ppyolov2_r50vd_dcn_mainbody_v1.0_infer.tar -C ./models/ tar -xf ./models/picodet_PPLCNet_x2_5_mainbody_lite_v1.0_infer.tar -C ./models/
``` ```
使用以下命令进行预测: 使用以下命令进行预测:
```shell ```shell
python python/predict_det.py -c configs/inference_det.yaml python3.7 python/predict_det.py -c configs/inference_det.yaml
``` ```
在配置文件 `configs/inference_det.yaml` 中有以下字段用于配置预测参数: 在配置文件 `configs/inference_det.yaml` 中有以下字段用于配置预测参数:
* `Global.infer_imgs`:待预测的图片文件路径; * `Global.infer_imgs`:待预测的图片文件路径;
* `Global.use_gpu`: 是否使用 GPU 预测,默认为 `True` * `Global.use_gpu`: 是否使用 GPU 预测,默认为 `True`
<a name="2.2"></a> <a name="2.2"></a>
### 2.2 特征提取模型推理 ### 2.2 特征提取模型推理
下面以商品特征提取为例,介绍特征提取模型推理。首先进入 PaddleClas 的 `deploy` 目录下: 下面以商品图片的特征提取为例,介绍特征提取模型推理。首先进入 PaddleClas 的 `deploy` 目录下:
```shell ```shell
cd /path/to/PaddleClas/deploy cd PaddleClas/deploy
``` ```
准备 PaddleClas 提供的商品特征提取 inference 模型: 准备 PaddleClas 提供的商品特征提取 inference 模型:
...@@ -90,13 +91,24 @@ cd /path/to/PaddleClas/deploy ...@@ -90,13 +91,24 @@ cd /path/to/PaddleClas/deploy
```shell ```shell
mkdir -p models mkdir -p models
# 下载商品特征提取 inference 模型并解压 # 下载商品特征提取 inference 模型并解压
wget -P ./models/ https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/models/inference/product_ResNet50_vd_aliproduct_v1.0_infer.tar wget -nc -P ./models/ https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/models/inference/PP-ShiTuV2/general_PPLCNetV2_base_pretrained_v1.0_infer.tar
tar -xf ./models/product_ResNet50_vd_aliproduct_v1.0_infer.tar -C ./models/ tar -xf ./models/general_PPLCNetV2_base_pretrained_v1.0_infer.tar -C ./models/
```
使用以下命令进行预测:
```shell
python3.7 python/predict_rec.py -c configs/inference_rec.yaml
``` ```
上述预测命令可以得到一个 512 维的特征向量,直接输出在在命令行中。 上述预测命令可以得到一个 512 维的特征向量,直接输出在在命令行中。
在配置文件 `configs/inference_det.yaml` 中有以下字段用于配置预测参数:
* `Global.infer_imgs`:待预测的图片文件路径;
* `Global.use_gpu`: 是否使用 GPU 预测,默认为 `True`
<a name="2.3"></a> <a name="2.3"></a>
### 2.3. PP-ShiTu PipeLine推理 ### 2.3. PP-ShiTu PipeLine推理
主体检测、特征提取和向量检索的串联预测,可以参考图像识别[快速体验](../quick_start/quick_start_recognition.md) 主体检测、特征提取和向量检索的串联预测,可以参考[图像识别快速开始](../quick_start/quick_start_recognition.md)
...@@ -79,8 +79,8 @@ python3.7 -m pip install paddle-serving-server-gpu==0.7.0.post112 # GPU with CUD ...@@ -79,8 +79,8 @@ python3.7 -m pip install paddle-serving-server-gpu==0.7.0.post112 # GPU with CUD
mkdir models mkdir models
cd models cd models
# 下载并解压通用识别模型 # 下载并解压通用识别模型
wget https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/models/inference/general_PPLCNet_x2_5_lite_v1.0_infer.tar wget https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/models/inference/PP-ShiTuV2/general_PPLCNetV2_base_pretrained_v1.0_infer.tar
tar -xf general_PPLCNet_x2_5_lite_v1.0_infer.tar tar -xf general_PPLCNetV2_base_pretrained_v1.0_infer.tar
# 下载并解压通用检测模型 # 下载并解压通用检测模型
wget https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/models/inference/picodet_PPLCNet_x2_5_mainbody_lite_v1.0_infer.tar wget https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/models/inference/picodet_PPLCNet_x2_5_mainbody_lite_v1.0_infer.tar
tar -xf picodet_PPLCNet_x2_5_mainbody_lite_v1.0_infer.tar tar -xf picodet_PPLCNet_x2_5_mainbody_lite_v1.0_infer.tar
...@@ -89,22 +89,22 @@ python3.7 -m pip install paddle-serving-server-gpu==0.7.0.post112 # GPU with CUD ...@@ -89,22 +89,22 @@ python3.7 -m pip install paddle-serving-server-gpu==0.7.0.post112 # GPU with CUD
```shell ```shell
# 转换通用识别模型 # 转换通用识别模型
python3.7 -m paddle_serving_client.convert \ python3.7 -m paddle_serving_client.convert \
--dirname ./general_PPLCNet_x2_5_lite_v1.0_infer/ \ --dirname ./general_PPLCNetV2_base_pretrained_v1.0_infer/ \
--model_filename inference.pdmodel \ --model_filename inference.pdmodel \
--params_filename inference.pdiparams \ --params_filename inference.pdiparams \
--serving_server ./general_PPLCNet_x2_5_lite_v1.0_serving/ \ --serving_server ./general_PPLCNetV2_base_pretrained_v1.0_serving/ \
--serving_client ./general_PPLCNet_x2_5_lite_v1.0_client/ --serving_client ./general_PPLCNetV2_base_pretrained_v1.0_client/
``` ```
上述命令的参数含义与[#3.1 模型转换](#3.1)相同 上述命令的参数含义与[#3.1 模型转换](#3.1)相同
通用识别 inference 模型转换完成后,会在当前文件夹多出 `general_PPLCNet_x2_5_lite_v1.0_serving/``general_PPLCNet_x2_5_lite_v1.0_client/` 的文件夹,具备如下结构: 通用识别 inference 模型转换完成后,会在当前文件夹多出 `general_PPLCNetV2_base_pretrained_v1.0_serving/``general_PPLCNetV2_base_pretrained_v1.0_client/` 的文件夹,具备如下结构:
```shell ```shell
├── general_PPLCNet_x2_5_lite_v1.0_serving/ ├── general_PPLCNetV2_base_pretrained_v1.0_serving/
│ ├── inference.pdiparams │ ├── inference.pdiparams
│ ├── inference.pdmodel │ ├── inference.pdmodel
│ ├── serving_server_conf.prototxt │ ├── serving_server_conf.prototxt
│ └── serving_server_conf.stream.prototxt │ └── serving_server_conf.stream.prototxt
└── general_PPLCNet_x2_5_lite_v1.0_client/ └── general_PPLCNetV2_base_pretrained_v1.0_client/
├── serving_client_conf.prototxt ├── serving_client_conf.prototxt
└── serving_client_conf.stream.prototxt └── serving_client_conf.stream.prototxt
``` ```
...@@ -119,7 +119,7 @@ python3.7 -m pip install paddle-serving-server-gpu==0.7.0.post112 # GPU with CUD ...@@ -119,7 +119,7 @@ python3.7 -m pip install paddle-serving-server-gpu==0.7.0.post112 # GPU with CUD
``` ```
上述命令的参数含义与[#3.1 模型转换](#3.1)相同 上述命令的参数含义与[#3.1 模型转换](#3.1)相同
识别推理模型转换完成后,会在当前文件夹多出 `general_PPLCNet_x2_5_lite_v1.0_serving/``general_PPLCNet_x2_5_lite_v1.0_client/` 的文件夹。分别修改 `general_PPLCNet_x2_5_lite_v1.0_serving/``general_PPLCNet_x2_5_lite_v1.0_client/` 目录下的 `serving_server_conf.prototxt` 中的 `alias` 名字: 将 `fetch_var` 中的 `alias_name` 改为 `features`。 修改后的 `serving_server_conf.prototxt` 内容如下 识别推理模型转换完成后,会在当前文件夹多出 `general_PPLCNetV2_base_pretrained_v1.0_serving/``general_PPLCNetV2_base_pretrained_v1.0_client/` 的文件夹。分别修改 `general_PPLCNetV2_base_pretrained_v1.0_serving/``general_PPLCNetV2_base_pretrained_v1.0_client/` 目录下的 `serving_server_conf.prototxt` 中的 `alias` 名字: 将 `fetch_var` 中的 `alias_name` 改为 `features`。 修改后的 `serving_server_conf.prototxt` 内容如下
```log ```log
feed_var { feed_var {
...@@ -132,7 +132,7 @@ python3.7 -m pip install paddle-serving-server-gpu==0.7.0.post112 # GPU with CUD ...@@ -132,7 +132,7 @@ python3.7 -m pip install paddle-serving-server-gpu==0.7.0.post112 # GPU with CUD
shape: 224 shape: 224
} }
fetch_var { fetch_var {
name: "save_infer_model/scale_0.tmp_1" name: "batch_norm_25.tmp_2"
alias_name: "features" alias_name: "features"
is_lod_tensor: false is_lod_tensor: false
fetch_type: 1 fetch_type: 1
...@@ -165,7 +165,7 @@ python3.7 -m pip install paddle-serving-server-gpu==0.7.0.post112 # GPU with CUD ...@@ -165,7 +165,7 @@ python3.7 -m pip install paddle-serving-server-gpu==0.7.0.post112 # GPU with CUD
# 回到deploy目录 # 回到deploy目录
cd ../ cd ../
# 下载构建完成的检索库 index # 下载构建完成的检索库 index
wget https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/data/drink_dataset_v1.0.tar wget https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/data/drink_dataset_v2.0.tar
# 解压构建完成的检索库 index # 解压构建完成的检索库 index
tar -xf drink_dataset_v1.0.tar tar -xf drink_dataset_v1.0.tar
``` ```
...@@ -175,7 +175,7 @@ python3.7 -m pip install paddle-serving-server-gpu==0.7.0.post112 # GPU with CUD ...@@ -175,7 +175,7 @@ python3.7 -m pip install paddle-serving-server-gpu==0.7.0.post112 # GPU with CUD
**注意:** 识别服务涉及到多个模型,出于性能考虑采用 PipeLine 部署方式。Pipeline 部署方式当前不支持 windows 平台。 **注意:** 识别服务涉及到多个模型,出于性能考虑采用 PipeLine 部署方式。Pipeline 部署方式当前不支持 windows 平台。
- 进入到工作目录 - 进入到工作目录
```shell ```shell
cd ./deploy/paddleserving/recognition cd ./paddleserving/recognition
``` ```
paddleserving 目录包含启动 Python Pipeline 服务、C++ Serving 服务和发送预测请求的代码,包括: paddleserving 目录包含启动 Python Pipeline 服务、C++ Serving 服务和发送预测请求的代码,包括:
```shell ```shell
...@@ -204,7 +204,7 @@ python3.7 -m pip install paddle-serving-server-gpu==0.7.0.post112 # GPU with CUD ...@@ -204,7 +204,7 @@ python3.7 -m pip install paddle-serving-server-gpu==0.7.0.post112 # GPU with CUD
``` ```
成功运行后,模型预测的结果会打印在客户端中,如下所示: 成功运行后,模型预测的结果会打印在客户端中,如下所示:
```log ```log
{'err_no': 0, 'err_msg': '', 'key': ['result'], 'value': ["[{'bbox': [345, 95, 524, 576], 'rec_docs': '红牛-强化型', 'rec_scores': 0.79903316}]"], 'tensors': []} {'err_no': 0, 'err_msg': '', 'key': ['result'], 'value': ["[{'bbox': [0, 0, 600, 600], 'rec_docs': '红牛-强化型', 'rec_scores': 0.7408101}]"], 'tensors': []}
``` ```
<a name="3.2.2"></a> <a name="3.2.2"></a>
...@@ -218,7 +218,7 @@ python3.7 -m pip install paddle-serving-server-gpu==0.7.0.post112 # GPU with CUD ...@@ -218,7 +218,7 @@ python3.7 -m pip install paddle-serving-server-gpu==0.7.0.post112 # GPU with CUD
# 一键编译安装Serving server、设置 SERVING_BIN # 一键编译安装Serving server、设置 SERVING_BIN
source ./build_server.sh python3.7 source ./build_server.sh python3.7
``` ```
**注:**[build_server.sh](../build_server.sh#L55-L62)所设定的路径可能需要根据实际机器上的环境如CUDA、python版本等作一定修改,然后再编译;如果执行`build_server.sh`过程中遇到非网络原因的报错,则可以手动将脚本中的命令逐条复制到终端执行。 **注:** [build_server.sh](../build_server.sh#L55-L62) 所设定的路径可能需要根据实际机器上的环境如CUDA、python版本等作一定修改,然后再编译;如果执行 `build_server.sh` 过程中遇到非网络原因的报错,则可以手动将脚本中的命令逐条复制到终端执行。
- C++ Serving使用的输入输出格式与Python不同,因此需要执行以下命令,将4个文件复制到下的文件覆盖掉[3.1](#31-模型转换)得到文件夹中的对应4个prototxt文件。 - C++ Serving使用的输入输出格式与Python不同,因此需要执行以下命令,将4个文件复制到下的文件覆盖掉[3.1](#31-模型转换)得到文件夹中的对应4个prototxt文件。
```shell ```shell
...@@ -226,8 +226,8 @@ python3.7 -m pip install paddle-serving-server-gpu==0.7.0.post112 # GPU with CUD ...@@ -226,8 +226,8 @@ python3.7 -m pip install paddle-serving-server-gpu==0.7.0.post112 # GPU with CUD
cd PaddleClas/deploy/ cd PaddleClas/deploy/
# 覆盖prototxt文件 # 覆盖prototxt文件
\cp ./paddleserving/recognition/preprocess/general_PPLCNet_x2_5_lite_v1.0_serving/*.prototxt ./models/general_PPLCNet_x2_5_lite_v1.0_serving/ \cp ./paddleserving/recognition/preprocess/general_PPLCNetV2_base_pretrained_v1.0_serving/*.prototxt ./models/general_PPLCNetV2_base_pretrained_v1.0_serving/
\cp ./paddleserving/recognition/preprocess/general_PPLCNet_x2_5_lite_v1.0_client/*.prototxt ./models/general_PPLCNet_x2_5_lite_v1.0_client/ \cp ./paddleserving/recognition/preprocess/general_PPLCNetV2_base_pretrained_v1.0_client/*.prototxt ./models/general_PPLCNetV2_base_pretrained_v1.0_client/
\cp ./paddleserving/recognition/preprocess/picodet_PPLCNet_x2_5_mainbody_lite_v1.0_client/*.prototxt ./models/picodet_PPLCNet_x2_5_mainbody_lite_v1.0_client/ \cp ./paddleserving/recognition/preprocess/picodet_PPLCNet_x2_5_mainbody_lite_v1.0_client/*.prototxt ./models/picodet_PPLCNet_x2_5_mainbody_lite_v1.0_client/
\cp ./paddleserving/recognition/preprocess/picodet_PPLCNet_x2_5_mainbody_lite_v1.0_serving/*.prototxt ./models/picodet_PPLCNet_x2_5_mainbody_lite_v1.0_serving/ \cp ./paddleserving/recognition/preprocess/picodet_PPLCNet_x2_5_mainbody_lite_v1.0_serving/*.prototxt ./models/picodet_PPLCNet_x2_5_mainbody_lite_v1.0_serving/
``` ```
...@@ -235,7 +235,7 @@ python3.7 -m pip install paddle-serving-server-gpu==0.7.0.post112 # GPU with CUD ...@@ -235,7 +235,7 @@ python3.7 -m pip install paddle-serving-server-gpu==0.7.0.post112 # GPU with CUD
- 启动服务: - 启动服务:
```shell ```shell
# 进入工作目录 # 进入工作目录
cd PaddleClas/deploy/paddleserving/recognition cd ./paddleserving/recognition
# 端口号默认为9400;运行日志默认保存在 log_PPShiTu.txt 中 # 端口号默认为9400;运行日志默认保存在 log_PPShiTu.txt 中
# CPU部署 # CPU部署
...@@ -254,7 +254,7 @@ python3.7 -m pip install paddle-serving-server-gpu==0.7.0.post112 # GPU with CUD ...@@ -254,7 +254,7 @@ python3.7 -m pip install paddle-serving-server-gpu==0.7.0.post112 # GPU with CUD
WARNING: Logging before InitGoogleLogging() is written to STDERR WARNING: Logging before InitGoogleLogging() is written to STDERR
I0614 03:01:36.273097 6084 naming_service_thread.cpp:202] brpc::policy::ListNamingService("127.0.0.1:9400"): added 1 I0614 03:01:36.273097 6084 naming_service_thread.cpp:202] brpc::policy::ListNamingService("127.0.0.1:9400"): added 1
I0614 03:01:37.393564 6084 general_model.cpp:490] [client]logid=0,client_cost=1107.82ms,server_cost=1101.75ms. I0614 03:01:37.393564 6084 general_model.cpp:490] [client]logid=0,client_cost=1107.82ms,server_cost=1101.75ms.
[{'bbox': [345, 95, 524, 585], 'rec_docs': '红牛-强化型', 'rec_scores': 0.8073724}] [{'bbox': [0, 0, 600, 600], 'rec_docs': '红牛-强化型', 'rec_scores': 0.7508101}]
``` ```
- 关闭服务 - 关闭服务
......
...@@ -23,7 +23,7 @@ Arch: ...@@ -23,7 +23,7 @@ Arch:
infer_output_key: features infer_output_key: features
infer_add_softmax: False infer_add_softmax: False
Backbone: Backbone:
name: PPLCNet_x2_5 name: PPLCNet_x2_5
pretrained: True pretrained: True
use_ssld: True use_ssld: True
...@@ -34,7 +34,7 @@ Arch: ...@@ -34,7 +34,7 @@ Arch:
embedding_size: 1280 embedding_size: 1280
class_num: 512 class_num: 512
Head: Head:
name: ArcMargin name: ArcMargin
embedding_size: 512 embedding_size: 512
class_num: 185341 class_num: 185341
margin: 0.2 margin: 0.2
...@@ -57,10 +57,9 @@ Optimizer: ...@@ -57,10 +57,9 @@ Optimizer:
learning_rate: 0.04 learning_rate: 0.04
warmup_epoch: 5 warmup_epoch: 5
regularizer: regularizer:
name: 'L2' name: "L2"
coeff: 0.00001 coeff: 0.00001
# data loader for train and eval # data loader for train and eval
DataLoader: DataLoader:
Train: Train:
...@@ -80,7 +79,7 @@ DataLoader: ...@@ -80,7 +79,7 @@ DataLoader:
scale: 1.0/255.0 scale: 1.0/255.0
mean: [0.485, 0.456, 0.406] mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225] std: [0.229, 0.224, 0.225]
order: '' order: ""
sampler: sampler:
name: DistributedBatchSampler name: DistributedBatchSampler
...@@ -93,7 +92,7 @@ DataLoader: ...@@ -93,7 +92,7 @@ DataLoader:
Eval: Eval:
Query: Query:
dataset: dataset:
name: VeriWild name: VeriWild
image_root: ./dataset/Aliproduct/ image_root: ./dataset/Aliproduct/
cls_label_path: ./dataset/Aliproduct/val_list.txt cls_label_path: ./dataset/Aliproduct/val_list.txt
...@@ -107,7 +106,7 @@ DataLoader: ...@@ -107,7 +106,7 @@ DataLoader:
scale: 0.00392157 scale: 0.00392157
mean: [0.485, 0.456, 0.406] mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225] std: [0.229, 0.224, 0.225]
order: '' order: ""
sampler: sampler:
name: DistributedBatchSampler name: DistributedBatchSampler
batch_size: 64 batch_size: 64
...@@ -118,7 +117,7 @@ DataLoader: ...@@ -118,7 +117,7 @@ DataLoader:
use_shared_memory: True use_shared_memory: True
Gallery: Gallery:
dataset: dataset:
name: VeriWild name: VeriWild
image_root: ./dataset/Aliproduct/ image_root: ./dataset/Aliproduct/
cls_label_path: ./dataset/Aliproduct/val_list.txt cls_label_path: ./dataset/Aliproduct/val_list.txt
...@@ -132,7 +131,7 @@ DataLoader: ...@@ -132,7 +131,7 @@ DataLoader:
scale: 0.00392157 scale: 0.00392157
mean: [0.485, 0.456, 0.406] mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225] std: [0.229, 0.224, 0.225]
order: '' order: ""
sampler: sampler:
name: DistributedBatchSampler name: DistributedBatchSampler
batch_size: 64 batch_size: 64
...@@ -146,3 +145,4 @@ Metric: ...@@ -146,3 +145,4 @@ Metric:
Eval: Eval:
- Recallk: - Recallk:
topk: [1, 5] topk: [1, 5]
- mAP: {}
...@@ -20,8 +20,8 @@ Arch: ...@@ -20,8 +20,8 @@ Arch:
name: RecModel name: RecModel
infer_output_key: features infer_output_key: features
infer_add_softmax: False infer_add_softmax: False
Backbone: Backbone:
name: MobileNetV1 name: MobileNetV1
pretrained: False pretrained: False
BackboneStopLayer: BackboneStopLayer:
...@@ -31,12 +31,12 @@ Arch: ...@@ -31,12 +31,12 @@ Arch:
embedding_size: 1024 embedding_size: 1024
class_num: 512 class_num: 512
Head: Head:
name: ArcMargin name: ArcMargin
embedding_size: 512 embedding_size: 512
class_num: 101 class_num: 101
margin: 0.15 margin: 0.15
scale: 30 scale: 30
# loss function config for traing/eval process # loss function config for traing/eval process
Loss: Loss:
Train: Train:
...@@ -60,7 +60,7 @@ Optimizer: ...@@ -60,7 +60,7 @@ Optimizer:
verbose: False verbose: False
last_epoch: -1 last_epoch: -1
regularizer: regularizer:
name: 'L2' name: "L2"
coeff: 0.0005 coeff: 0.0005
# data loader for train and eval # data loader for train and eval
...@@ -82,7 +82,7 @@ DataLoader: ...@@ -82,7 +82,7 @@ DataLoader:
scale: 0.00392157 scale: 0.00392157
mean: [0.485, 0.456, 0.406] mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225] std: [0.229, 0.224, 0.225]
order: '' order: ""
- RandomErasing: - RandomErasing:
EPSILON: 0.5 EPSILON: 0.5
sl: 0.02 sl: 0.02
...@@ -98,10 +98,10 @@ DataLoader: ...@@ -98,10 +98,10 @@ DataLoader:
loader: loader:
num_workers: 4 num_workers: 4
use_shared_memory: True use_shared_memory: True
Eval: Eval:
Query: Query:
dataset: dataset:
name: VeriWild name: VeriWild
image_root: ./dataset/CUB_200_2011/ image_root: ./dataset/CUB_200_2011/
cls_label_path: ./dataset/CUB_200_2011/test_list.txt cls_label_path: ./dataset/CUB_200_2011/test_list.txt
...@@ -115,7 +115,7 @@ DataLoader: ...@@ -115,7 +115,7 @@ DataLoader:
scale: 0.00392157 scale: 0.00392157
mean: [0.485, 0.456, 0.406] mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225] std: [0.229, 0.224, 0.225]
order: '' order: ""
sampler: sampler:
name: DistributedBatchSampler name: DistributedBatchSampler
batch_size: 64 batch_size: 64
...@@ -126,7 +126,7 @@ DataLoader: ...@@ -126,7 +126,7 @@ DataLoader:
use_shared_memory: True use_shared_memory: True
Gallery: Gallery:
dataset: dataset:
name: VeriWild name: VeriWild
image_root: ./dataset/CUB_200_2011/ image_root: ./dataset/CUB_200_2011/
cls_label_path: ./dataset/CUB_200_2011/test_list.txt cls_label_path: ./dataset/CUB_200_2011/test_list.txt
...@@ -140,7 +140,7 @@ DataLoader: ...@@ -140,7 +140,7 @@ DataLoader:
scale: 1.0/255.0 scale: 1.0/255.0
mean: [0.485, 0.456, 0.406] mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225] std: [0.229, 0.224, 0.225]
order: '' order: ""
sampler: sampler:
name: DistributedBatchSampler name: DistributedBatchSampler
batch_size: 64 batch_size: 64
...@@ -155,4 +155,3 @@ Metric: ...@@ -155,4 +155,3 @@ Metric:
- Recallk: - Recallk:
topk: [1, 5] topk: [1, 5]
- mAP: {} - mAP: {}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册