@@ -4,7 +4,23 @@ The mainbody detection technology is currently a widely used detection technolog
This tutorial will introduce the technology from three aspects, namely, the datasets, model selection and model training.
## Dataset
## Catalogue
-[1. Dataset](#1)
-[2. Model Selection](#2)
-[2.1 Lightweight Mainbody Detection Model](#2.1)
-[2.2 Server-side Mainbody Detection Model](#2.2)
-[3. Model Training](#3)
-[3.1 Prepare For the Environment](#3.1)
-[3.2 Prepare For the Dataset](#3.2)
-[3.3 Configuration Files](#3.3)
-[3.4 Begin the Training Process](#3.4)
-[3.5 Model Prediction](#3.5)
-[3.6 Model Export and Inference Deployment](#3.6)
<aname="1"></a>
## 1. Dataset
The datasets we used for mainbody detection tasks are shown in the following table.
...
...
@@ -18,7 +34,9 @@ The datasets we used for mainbody detection tasks are shown in the following tab
In the actual training process, all datasets are mixed together. Categories of all the labeled boxes are modified as `foreground`, and the detection model we trained only contains one category (`foreground`).
## Model Selection
<aname="2"></a>
## 2. Model Selection
There are a wide variety of object detection methods, such as the commonly used two-stage detectors (FasterRCNN series, etc.), single-stage detectors (YOLO, SSD, etc.), anchor-free detectors (FCOS, etc.) and so on. PaddleDetection has its self-developed PP-YOLO models for server-side scenarios and PicoDet models for end-side scenarios (CPU and mobile), which all take the lead in the area.
...
...
@@ -34,7 +52,9 @@ Notes:
- Detailed information of the CPU of the speed evaluation machine:`Intel(R) Xeon(R) Gold 6148 CPU @ 2.40GHz`.The speed indicator is the testing result when mkldnn is on and the number of threads is set to 10.
- Mainbody detection has a time-consuming preprocessing procedure, with an average time of about 40 to 55 ms per image in the above machine. Therefore, it is not included in the inference time.
### Lightweight Mainbody Detection Model
<aname="2.1"></a>
### 2.1 Lightweight Mainbody Detection Model
PicoDet, introduced by [PaddleDetection](https://github.com/PaddlePaddle/PaddleDetection), is an object detection algorithm applied to CPU or mobile-side scenarios. It integrates the following optimization algorithm.
...
...
@@ -48,7 +68,9 @@ For more details of optimized PicoDet and benchmark, you can refer to [Tutorial
To balance the detection speed and effects in lightweight mainbody detection tasks, we adopt PPLCNet_x2_5 as the backbone of the model and revise the image scale for training and inference to 640x640, with the rest configured the same as [picodet_m_shufflenetv2_416_coco.yml](https://github.com/PaddlePaddle/PaddleDetection/blob/develop/configs/picodet/picodet_m_shufflenetv2_416_coco.yml). The final detection model is obtained after the training of customized mainbody detection datasets.
### Server-side Mainbody Detection Model
<aname="2.2"></a>
### 2.2 Server-side Mainbody Detection Model
PP-YOLO is proposed by [PaddleDetection](https://github.com/PaddlePaddle/PaddleDetection). It greatly optimizes the yolov3 model from multiple perspectives such as backbone, data augmentation, regularization strategy, loss function, and post-processing. It reaches the state of the art in terms of "speed-precision". The optimization strategy is as follows.
...
...
@@ -67,11 +89,15 @@ For more information about PP-YOLO, you can refer to [PP-YOLO tutorial](https://
In the mainbody detection task, we use `ResNet50vd-DCN` as our backbone for better performance. The config file is [ppyolov2_r50vd_dcn_365e_coco.yml](https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.1/configs/ppyolo/ppyolov2_r50vd_dcn_365e_coco.yml), in which the dataset path is modified to the customized mainbody detection dataset. The final detection model can be downloaded [here](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/models/inference/ppyolov2_r50vd_dcn_mainbody_v1.0_infer.tar).
## Model Training
<aname="3"></a>
## 3 Model Training
This section mainly talks about how to train your own mainbody detection model using PaddleDetection on your own datasets.
### Prepare For the Environment
<aname="3.1"></a>
### 3.1 Prepare For the Environment
Download PaddleDetection and install requirements.
For more installation tutorials, please refer to [Installation Tutorial](https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.1/docs/tutorials/INSTALL.md)
### Prepare For the Dataset
<aname="3.2"></a>
### 3.2 Prepare For the Dataset
For customized dataset, you should convert it to COCO format. Please refer to [Customized Dataset Tutorial](https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.1/static/docs/tutorials/Custom_DataSet.md) to build your own datasets with COCO format.
...
...
@@ -96,11 +124,13 @@ In mainbody detection task, all the objects belong to foregroud. Therefore, `cat
@@ -122,7 +152,9 @@ In mainbody detection task, you need to modify `num_classes` in `datasets/coco_d
In addition, the above files can also be modified according to real situations, for example, if the video memory is overflowing, the batch size and learning rate can be reduced in equal proportion.
### Begin the Training Process
<aname="3.4"></a>
### 3.4 Begin the Training Process
PaddleDetection supports many ways of training process.
`--draw_threshold` is an optional parameter. According to NMS calculation, different thresholds will produce different results. `keep_top_k` indicates the maximum number of output targets, with a default value of 100 that can be modified according to their actual situation.
### Model Export and Inference Deployment
<aname="3.6"></a>
### 3.6 Model Export and Inference Deployment
Use the following to export the inference model:
...
...
@@ -191,7 +227,7 @@ The final directory contains `inference/ppyolov2_r50vd_dcn_365e_coco`, `inferen
After exporting the model, the path of the detection model can be changed to the inference model path to complete the prediction task.
Take product recognition as an example,you can modify the field `Global.det_inference_model_dir` in its config file [inference_product.yaml](https://github.com/PaddlePaddle/PaddleClas/blob/develop/deploy/configs/inference_product.yaml) to the directory of exported inference model, and then finish the detection and recognition of the product with reference to [Quick Start for Image Recognition](https://github.com/PaddlePaddle/PaddleClas/blob/develop/docs/zh_CN_tmp/tutorials/quick_start_recognition.md).
Take product recognition as an example,you can modify the field `Global.det_inference_model_dir` in its config file [inference_product.yaml](../../../deploy/configs/inference_product.yaml) to the directory of exported inference model, and then finish the detection and recognition of the product with reference to [Quick Start for Image Recognition](./quick_start/quick_start_recognition_en.md).
As shown in the figure above, two parts constitute the vector search in the whole `PP-ShiTu` system.
...
...
@@ -20,15 +20,15 @@ This document mainly introduces the installation of the search module in PaddleC
------
## Contents
-[1. Installation of the Search Library](https://github.com/PaddlePaddle/PaddleClas/blob/develop/docs/zh_CN/image_recognition_pipeline/vector_search.md#1)
-[3. Introduction of and Configuration Files](https://github.com/PaddlePaddle/PaddleClas/blob/develop/docs/zh_CN/image_recognition_pipeline/vector_search.md#3)
-[3.1 Parameters of Library Building and Configuration Files](https://github.com/PaddlePaddle/PaddleClas/blob/develop/docs/zh_CN/image_recognition_pipeline/vector_search.md#3.1)
-[3.2 Parameters of Search Configuration Files](https://github.com/PaddlePaddle/PaddleClas/blob/develop/docs/zh_CN/image_recognition_pipeline/vector_search.md#3.2)
## Catalogue
-[1. Installation of the Search Library](#1)
-[2. Search Algorithms](#2)
-[3. Introduction of and Configuration Files](#3)
-[3.1 Parameters of Library Building and Configuration Files](#3.1)
-[3.2 Parameters of Search Configuration Files](#3.2)
If the above cannot be properly used, please `uninstall` and then `install` again, especially when you are using`windows`.
<aname="2"></a>
## 2. Search Algorithms
Currently, the search module in `PaddleClas` supports the following three search algorithms:
...
...
@@ -50,10 +52,14 @@ Currently, the search module in `PaddleClas` supports the following three search
Each search algorithm can find its right place in different scenarios. `HNSW32`, as the default method, strikes a balance between accuracy and speed, see its detailed introduction in the [official document](https://github.com/facebookresearch/faiss/wiki).
<aname="3"></a>
## 3. Introduction of Configuration Files
Configuration files involving the search module are under `deploy/configs/`, where `build_*.yaml` is related to building the feature library, and `inference_*.yaml` is the inference file for retrieval or classification.
<aname="3.1"></a>
### 3.1 Parameters of Library Building and Configuration Files
The building of the library is detailed as follows:
...
...
@@ -93,11 +99,11 @@ IndexProcess:
-**dist_type**: the method of similarity calculation adopted in feature matching. For example, Inner Product(`IP`) and Euclidean distance(`L2`).
-**embedding_size**: feature dimensionality
<aname="3.2"></a>
### 3.2 Parameters of Search Configuration Files
To integrate the search into the overall `PP-ShiTu` process, please refer to `The Introduction of PP-ShiTu Image Recognition System` in [README](https://github.com/PaddlePaddle/PaddleClas/blob/develop/README_ch.md). Please check the [Quick Start for Image Recognition](https://github.com/PaddlePaddle/PaddleClas/blob/develop/docs/zh_CN/quick_start/quick_start_recognition.md) for the specific operation of the search.
To integrate the search into the overall `PP-ShiTu` process, please refer to `The Introduction of PP-ShiTu Image Recognition System` in [README](../../../README_en.md). Please check the [Quick Start for Image Recognition](../quick_start/quick_start_recognition_en.md) for the specific operation of the search.
The search part is configured as follows. Please refer to `deploy/configs/inference_*.yaml` for the complete version.
@@ -8,67 +8,83 @@ Generally speaking, Image Classification attempts to comprehend an entire image
Image Classification is a very basic but important field in the subject of computer vision. Its research results have always influenced the development of computer vision and even deep learning. Image classification has many sub-fields, such as multi-label image classification and fine-grained image classification. Here is only a brief description of single-label image classification.
See [here](https://github.com/PaddlePaddle/PaddleClas/blob/develop/docs/zh_CN/algorithm_introduction/image_classification.md) for the detailed introduction of image classification algorithms.
See [here](../algorithm_introduction/image_classification_en.md) for the detailed introduction of image classification algorithms.
-[3.1 Training and Evaluation on CPU or Single GPU](https://github.com/PaddlePaddle/PaddleClas/blob/develop/docs/zh_CN/models_training/classification.md#3.1)
-[3.1.1 Model Training](https://github.com/PaddlePaddle/PaddleClas/blob/develop/docs/zh_CN/models_training/classification.md#3.1.1)
-[3.1.2 Model Finetuning](https://github.com/PaddlePaddle/PaddleClas/blob/develop/docs/zh_CN/models_training/classification.md#3.1.2)
-[3.1.4 Model Evaluation](https://github.com/PaddlePaddle/PaddleClas/blob/develop/docs/zh_CN/models_training/classification.md#3.1.4)
-[3.2 Training and Evaluation on Linux+ Multi-GPU](https://github.com/PaddlePaddle/PaddleClas/blob/develop/docs/zh_CN/models_training/classification.md#3.2)
-[3.2.1 Model Training](https://github.com/PaddlePaddle/PaddleClas/blob/develop/docs/zh_CN/models_training/classification.md#3.2.1)
-[3.2.2 Model Finetuning](https://github.com/PaddlePaddle/PaddleClas/blob/develop/docs/zh_CN/models_training/classification.md#3.2.2)
-[3.2.4 Model Evaluation](https://github.com/PaddlePaddle/PaddleClas/blob/develop/docs/zh_CN/models_training/classification.md#3.2.4)
-[3.3 Use the Pre-trained Model to Predict](https://github.com/PaddlePaddle/PaddleClas/blob/develop/docs/zh_CN/models_training/classification.md#3.3)
-[3.4 Use the Inference Model to Predict](https://github.com/PaddlePaddle/PaddleClas/blob/develop/docs/zh_CN/models_training/classification.md#3.4)
-[1. Dataset Introduction](#1)
-[1.1 ImageNet-1k](#1.1)
-[1.2 CIFAR-10/CIFAR-100](#1.2)
-[2. Image Classification Process](#2)
-[2.1 Data and Its Preprocessing](#2.1)
-[2.2 Prepare the Model](#2.2)
-[2.3 Train the Model](#2.3)
-[2.4 Evaluate the Model](#2.4)
-[3. Application Methods](#3)
-[3.1 Training and Evaluation on CPU or Single GPU](#3.1)
-[3.1.1 Model Training](#3.1.1)
-[3.1.2 Model Finetuning](#3.1.2)
-[3.1.3 Resume Training](#3.1.3)
-[3.1.4 Model Evaluation](#3.1.4)
-[3.2 Training and Evaluation on Linux+ Multi-GPU](#3.2)
-[3.2.1 Model Training](#3.2.1)
-[3.2.2 Model Finetuning](#3.2.2)
-[3.2.3 Resume Training](#3.2.3)
-[3.2.4 Model Evaluation](#3.2.4)
-[3.3 Use the Pre-trained Model to Predict](#3.3)
-[3.4 Use the Inference Model to Predict](#3.4)
<aname="1"></a>
## 1. Dataset Introduction
<aname="1.1"></a>
### 1.1 ImageNet-1k
The ImageNet is a large-scale visual database for the research of visual object recognition. More than 14 million images have been annotated manually to point out objects in the picture in this project, and at least more than 1 million images provide bounding box. ImageNet-1k is a subset of the ImageNet dataset, which contains 1000 categories. The training set contains 1281167 image data, and the validation set contains 50,000 image data. Since 2010, the ImageNet project has held an image classification competition every year, which is the ImageNet Large-scale Visual Recognition Challenge (ILSVRC). The dataset used in the challenge is ImageNet-1k. So far, ImageNet-1k has become one of the most important data sets for the development of computer vision, and it promotes the development of the entire computer vision. The initialization models of many computer vision downstream tasks are based on the weights trained on this dataset.
<aname="1.2"></a>
### 1.2 CIFAR-10/CIFAR-100
The CIFAR-10 dataset consists of 60,000 color images in 10 categories, with an image resolution of 32x32, and each category has 6000 images, including 5000 in the training set and 1000 in the validation set. 10 different classes represent airplanes, cars, birds, cats, deer, dogs, frogs, horses, ships and trucks. The CIFAR-100 data set is an extension of CIFAR-10. It consists of 60,000 color images in 100 classes, with an image resolution of 32x32, and each class has 600 images, including 500 in the training set and 100 in the validation set. Researchers can try different algorithms quickly because these two data sets are small in scale. These two datasets are also commonly used data sets for testing the quality of models in the image classification field.
<aname="2"></a>
## 2. Image Classification Process
The prepared training data is preprocessed and then passed through the image classification model. The output of the model and the real label are used in a cross-entropy loss function. This loss function describes the convergence direction of the model. Then the corresponding gradient descent for the final loss function is calculated and returned to the model, which update the weight of the model by optimizers. Finally, an image classification model can be obtained.
<aname="2.1"></a>
### 2.1 Data Preprocessing
The quality and quantity of data often determine the performance of a model. In the field of image classification, data includes images and labels. In most cases, labeled data is scarce, so the amount of data is difficult to reach the level of saturation of the model. In order to enable the model to learn more image features, a lot of image transformation or data augmentation is required before the image enters the model, so as to ensure the diversity of input image data and ensure that the model has better generalization capabilities. PaddleClas provides standard image transformation for training ImageNet-1k, and also provides 8 data augmentation methods. For related codes, please refer to [data preprocess](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.2/ppcls/data/preprocess),The configuration file refer to [Data Augmentation Configuration File](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.2/ppcls/configs/ImageNet/DataAugment).
The quality and quantity of data often determine the performance of a model. In the field of image classification, data includes images and labels. In most cases, labeled data is scarce, so the amount of data is difficult to reach the level of saturation of the model. In order to enable the model to learn more image features, a lot of image transformation or data augmentation is required before the image enters the model, so as to ensure the diversity of input image data and ensure that the model has better generalization capabilities. PaddleClas provides standard image transformation for training ImageNet-1k, and also provides 8 data augmentation methods. For related codes, please refer to [data preprocess](../../../ppcls/data/preprocess),The configuration file refer to [Data Augmentation Configuration File](../../../ppcls/configs/ImageNet/DataAugment). For related algorithms, please refer to [data augment algorithms](../algorithm_introduction/DataAugmentation_en.md).
<aname="2.2"></a>
### 2.2 Prepare the Model
After the data is determined, the model often determines the upper limit of the final accuracy. In the field of image classification, classic models emerge in an endless stream. PaddleClas provides 35 series and a total of 164 ImageNet pre-trained models. For specific accuracy, speed and other indicators, please refer to [Backbone Network Introduction](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.2/docs/en/models).
After the data is determined, the model often determines the upper limit of the final accuracy. In the field of image classification, classic models emerge in an endless stream. PaddleClas provides 35 series and a total of 164 ImageNet pre-trained models. For specific accuracy, speed and other indicators, please refer to [Backbone Network Introduction](../algorithm_introduction/ImageNet_models_en.md).
<aname="2.3"></a>
### 2.3 Train
After preparing the data and model, you can start training the model and update the parameters of the model. After many iterations, a trained model can finally be obtained for image classification tasks. The training process of image classification requires a lot of experience and involves the setting of many hyperparameters. PaddleClas provides a series of [training tuning methods](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.2/docs/en/models/Tricks_en.md), which can quickly help you obtain a high-precision model.
After preparing the data and model, you can start training the model and update the parameters of the model. After many iterations, a trained model can finally be obtained for image classification tasks. The training process of image classification requires a lot of experience and involves the setting of many hyperparameters. PaddleClas provides a series of [training tuning methods](./train_strategy_en.md), which can quickly help you obtain a high-precision model.
<aname="2.4"></a>
### 2.4 Evaluation
After a model is trained, the evaluation results of the model on the validation set can determine the performance of the model. The evaluation index is generally Top1-Acc or Top5-Acc. The higher the index, the better the model performance.
<aname="3"></a>
## 3. Application Methods
Please refer to [Installation](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.2/docs/en/tutorials/install_en.md) to setup environment at first, and prepare flower102 dataset by following the instruction mentioned in the [Quick Start](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.2/docs/en/tutorials/quick_start_en.md).
Please refer to [Installation](../installation/install_paddleclas_en.md) to setup environment at first, and prepare flower102 dataset by following the instruction mentioned in the [Quick Start](../quick_start/quick_start_classification_new_user_en.md).
So far, PaddleClas supports the following training/evaluation environments:
...
...
@@ -81,9 +97,13 @@ So far, PaddleClas supports the following training/evaluation environments:
└── Linux
```
<aname="3.1"></a>
### 3.1 Training and Evaluation on CPU or Single GPU
If training and evaluation are performed on CPU or single GPU, it is recommended to use the `tools/train.py` and `tools/eval.py`. For training and evaluation in multi-GPU environment on Linux, please refer to [3.2 Training and evaluation on Linux+GPU](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.2/docs/en/tutorials/getting_started_en.md#2-training-and-evaluation-on-linuxgpu).
If training and evaluation are performed on CPU or single GPU, it is recommended to use the `tools/train.py` and `tools/eval.py`. For training and evaluation in multi-GPU environment on Linux, please refer to [3.2 Training and evaluation on Linux+GPU](#3.2).
<aname="3.1.1"></a>
#### 3.1.1 Model Training
...
...
@@ -98,7 +118,7 @@ python3 tools/train.py \
Among them, `-c` is used to specify the path of the configuration file, `-o` is used to specify the parameters needed to be modified or added, `-o Arch.pretrained=False` means to not using pre-trained models. `-o Global.device=gpu` means to use GPU for training. If you want to use the CPU for training, you need to set `Global.device` to `cpu`.
Of course, you can also directly modify the configuration file to update the configuration. For specific configuration parameters, please refer to [Configuration Document](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.2/docs/en/tutorials/config_description_en.md).
Of course, you can also directly modify the configuration file to update the configuration. For specific configuration parameters, please refer to [Configuration Document](config_description_en.md).
The output log examples are as follows:
...
...
@@ -124,6 +144,8 @@ The output log examples are as follows:
During training, you can view loss changes in real time through `VisualDL`, see [VisualDL](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.2/docs/en/extension/VisualDL_en.md) for details.
<aname="3.1.2"></a>
#### 3.1.2 Model Finetuning
After correcting config file, you can load pretrained model weight to finetune. The command is as follows:
...
...
@@ -137,7 +159,9 @@ python3 tools/train.py \
Among them,`Arch.pretrained` is used to set the address to load the pretrained weights. When using it, you need to replace it with your own pretrained weights' path, or you can modify the path directly in the configuration file. You can also set it into `True` to use pretrained weights that trained in ImageNet1k.
We also provide a lot of pre-trained models trained on the ImageNet-1k dataset. For the model list and download address, please refer to the [model library overview](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.2/docs/en/models/models_intro_en.md).
We also provide a lot of pre-trained models trained on the ImageNet-1k dataset. For the model list and download address, please refer to the [model library overview](../algorithm_introduction/ImageNet_models_en.md).
<aname="3.1.3"></a>
#### 3.1.3 Resume Training
...
...
@@ -170,6 +194,8 @@ The configuration file does not need to be modified. You only need to add the `G
.
```
<aname="3.1.4"></a>
#### 3.1.4 Model Evaluation
The model evaluation process can be started as follows.
...
...
@@ -187,14 +213,18 @@ Some of the configurable evaluation parameters are described as follows:
-`Arch.name`:Model name
-`Global.pretrained_model`:The path of the model file to be evaluated
**Note:** When loading the model to be evaluated, you only need to specify the path of the model file stead of the suffix. PaddleClas will automatically add the `.pdparams` suffix, such as [3.1.3 Resume Training](https://github.com/PaddlePaddle/PaddleClas/blob/ develop/docs/zh_CN/models_training/classification.md#3.1.3).
**Note:** When loading the model to be evaluated, you only need to specify the path of the model file stead of the suffix. PaddleClas will automatically add the `.pdparams` suffix, such as [3.1.3 Resume Training](#3.1.3).
When loading the model to be evaluated, you only need to specify the path of the model file stead of the suffix. PaddleClas will automatically add the `.pdparams` suffix, such as [3.1.3 Resume Training](https://github.com/PaddlePaddle/PaddleClas/blob/ develop/docs/zh_CN/models_training/classification.md#3.1.3).
<aname="3.2"></a>
### 3.2 Training and Evaluation on Linux+ Multi-GPU
If you want to run PaddleClas on Linux with GPU, it is highly recommended to use `paddle.distributed.launch` to start the model training script(`tools/train.py`) and evaluation script(`tools/eval.py`), which can start on multi-GPU environment more conveniently.
<aname="3.2.1"></a>
#### 3.2.1 Model Training
The training process can be started in the following way. `paddle.distributed.launch` specifies the GPU running card number by setting `gpus`:
The format of output log information is the same as above, see [3.1.1 Model training](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.2/docs/en/tutorials/getting_started_en.md#11-model-training) for details.
The format of output log information is the same as above, see [3.1.1 Model training](#3.1.1) for details.
Among them, `Arch.pretrained` is set to `True` or `False`. It also can be used to set the address to load the pretrained weights. When using it, you need to replace it with your own pretrained weights' path, or you can modify the path directly in the configuration file.
There contains a lot of examples of model finetuning in the [new user version](https://github.com/PaddlePaddle/PaddleClas/blob/develop/docs/zh_CN/quick_start/quick_start_classification_new_user.md) and [professional version](https://github.com/PaddlePaddle/PaddleClas/blob/develop/docs/zh_CN/quick_start/quick_start_classification_professional.md) of PaddleClas Trial in 30 mins. You can refer to this tutorial to finetune the model on a specific dataset.
There contains a lot of examples of model finetuning in the [new user version](../quick_start/quick_start_classification_new_user_en.md) and [professional version](../quick_start/quick_start_classification_professional_en.md) of PaddleClas Trial in 30 mins. You can refer to this tutorial to finetune the model on a specific dataset.
The configuration file does not need to be modified. You only need to add the `Global.checkpoints` parameter during training, which represents the path of the checkpoints. The parameter weights, learning rate, optimizer and other information will be loaded using this parameter as described in [3.1.3 Resume training](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.2/docs/en/tutorials/getting_started_en.md#13-resume-training).
The configuration file does not need to be modified. You only need to add the `Global.checkpoints` parameter during training, which represents the path of the checkpoints. The parameter weights, learning rate, optimizer and other information will be loaded using this parameter as described in [3.1.3 Resume training](#3.1.3).
About parameter description, see [3.1.4 Model evaluation](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.2/docs/en/tutorials/getting_started_en.md#14-model-evaluation) for details.
About parameter description, see [3.1.4 Model evaluation](#3.1.4) for details.
<aname="3.3"></a>
### 3.3 Use the Pre-trained Model to Predict
...
...
@@ -274,6 +312,8 @@ Parameters:
-`Infer.infer_imgs`:The path of the image file or folder to be predicted.
-`Global.pretrained_model`:Weight file path, such as`./output/MobileNetV3_large_x1_0/best_model`
<aname="3.4"></a>
### 3.4 Use the Inference Model to Predict
By exporting the inference model,PaddlePaddle supports inference using prediction engines, which will be introduced next. Firstly, you should export inference model using `tools/export_model.py`.
Among them, `Global.pretrained_model` parameter is used to specify the model file path that does not need to include the file suffix name.(such as [3.1.3 Resume Training](https://github.com/PaddlePaddle/PaddleClas/blob/develop/docs/zh_CN/models_training/classification.md#3.1.3))。
Among them, `Global.pretrained_model` parameter is used to specify the model file path that does not need to include the file suffix name.(such as [3.1.3 Resume Training](#3.1.3))。
The above command will generate the model structure file (`inference.pdmodel`) and the model weight file (`inference.pdiparams`), and then the inference engine can be used for inference:
To experience the whole image recognition system, or learn how to build a feature gallery, please refer to [Quick Start of Image Recognition](. /quick_start/quick_start_recognition.md), which explains the overall application process. The following parts expound on the training part of the above three steps.
To experience the whole image recognition system, or learn how to build a feature gallery, please refer to [Quick Start of Image Recognition](../quick_start/quick_start_recognition_en.md), which explains the overall application process. The following parts expound on the training part of the above three steps.
Please first refer to the [Installation Guide](https://github.com/PaddlePaddle/PaddleClas/blob/develop/docs/zh_CN/installation/install_paddleclas.md) to configure the runtime environment.
Please first refer to the [Installation Guide](../installation/install_paddleclas_en.md) to configure the runtime environment.
-[2. Feature Model Training](https://github.com/PaddlePaddle/PaddleClas/blob/develop/docs/zh_CN/models_training/recognition.md#2)
-[2.1. Data Preparation](https://github.com/PaddlePaddle/PaddleClas/blob/develop/docs/zh_CN/models_training/recognition.md#2.1)
-[2. 2 Single GPU-based Training and Evaluation](https://github.com/PaddlePaddle/PaddleClas/blob/develop/docs/zh_CN/models_training/recognition.md#2.2)
-[2.2.1 Model Training](https://github.com/PaddlePaddle/PaddleClas/blob/develop/docs/zh_CN/models_training/recognition.md#2.2.2)
-[2. 2 Single GPU-based Training and Evaluation](#2.2)
-[2.2.1 Model Training](#2.2.2)
-[2.2.2 Resume Training](#2.2.2)
-[2.2.3 Model Evaluation](#2.2.3)
-[2.3 Export Inference Model](#2.3)
-[3. Vector Search](#3)
-[4. Basic Knowledge](#4)
<aname="1"></a>
## 1. Mainbody Detection
...
...
@@ -45,11 +45,11 @@ For more information about the training method of mainbody detection, please ref
For more information on the introduction and download of the model provided in PaddleClas for body detection, please refer to: [PaddleDetection Tutorial](https://github.com/PaddlePaddle/PaddleClas/blob/develop/docs/zh_CN/image_recognition_pipeline/mainbody_detection.md).
<aname="2"></a>
## 2. Feature Model Training
<aname="2.1"></a>
### 2.1 Data Preparation
...
...
@@ -123,7 +123,7 @@ The format of testing set is the same as the one of training set.
**Note**:
- When the gallery dataset and query dataset are the same, in order to remove the first data retrieved (the retrieved images themselves do not need to be evaluated), each data needs to correspond to a unique id for subsequent evaluation of metrics such as mAP, recall@1, etc. Please refer to [Introduction to image retrieval datasets](https://github.com/PaddlePaddle/PaddleClas/blob/develop/docs/zh_CN/models_training/recognition.md#图像检索数据集介绍) for the analysis of gallery datasets and query datasets, and [Image retrieval evaluation metrics](https://github.com/PaddlePaddle/PaddleClas/blob/develop/docs/zh_CN/models_training/recognition.md#图像检索评价指标) for the evaluation of mAP, recall@1, etc.
- When the gallery dataset and query dataset are the same, in order to remove the first data retrieved (the retrieved images themselves do not need to be evaluated), each data needs to correspond to a unique id for subsequent evaluation of metrics such as mAP, recall@1, etc. Please refer to [Introduction to image retrieval datasets](#Introduction to Image Retrieval Datasets) for the analysis of gallery datasets and query datasets, and [Image retrieval evaluation metrics](#Image Retrieval Evaluation Metrics) for the evaluation of mAP, recall@1, etc.
Back to `PaddleClas` root directory.
...
...
@@ -132,13 +132,15 @@ Back to `PaddleClas` root directory.
cd ../../
```
<aname="2.2"></a>
### 2.2 Single GPU-based Training and Evaluation
For training and evaluation on a single GPU, the `tools/train.py` and `tools/eval.py` scripts are recommended.
#### 2.2.1 Model Training
Once you have prepared the configuration file, you can start training the image retrieval task in the following way. the method used by PaddleClas to train the image retrieval is metric learning, referring to [metric learning](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.2/docs/en/tutorials/getting_started_retrieval_en.md#Metric-Learning) for more explanations.
Once you have prepared the configuration file, you can start training the image retrieval task in the following way. the method used by PaddleClas to train the image retrieval is metric learning, referring to [metric learning](#metric learning) for more explanations.
`-c` is used to specify the path to the configuration file, and `-o` is used to specify the parameters that need to be modified or added, where `-o Arch.Backbone.pretrained=True` indicates that the Backbone part uses the pre-trained model. In addtion,`Arch.Backbone.pretrained` can also specify the address of a specific model weight file, which needs to be replaced with the path to your own pre-trained model weight file when using it. `-o Global.device=gpu` indicates that the GPU is used for training. If you want to use a CPU for training, you need to set `Global.device` to `cpu`.
For more detailed training configuration, you can also modify the corresponding configuration file of the model directly. Refer to the [configuration document](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.2/docs/en/tutorials/config_description_en.md) for specific configuration parameters.
For more detailed training configuration, you can also modify the corresponding configuration file of the model directly. Refer to the [configuration document](config_description_en.md) for specific configuration parameters.
Run the above commands to check the output log, an example is as follows:
...
...
@@ -172,7 +174,7 @@ Run the above commands to check the output log, an example is as follows:
The Backbone here is MobileNetV1, if you want to use other backbone, you can rewrite the parameter `Arch.Backbone.name`, for example by adding `-o Arch.Backbone.name={other Backbone}` to the command. In addition, as the input dimension of the `Neck` section differs between models, replacing a Backbone may require rewriting the input size here in a similar way to replacing the Backbone's name.
In the Training Loss section, [CELoss](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.2/ppcls/loss/celoss.py) and [TripletLossV2](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.2/ppcls/loss/triplet.py) are used here with the following configuration files:
In the Training Loss section, [CELoss](../../../ppcls/loss/celoss.py) and [TripletLossV2](../../../ppcls/loss/triplet.py) are used here with the following configuration files:
```
Loss:
...
...
@@ -184,7 +186,7 @@ Loss:
margin: 0.5
```
The final total Loss is a weighted sum of all Losses, where weight defines the weight of a particular Loss in the final total. If you want to replace other Losses, you can also change the Loss field in the configuration file, for the currently supported Losses please refer to [Loss](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.2/ppcls/loss).
The final total Loss is a weighted sum of all Losses, where weight defines the weight of a particular Loss in the final total. If you want to replace other Losses, you can also change the Loss field in the configuration file, for the currently supported Losses please refer to [Loss](../../../ppcls/loss).
#### 2.2.2 Resume Training
...
...
@@ -246,13 +248,15 @@ Some of the configurable evaluation parameters are introduced as follows.
-`Arch.name`:the name of the model
-`Global.pretrained_model`:path to the pre-trained model file of the model to be evaluated, unlike `Global.Backbone.pretrained`, the pre-trained model is the weight of the whole model instead of the Backbone only. When it is time to do model evaluation, the weights of the whole model need to be loaded.
-`Metric.Eval`:the metric to be evaluated, by default evaluates recall@1, recall@5, mAP. when you are not going to evaluate a metric, you can remove the corresponding trial marker from the configuration file; when you want to add a certain evaluation metric, you can also refer to [Metric](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.2/ppcls/metric/metrics.py) section to add the relevant metric to the configuration file `Metric.Eval`.
-`Metric.Eval`:the metric to be evaluated, by default evaluates recall@1, recall@5, mAP. when you are not going to evaluate a metric, you can remove the corresponding trial marker from the configuration file; when you want to add a certain evaluation metric, you can also refer to [Metric](../../../ppcls/metric/metrics.py) section to add the relevant metric to the configuration file `Metric.Eval`.
**Note:**
- When loading the model to be evaluated, the path to the model file needs to be specified, but it is not necessary to include the file suffix, PaddleClas will automatically complete the `.pdparams` suffix, e.g. [2.2.2 Resume Training](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.2/docs/en/tutorials/getting_started_retrieval_en.md#Resume-Training).
- When loading the model to be evaluated, the path to the model file needs to be specified, but it is not necessary to include the file suffix, PaddleClas will automatically complete the `.pdparams` suffix, e.g. [2.2.2 Resume Training](#2.2.2).
- Metric learning are generally not evaluated for TopkAcc.
<aname="2.3"></a>
### 2.3 Export Inference Model
By exporting the inference model, PaddlePaddle supports the transformation of the trained model using prediction with inference engine.
`Global.pretrained_model` is used to specify the model file path, which still does not need to contain the model file suffix (e.g.[2.2.2 Model Recovery Training](https://github.com/PaddlePaddle/PaddleClas/blob/develop/docs/zh_CN/models_training/recognition.md#2.2.2)). When executed, it will generate the `./inference` directory, which contains the `inference.pdiparams`,`inference.pdiparams.info`, and`inference.pdmodel` files.`Global.save_inference_dir` allows you to specify the path to export the inference model. The inference model saved here is truncated at the embedding feature level, i.e. the final output of the model is n-dimensional embedding features.
`Global.pretrained_model` is used to specify the model file path, which still does not need to contain the model file suffix (e.g.[2.2.2 Model Recovery Training](#2.2.2)). When executed, it will generate the `./inference` directory, which contains the `inference.pdiparams`,`inference.pdiparams.info`, and`inference.pdmodel` files.`Global.save_inference_dir` allows you to specify the path to export the inference model. The inference model saved here is truncated at the embedding feature level, i.e. the final output of the model is n-dimensional embedding features.
The above command will generate the model structure file (`inference.pdmodel`) and the model weights file (`inference.pdiparams`), which can then be used for inference using the inference engine. The process of inference using the inference model can be found in [Predictive inference based on the Python prediction engine](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.2/docs/en/tutorials/@shengyu).
The above command will generate the model structure file (`inference.pdmodel`) and the model weights file (`inference.pdiparams`), which can then be used for inference using the inference engine. The process of inference using the inference model can be found in [Predictive inference based on the Python prediction engine](../inference_deployment/python_deploy_en.md).
If the above cannot be properly referenced, please `uninstall` and then `install` again, especially when you are using`windows`.
<aname="4"></a>
## 4. Basic Knowledge
Image retrieval refers to a query image given a specific instance (e.g. a specific target, scene, item, etc.) that contains the same instance from a database image. Unlike image classification, image retrieval solves an open set problem where the training set may not contain the class of the image being recognised. The overall process of image retrieval is: firstly, the images are represented in a suitable feature vector, secondly, a nearest neighbour search is performed on these image feature vectors using Euclidean or Cosine distances to find similar images in the base, and finally, some post-processing techniques can be used to fine-tune the retrieval results and determine information such as the category of the image being recognised. Therefore, the key to determining the performance of an image retrieval algorithm lies in the goodness of the feature vectors corresponding to the images.
<aname="metric learning"></a>
- Metric Learning
Metric learning studies how to learn a distance function on a particular task so that the distance function can help nearest-neighbour based algorithms (kNN, k-means, etc.) to achieve better performance. Deep Metric Learning is a method of metric learning that aims to learn a mapping from the original features to a low-dimensional dense vector space (embedding space) such that similar objects on the embedding space are closer together using commonly used distance functions (Euclidean distance, cosine distance, etc.) ) on the embedding space, while the distances between objects of different classes are not close to each other. Deep metric learning has achieved very successful applications in the field of computer vision, such as face recognition, commodity recognition, image retrieval, pedestrian re-identification, etc. See [HERE](https://github.com/PaddlePaddle/PaddleClas/blob/develop/docs/zh_CN/algorithm_introduction/metric_learning.md) for detailed information.
Metric learning studies how to learn a distance function on a particular task so that the distance function can help nearest-neighbour based algorithms (kNN, k-means, etc.) to achieve better performance. Deep Metric Learning is a method of metric learning that aims to learn a mapping from the original features to a low-dimensional dense vector space (embedding space) such that similar objects on the embedding space are closer together using commonly used distance functions (Euclidean distance, cosine distance, etc.) ) on the embedding space, while the distances between objects of different classes are not close to each other. Deep metric learning has achieved very successful applications in the field of computer vision, such as face recognition, commodity recognition, image retrieval, pedestrian re-identification, etc. See [HERE](../algorithm_introduction/metric_learning_em.md) for detailed information.
<aname="Introduction to Image Retrieval Datasets"></a>
- Introduction to Image Retrieval Datasets
- Training Dataset: used to train the model so that it can learn the image features of the collection.
- Gallery Dataset: used to provide the gallery data for the image retrieval task. The gallery dataset can be the same as the training set or the test set, or different.
- Test Set (Query Dataset): used to test the goodness of the model, usually each test image in the test set is extracted with features, and then matched with the features of the underlying data to obtain recognition results, and then the metrics of the whole test set are calculated based on the recognition results.
<aname="Image Retrieval Evaluation Metrics"></a>
- Image Retrieval Evaluation Metrics
- recall: indicates the number of predicted positive cases with positive labels / the number of cases with positive labels