未验证 提交 cb8f9d79 编写于 作者: C cuicheng01 提交者: GitHub

Merge pull request #2046 from TingquanGao/dev/add_en_doc

docs: add en doc
# PULC Quick Start
------
This document introduces the prediction using PULC series model based on PaddleClas wheel.
## Catalogue
- [1. Installation](#1)
- [1.1 PaddlePaddle Installation](#11)
- [1.2 PaddleClas wheel Installation](#12)
- [2. Quick Start](#2)
- [2.1 Predicion with Command Line](#2.1)
- [2.2 Predicion with Python](#2.2)
- [2.3 Supported Model List](#2.3)
- [3. Summary](#3)
<a name="1"></a>
## 1. Installation
<a name="1.1"></a>
### 1.1 PaddlePaddle Installation
- Run the following command to install if CUDA9 or CUDA10 is available.
```bash
python3 -m pip install paddlepaddle-gpu -i https://mirror.baidu.com/pypi/simple
```
- Run the following command to install if GPU device is unavailable.
```bash
python3 -m pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple
```
Please refer to [PaddlePaddle Installation](https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/en/install/pip/linux-pip_en.html) for more information about installation, for examples other versions.
<a name="1.2"></a>
### 1.2 PaddleClas wheel Installation
```bash
pip3 install paddleclas
```
<a name="2"></a>
## 2. Quick Start
PaddleClas provides a series of test cases, which contain demos of different scenes about people, cars, OCR, etc. Click [here](https://paddleclas.bj.bcebos.com/data/PULC/pulc_demo_imgs.zip) to download the data.
<a name="2.1"></a>
### 2.1 Predicion with Command Line
```
cd /path/to/pulc_demo_imgs
```
The prediction command:
```bash
paddleclas --model_name=person_exists --infer_imgs=pulc_demo_imgs/person_exists/objects365_01780782.jpg
```
Result:
```
>>> result
class_ids: [0], scores: [0.9955421453341842], label_names: ['nobody'], filename: pulc_demo_imgs/person_exists/objects365_01780782.jpg
Predict complete!
```
`Nobody` means there is no one in the image, `someone` means there is someone in the image. Therefore, the prediction result indicates that there is no one in the figure.
**Note**: The "--infer_imgs" argument specify the image(s) to be predict, and you can also specify a directoy contains images. If use other model, you can specify the `--model_name` argument. Please refer to [2.3 Supported Model List](#2.3) for the supported model list.
<a name="2.2"></a>
### 2.2 Predicion with Python
You can also use in Python:
```python
import paddleclas
model = paddleclas.PaddleClas(model_name="person_exists")
result = model.predict(input_data="pulc_demo_imgs/person_exists/objects365_01780782.jpg")
print(next(result))
```
The printed result information:
```
>>> result
[{'class_ids': [0], 'scores': [0.9955421453341842], 'label_names': ['nobody'], 'filename': 'pulc_demo_imgs/person_exists/objects365_01780782.jpg'}]
```
**Note**: `model.predict()` is a generator, so `next()` or `for` is needed to call it. This would to predict by batch that length is `batch_size`, default by 1. You can specify the argument `batch_size` and `model_name` when instantiating PaddleClas object, for example: `model = paddleclas.PaddleClas(model_name="person_exists", batch_size=2)`. Please refer to [2.3 Supported Model List](#2.3) for the supported model list.
<a name="2.3"></a>
### 2.3 Supported Model List
The name of PULC series models are as follows:
| Name | Intro |
| --- | --- |
| person_exists | Human Exists Classification |
| person_attribute | Pedestrian Attribute Classification |
| safety_helmet | Classification of Wheather Wearing Safety Helmet |
| traffic_sign | Traffic Sign Classification |
| vehicle_attribute | Vehicle Attribute Classification |
| car_exists | Car Exists Classification |
| text_image_orientation | Text Image Orientation Classification |
| textline_orientation | Text-line Orientation Classification |
| language_classification | Language Classification |
<a name="3"></a>
## 3. Summary
The PULC series models have been verified to be effective in different scenarios about people, vehicles, OCR, etc. The ultra lightweight model can achieve the accuracy close to SwinTransformer model, and the speed is increased by 40+ times. And PULC also provides the whole process of dataset getting, model training, model compression and deployment. Please refer to [Human Exists Classification](PULC_person_exists_en.md)[Pedestrian Attribute Classification](PULC_person_attribute_en.md)[Classification of Wheather Wearing Safety Helmet](PULC_safety_helmet_en.md)[Traffic Sign Classification](PULC_traffic_sign_en.md)[Vehicle Attribute Classification](PULC_vehicle_attribute_en.md)[Car Exists Classification](PULC_car_exists_en.md)[Text Image Orientation Classification](PULC_text_image_orientation_en.md)[Text-line Orientation Classification](PULC_textline_orientation_en.md)[Language Classification](PULC_language_classification_en.md) for more information about different scenarios.
# PaddleClas wheel package # PaddleClas wheel package
Paddleclas supports Python WHL package for prediction. At present, WHL package only supports image classification, but does not support subject detection, feature extraction and vector retrieval. PaddleClas supports Python wheel package for prediction. At present, PaddleClas wheel supports image classification including ImagetNet1k models and PULC models, but does not support mainbody detection, feature extraction and vector retrieval.
--- ---
...@@ -9,7 +9,7 @@ Paddleclas supports Python WHL package for prediction. At present, WHL package o ...@@ -9,7 +9,7 @@ Paddleclas supports Python WHL package for prediction. At present, WHL package o
- [1. Installation](#1) - [1. Installation](#1)
- [2. Quick Start](#2) - [2. Quick Start](#2)
- [3. Definition of Parameters](#3) - [3. Definition of Parameters](#3)
- [4. Usage](#4) - [4. More usage](#4)
- [4.1 View help information](#4.1) - [4.1 View help information](#4.1)
- [4.2 Prediction using inference model provide by PaddleClas](#4.2) - [4.2 Prediction using inference model provide by PaddleClas](#4.2)
- [4.3 Prediction using local model files](#4.3) - [4.3 Prediction using local model files](#4.3)
...@@ -20,6 +20,7 @@ Paddleclas supports Python WHL package for prediction. At present, WHL package o ...@@ -20,6 +20,7 @@ Paddleclas supports Python WHL package for prediction. At present, WHL package o
- [4.8 Specify the mapping between class id and label name](#4.8) - [4.8 Specify the mapping between class id and label name](#4.8)
<a name="1"></a> <a name="1"></a>
## 1. Installation ## 1. Installation
* installing from pypi * installing from pypi
...@@ -36,8 +37,14 @@ pip3 install dist/* ...@@ -36,8 +37,14 @@ pip3 install dist/*
``` ```
<a name="2"></a> <a name="2"></a>
## 2. Quick Start ## 2. Quick Start
* Using the `ResNet50` model provided by PaddleClas, the following image(`'docs/images/inference_deployment/whl_demo.jpg'`) as an example.
<a name="2.1"></a>
### 2.1 ImageNet1k models
Using the `ResNet50` model provided by PaddleClas, the following image(`'docs/images/inference_deployment/whl_demo.jpg'`) as an example.
![](../../images/inference_deployment/whl_demo.jpg) ![](../../images/inference_deployment/whl_demo.jpg)
...@@ -68,25 +75,89 @@ filename: docs/images/inference_deployment/whl_demo.jpg, top-5, class_ids: [8, 7 ...@@ -68,25 +75,89 @@ filename: docs/images/inference_deployment/whl_demo.jpg, top-5, class_ids: [8, 7
Predict complete! Predict complete!
``` ```
<a name="2.2"></a>
### 2.2 PULC models
PULC integrates various state-of-the-art algorithms such as backbone network, data augmentation and distillation, etc., and finally can automatically obtain a lightweight and high-precision image classification model.
PaddleClas provides a series of test cases, which contain demos of different scenes about people, cars, OCR, etc. Click [here](https://paddleclas.bj.bcebos.com/data/PULC/pulc_demo_imgs.zip) to download the data.
Prection using the PULC "Human Exists Classification" model provided by PaddleClas:
* Python
```python
import paddleclas
model = paddleclas.PaddleClas(model_name="person_exists")
result = model.predict(input_data="pulc_demo_imgs/person_exists/objects365_01780782.jpg")
print(next(result))
```
```
>>> result
[{'class_ids': [0], 'scores': [0.9955421453341842], 'label_names': ['nobody'], 'filename': 'pulc_demo_imgs/person_exists/objects365_01780782.jpg'}]
```
`Nobody` means there is no one in the image, `someone` means there is someone in the image. Therefore, the prediction result indicates that there is no one in the figure.
**Note**: `model.predict()` is a generator, so `next()` or `for` is needed to call it. This would to predict by batch that length is `batch_size`, default by 1. You can specify the argument `batch_size` and `model_name` when instantiating PaddleClas object, for example: `model = paddleclas.PaddleClas(model_name="person_exists", batch_size=2)`. Please refer to [Supported Model List](#PULC_Models) for the supported model list.
* CLI
```bash
paddleclas --model_name=person_exists --infer_imgs=pulc_demo_imgs/person_exists/objects365_01780782.jpg
```
```
>>> result
class_ids: [0], scores: [0.9955421453341842], label_names: ['nobody'], filename: pulc_demo_imgs/person_exists/objects365_01780782.jpg
Predict complete!
```
**Note**: The "--infer_imgs" argument specify the image(s) to be predict, and you can also specify a directoy contains images. If use other model, you can specify the `--model_name` argument. Please refer to [Supported Model List](#PULC_Models) for the supported model list.
<a name="PULC_Models"></a>
**Supported Model List**
The name of PULC series models are as follows:
| Name | Intro |
| --- | --- |
| person_exists | Human Exists Classification |
| person_attribute | Pedestrian Attribute Classification |
| safety_helmet | Classification of Wheather Wearing Safety Helmet |
| traffic_sign | Traffic Sign Classification |
| vehicle_attribute | Vehicle Attribute Classification |
| car_exists | Car Exists Classification |
| text_image_orientation | Text Image Orientation Classification |
| textline_orientation | Text-line Orientation Classification |
| language_classification | Language Classification |
Please refer to [Human Exists Classification](../PULC/PULC_person_exists_en.md)[Pedestrian Attribute Classification](../PULC/PULC_person_attribute_en.md)[Classification of Wheather Wearing Safety Helmet](../PULC/PULC_safety_helmet_en.md)[Traffic Sign Classification](../PULC/PULC_traffic_sign_en.md)[Vehicle Attribute Classification](../PULC/PULC_vehicle_attribute_en.md)[Car Exists Classification](../PULC/PULC_car_exists_en.md)[Text Image Orientation Classification](../PULC/PULC_text_image_orientation_en.md)[Text-line Orientation Classification](../PULC/PULC_textline_orientation_en.md)[Language Classification](../PULC/PULC_language_classification_en.md) for more information about different scenarios.
<a name="3"></a> <a name="3"></a>
## 3. Definition of Parameters ## 3. Definition of Parameters
The following parameters can be specified in Command Line or used as parameters of the constructor when instantiating the PaddleClas object in Python. The following parameters can be specified in Command Line or used as parameters of the constructor when instantiating the PaddleClas object in Python.
* model_name(str): If using inference model based on ImageNet1k provided by Paddle, please specify the model's name by the parameter. * model_name(str): If using inference model based on ImageNet1k provided by Paddle, please specify the model's name by the parameter.
* inference_model_dir(str): Local model files directory, which is valid when `model_name` is not specified. The directory should contain `inference.pdmodel` and `inference.pdiparams`. * inference_model_dir(str): Local model files directory, which is valid when `model_name` is not specified. The directory should contain `inference.pdmodel` and `inference.pdiparams`.
* infer_imgs(str): The path of image to be predicted, or the directory containing the image files, or the URL of the image from Internet. * infer_imgs(str): The path of image to be predicted, or the directory containing the image files, or the URL of the image from Internet.
* use_gpu(bool): Whether to use GPU or not, default by `True`. * use_gpu(bool): Whether to use GPU or not.
* gpu_mem(int): GPU memory usages,default by `8000` * gpu_mem(int): GPU memory usages.
* use_tensorrt(bool): Whether to open TensorRT or not. Using it can greatly promote predict preformance, default by `False`. * use_tensorrt(bool): Whether to open TensorRT or not. Using it can greatly promote predict preformance.
* enable_mkldnn(bool): Whether enable MKLDNN or not, default `False`. * enable_mkldnn(bool): Whether enable MKLDNN or not.
* cpu_num_threads(int): Assign number of cpu threads, valid when `--use_gpu` is `False` and `--enable_mkldnn` is `True`, default by `10`. * cpu_num_threads(int): Assign number of cpu threads, valid when `--use_gpu` is `False` and `--enable_mkldnn` is `True`.
* batch_size(int): Batch size, default by `1`. * batch_size(int): Batch size.
* resize_short(int): Resize the minima between height and width into `resize_short`, default by `256`. * resize_short(int): Resize the minima between height and width into `resize_short`.
* crop_size(int): Center crop image to `crop_size`, default by `224`. * crop_size(int): Center crop image to `crop_size`.
* topk(int): Print (return) the `topk` prediction results, default by `5`. * topk(int): Print (return) the `topk` prediction results when Topk postprocess is used.
* class_id_map_file(str): The mapping file between class ID and label, default by `ImageNet1K` dataset's mapping. * threshold(float): The threshold of ThreshOutput when postprocess is used.
* pre_label_image(bool): whether prelabel or not, default=False. * class_id_map_file(str): The mapping file between class ID and label.
* save_dir(str): The directory to save the prediction results that can be used as pre-label, default by `None`, that is, not to save. * save_dir(str): The directory to save the prediction results that can be used as pre-label.
**Note**: If you want to use `Transformer series models`, such as `DeiT_***_384`, `ViT_***_384`, etc., please pay attention to the input size of model, and need to set `resize_short=384`, `resize=384`. The following is a demo. **Note**: If you want to use `Transformer series models`, such as `DeiT_***_384`, `ViT_***_384`, etc., please pay attention to the input size of model, and need to set `resize_short=384`, `resize=384`. The following is a demo.
...@@ -103,6 +174,7 @@ clas = PaddleClas(model_name='ViT_base_patch16_384', resize_short=384, crop_size ...@@ -103,6 +174,7 @@ clas = PaddleClas(model_name='ViT_base_patch16_384', resize_short=384, crop_size
``` ```
<a name="4"></a> <a name="4"></a>
## 4. Usage ## 4. Usage
PaddleClas provides two ways to use: PaddleClas provides two ways to use:
...@@ -110,6 +182,7 @@ PaddleClas provides two ways to use: ...@@ -110,6 +182,7 @@ PaddleClas provides two ways to use:
2. Bash command line programming. 2. Bash command line programming.
<a name="4.1"></a> <a name="4.1"></a>
### 4.1 View help information ### 4.1 View help information
* CLI * CLI
...@@ -118,6 +191,7 @@ paddleclas -h ...@@ -118,6 +191,7 @@ paddleclas -h
``` ```
<a name="4.2"></a> <a name="4.2"></a>
### 4.2 Prediction using inference model provide by PaddleClas ### 4.2 Prediction using inference model provide by PaddleClas
You can use the inference model provided by PaddleClas to predict, and only need to specify `model_name`. In this case, PaddleClas will automatically download files of specified model and save them in the directory `~/.paddleclas/`. You can use the inference model provided by PaddleClas to predict, and only need to specify `model_name`. In this case, PaddleClas will automatically download files of specified model and save them in the directory `~/.paddleclas/`.
...@@ -136,6 +210,7 @@ paddleclas --model_name='ResNet50' --infer_imgs='docs/images/inference_deploymen ...@@ -136,6 +210,7 @@ paddleclas --model_name='ResNet50' --infer_imgs='docs/images/inference_deploymen
``` ```
<a name="4.3"></a> <a name="4.3"></a>
### 4.3 Prediction using local model files ### 4.3 Prediction using local model files
You can use the local model files trained by yourself to predict, and only need to specify `inference_model_dir`. Note that the directory must contain `inference.pdmodel` and `inference.pdiparams`. You can use the local model files trained by yourself to predict, and only need to specify `inference_model_dir`. Note that the directory must contain `inference.pdmodel` and `inference.pdiparams`.
...@@ -154,6 +229,7 @@ paddleclas --inference_model_dir='./inference/' --infer_imgs='docs/images/infere ...@@ -154,6 +229,7 @@ paddleclas --inference_model_dir='./inference/' --infer_imgs='docs/images/infere
``` ```
<a name="4.4"></a> <a name="4.4"></a>
### 4.4 Prediction by batch ### 4.4 Prediction by batch
You can predict by batch, only need to specify `batch_size` when `infer_imgs` is direcotry contain image files. You can predict by batch, only need to specify `batch_size` when `infer_imgs` is direcotry contain image files.
...@@ -173,6 +249,7 @@ paddleclas --model_name='ResNet50' --infer_imgs='docs/images/' --batch_size 2 ...@@ -173,6 +249,7 @@ paddleclas --model_name='ResNet50' --infer_imgs='docs/images/' --batch_size 2
``` ```
<a name="4.5"></a> <a name="4.5"></a>
### 4.5 Prediction of Internet image ### 4.5 Prediction of Internet image
You can predict the Internet image, only need to specify URL of Internet image by `infer_imgs`. In this case, the image file will be downloaded and saved in the directory `~/.paddleclas/images/`. You can predict the Internet image, only need to specify URL of Internet image by `infer_imgs`. In this case, the image file will be downloaded and saved in the directory `~/.paddleclas/images/`.
...@@ -191,6 +268,7 @@ paddleclas --model_name='ResNet50' --infer_imgs='https://raw.githubusercontent.c ...@@ -191,6 +268,7 @@ paddleclas --model_name='ResNet50' --infer_imgs='https://raw.githubusercontent.c
``` ```
<a name="4.6"></a> <a name="4.6"></a>
### 4.6 Prediction of NumPy.array format image ### 4.6 Prediction of NumPy.array format image
In Python code, you can predict the `NumPy.array` format image, only need to use the `infer_imgs` to transfer variable of image data. Note that the models in PaddleClas only support to predict 3 channels image data, and channels order is `RGB`. In Python code, you can predict the `NumPy.array` format image, only need to use the `infer_imgs` to transfer variable of image data. Note that the models in PaddleClas only support to predict 3 channels image data, and channels order is `RGB`.
...@@ -205,6 +283,7 @@ print(next(result)) ...@@ -205,6 +283,7 @@ print(next(result))
``` ```
<a name="4.7"></a> <a name="4.7"></a>
### 4.7 Save the prediction result(s) ### 4.7 Save the prediction result(s)
You can save the prediction result(s) as pre-label, only need to use `pre_label_out_dir` to specify the directory to save. You can save the prediction result(s) as pre-label, only need to use `pre_label_out_dir` to specify the directory to save.
...@@ -223,6 +302,7 @@ paddleclas --model_name='ResNet50' --infer_imgs='docs/images/' --save_dir='./out ...@@ -223,6 +302,7 @@ paddleclas --model_name='ResNet50' --infer_imgs='docs/images/' --save_dir='./out
``` ```
<a name="4.8"></a> <a name="4.8"></a>
### 4.8 Specify the mapping between class id and label name ### 4.8 Specify the mapping between class id and label name
You can specify the mapping between class id and label name, only need to use `class_id_map_file` to specify the mapping file. PaddleClas uses ImageNet1K's mapping by default. You can specify the mapping between class id and label name, only need to use `class_id_map_file` to specify the mapping file. PaddleClas uses ImageNet1K's mapping by default.
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
------ ------
本文主要介绍PaddleClas whl包对 PULC 系列模型的快速使用 本文主要介绍通过 PaddleClas whl 包,使用 PULC 系列模型进行预测
## 目录 ## 目录
...@@ -49,9 +49,7 @@ pip3 install paddleclas ...@@ -49,9 +49,7 @@ pip3 install paddleclas
## 2. 快速体验 ## 2. 快速体验
PaddleClas 提供了一系列测试图片,里边包含人、车、OCR等方向的多个场景大的demo数据。点击[这里](https://paddleclas.bj.bcebos.com/data/PULC/pulc_demo_imgs.zip)下载并解压,然后在终端中切换到相应目录。 PaddleClas 提供了一系列测试图片,里边包含人、车、OCR等方向的多个场景的demo数据。点击[这里](https://paddleclas.bj.bcebos.com/data/PULC/pulc_demo_imgs.zip)下载并解压,然后在终端中切换到相应目录。
<a name="2.1"></a> <a name="2.1"></a>
...@@ -125,7 +123,3 @@ PULC 系列模型的名称和简介如下: ...@@ -125,7 +123,3 @@ PULC 系列模型的名称和简介如下:
通过本节内容,相信您已经熟练掌握 PaddleClas whl 包的 PULC 模型使用方法并获得了初步效果。 通过本节内容,相信您已经熟练掌握 PaddleClas whl 包的 PULC 模型使用方法并获得了初步效果。
PULC 方法产出的系列模型在人、车、OCR等方向的多个场景中均验证有效,用超轻量模型就可实现与 SwinTransformer 模型接近的精度,预测速度提高 40+ 倍。并且打通数据、模型训练、压缩和推理部署全流程,具体地,您可以参考[PULC有人/无人分类模型](PULC_person_exists.md)[PULC人体属性识别模型](PULC_person_attribute.md)[PULC佩戴安全帽分类模型](PULC_safety_helmet.md)[PULC交通标志分类模型](PULC_traffic_sign.md)[PULC车辆属性识别模型](PULC_vehicle_attribute.md)[PULC有车/无车分类模型](PULC_car_exists.md)[PULC含文字图像方向分类模型](PULC_text_image_orientation.md)[PULC文本行方向分类模型](PULC_textline_orientation.md)[PULC语种分类模型](PULC_language_classification.md) PULC 方法产出的系列模型在人、车、OCR等方向的多个场景中均验证有效,用超轻量模型就可实现与 SwinTransformer 模型接近的精度,预测速度提高 40+ 倍。并且打通数据、模型训练、压缩和推理部署全流程,具体地,您可以参考[PULC有人/无人分类模型](PULC_person_exists.md)[PULC人体属性识别模型](PULC_person_attribute.md)[PULC佩戴安全帽分类模型](PULC_safety_helmet.md)[PULC交通标志分类模型](PULC_traffic_sign.md)[PULC车辆属性识别模型](PULC_vehicle_attribute.md)[PULC有车/无车分类模型](PULC_car_exists.md)[PULC含文字图像方向分类模型](PULC_text_image_orientation.md)[PULC文本行方向分类模型](PULC_textline_orientation.md)[PULC语种分类模型](PULC_language_classification.md)
...@@ -298,7 +298,7 @@ def args_cfg(): ...@@ -298,7 +298,7 @@ def args_cfg():
parser.add_argument( parser.add_argument(
"--use_tensorrt", "--use_tensorrt",
type=str2bool, type=str2bool,
help="Whether use TensorRT to accelerate. ") help="Whether use TensorRT to accelerate.")
parser.add_argument( parser.add_argument(
"--use_fp16", type=str2bool, help="Whether use FP16 to predict.") "--use_fp16", type=str2bool, help="Whether use FP16 to predict.")
parser.add_argument("--batch_size", type=int, help="Batch size.") parser.add_argument("--batch_size", type=int, help="Batch size.")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册