提交 c96af151 编写于 作者: littletomatodonkey's avatar littletomatodonkey

fix getting started en

上级 efd45a6d
......@@ -2,37 +2,105 @@
---
Please refer to [Installation](install.md) to setup environment at first, and prepare ImageNet1K data by following the instruction mentioned in the [data](data.md)
## Setup
## 1. Training and Evaluation on Windows or CPU
**Setup PYTHONPATH:**
If training and evaluation are performed on Windows system or CPU, it is recommended to use the `tools/train_multi_platform.py` and `tools/eval_multi_platform.py` scripts.
## 1.1 Model training
After preparing the configuration file, The training process can be started in the following way.
```
python tools/train_multi_platform.py \
-c configs/ResNet/ResNet50.yaml \
-o model_save_dir=./output/ \
-o use_gpu=True
```
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 model_save_dir=./output/` means to modify the `model_save_dir` in the configuration file to ` ./output/`. `-o use_gpu=True` means to use GPU for training. If you want to use the CPU for training, you need to set `use_gpu` to `False`.
Of course, you can also directly modify the configuration file to update the configuration. For specific configuration parameters, please refer to [Configuration Document](config.md).
* The output log examples are as follows:
* If mixup or cutmix is used in training, only loss, lr (learning rate) and training time of the minibatch will be printed in the log.
```
train step:890 loss: 6.8473 lr: 0.100000 elapse: 0.157s
```
* If mixup or cutmix is not used during training, in addition to loss, lr (learning rate) and the training time of the minibatch, top-1 and top-k( The default is 5) will also be printed in the log.
```
epoch:0 train step:13 loss:7.9561 top1:0.0156 top5:0.1094 lr:0.100000 elapse:0.193s
```
During training, you can view loss changes in real time through `VisualDL`. The command is as follows.
```bash
export PYTHONPATH=path_to_PaddleClas:$PYTHONPATH
visualdl --logdir ./scalar --host <host_IP> --port <port_num>
```
## Training and validating
### 1.2 Model finetuning
PaddleClas support `tools/train.py` and `tools/eval.py` to start training and validating.
* After configuring the configuration file, you can finetune it by loading the pretrained weights, The command is as shown below.
### Training
```
python tools/train_multi_platform.py \
-c configs/ResNet/ResNet50.yaml \
-o pretrained_model="./pretrained/ResNet50_pretrained"
```
Among them, `pretrained_model` 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.
### 1.3 Resume Training
* If the training process is terminated for some reasons, you can also load the checkpoints to continue training.
```
python tools/train_multi_platform.py \
-c configs/ResNet/ResNet50.yaml \
-o checkpoints="./output/ResNet/0/ppcls"
```
The configuration file does not need to be modified. You only need to add the `checkpoints` parameter during training, which represents the path of the checkpoints. The parameter weights, earning rate, optimizer and other information will be loaded using this parameter.
### 1.4 Model evaluation
* The model evaluation process can be started as follows.
```bash
# PaddleClas use paddle.distributed.launch to start multi-cards and multiprocess training.
# Set FLAGS_selected_gpus to indicate GPU cards
python tools/eval_multi_platform.py \
-c ./configs/eval.yaml \
-o ARCHITECTURE.name="ResNet50_vd" \
-o pretrained_model=path_to_pretrained_models
```
You can modify the `ARCHITECTURE.name` field and `pretrained_model` field in `configs/eval.yaml` to configure the evaluation model, and you also can update the configuration through the -o parameter.
**Note:** When loading the pretrained model, you need to specify the prefix of the pretrained model. For example, the pretrained model path is `output/ResNet50_vd/19`, and the pretrained model filename is `output/ResNet50_vd/19/ppcls.pdparams`, the parameter `pretrained_model` needs to be specified as `output/ResNet50_vd/19/ppcls`, PaddleClas will automatically fill in the `.pdparams` suffix.
### 2. Training and evaluation on Linux+GPU
If you want to run PaddleClas on Linux with GPU, it is highly recommended to use the model training and evaluation scripts provided by PaddleClas: `tools/train.py` and `tools/eval.py`.
### 2.1 Model training
After preparing the configuration file, The training process can be started in the following way.
```bash
# PaddleClas starts multi-card and multi-process training through launch
# Specify the GPU running card number by setting FLAGS_selected_gpus
python -m paddle.distributed.launch \
--selected_gpus="0,1,2,3" \
tools/train.py \
-c ./configs/ResNet/ResNet50_vd.yaml
```
- log:
```
epoch:0 train step:13 loss:7.9561 top1:0.0156 top5:0.1094 lr:0.100000 elapse:0.193
```
add -o params to update configuration
The configuration can be updated by adding the `-o` parameter.
```bash
python -m paddle.distributed.launch \
......@@ -40,48 +108,62 @@ python -m paddle.distributed.launch \
tools/train.py \
-c ./configs/ResNet/ResNet50_vd.yaml \
-o use_mix=1 \
--vdl_dir=./scalar/
--vdl_dir=./scalar/
```
- log:
The format of output log information is the same as above.
### 2.2 Model finetuning
* After configuring the configuration file, you can finetune it by loading the pretrained weights, The command is as shown below.
```
epoch:0 train step:522 loss:1.6330 lr:0.100000 elapse:0.210
python -m paddle.distributed.launch \
--selected_gpus="0,1,2,3" \
tools/train.py \
-c configs/ResNet/ResNet50.yaml \
-o pretrained_model="./pretrained/ResNet50_pretrained"
```
or modify configuration directly to config fileds, please refer to [config](config.md) for more details.
Among them, `pretrained_model` 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.
use visuldl to visulize training loss in the real time
* There contains a lot of examples of model finetuning in [The quick start tutorial](./quick_start_en.md). You can refer to this tutorial to finetune the model on a specific dataset.
```bash
visualdl --logdir ./scalar --host <host_IP> --port <port_num>
### 2.3 Resume Training
```
* If the training process is terminated for some reasons, you can also load the checkpoints to continue training.
```
python -m paddle.distributed.launch \
--selected_gpus="0,1,2,3" \
tools/train.py \
-c configs/ResNet/ResNet50.yaml \
-o checkpoints="./output/ResNet/0/ppcls"
```
### finetune
The configuration file does not need to be modified. You only need to add the `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.
* please refer to [Trial](./quick_start.md) for more details.
### 2.4 Model evaluation
### validation
* The model evaluation process can be started as follows.
```bash
python tools/eval.py \
python tools/eval_multi_platform.py \
-c ./configs/eval.yaml \
-o ARCHITECTURE.name="ResNet50_vd" \
-o pretrained_model=path_to_pretrained_models
```
modify `configs/eval.yaml filed: `ARCHITECTURE.name` and filed: `pretrained_model` to config valid model or add -o params to update config directly.
You can modify the `ARCHITECTURE.name` field and `pretrained_model` field in `configs/eval.yaml` to configure the evaluation model, and you also can update the configuration through the -o parameter.
**NOTE: ** when loading the pretrained model, should ignore the suffix ```.pdparams```
## 3. Model inference
## Predict
PaddlePaddle provides three ways to perform model inference. Next, how to use the inference engine to perforance model inference will be introduced.
PaddlePaddle supprot three predict interfaces
Use predicator interface to predict
First, export inference model
Firstly, you should export inference model using `tools/export_model.py`.
```bash
python tools/export_model.py \
......@@ -90,7 +172,8 @@ python tools/export_model.py \
--output_path=save_inference_dir
```
Second, start predicator enginee:
Secondly, Inference engine can be started using the following commands.
```bash
python tools/infer/predict.py \
......@@ -100,4 +183,4 @@ python tools/infer/predict.py \
--use_gpu=1 \
--use_tensorrt=True
```
please refer to [inference](../extension/paddle_inference.md) for more details.
please refer to [inference](../extension/paddle_inference_en.md) for more details.
......@@ -2,14 +2,13 @@
---
请事先参考[安装指南](install.md)配置运行环境,并根据[数据说明](./data.md)文档准备ImageNet1k数据,本章节下面所有的实验均以ImageNet1k数据集为例。
## 一、Windows或者CPU上训练
## 1. Windows或者CPU上训练与评估
如果在windows系统或者CPU上进行训练与评估,推荐使用`tools/train_multi_platform.py``tools/eval_multi_platform.py`脚本。
### 1.1 模型训练
配置好数据路径之后,可以使用下面的方式启动训练。
准备好配置文件之后,可以使用下面的方式启动训练。
```
python tools/train_multi_platform.py \
......@@ -40,7 +39,6 @@ python tools/train_multi_platform.py \
```bash
visualdl --logdir ./scalar --host <host_IP> --port <port_num>
```
### 1.2 模型微调
......@@ -57,7 +55,7 @@ python tools/train_multi_platform.py \
### 1.3 模型恢复训练
* 如果训练任务,因为其他原因被终止,也可以加载预训练模型继续训练。
* 如果训练任务因为其他原因被终止,也可以加载断点权重继续训练。
```
python tools/train_multi_platform.py \
......@@ -65,11 +63,13 @@ python tools/train_multi_platform.py \
-o checkpoints="./output/ResNet/0/ppcls"
```
其中配置文件不需要做任何修改,只需要在训练时添加`checkpoints`参数即可,表示加载的预训练模型路径,使用该参数会同时加载保存的模型参数权重和学习率、优化器等信息。
其中配置文件不需要做任何修改,只需要在训练时添加`checkpoints`参数即可,表示加载的断点权重路径,使用该参数会同时加载保存的断点权重和学习率、优化器等信息。
### 1.4 模型评估
* 可以通过以下命令完成模型评估。
```bash
python tools/eval_multi_platform.py \
-c ./configs/eval.yaml \
......@@ -77,12 +77,12 @@ python tools/eval_multi_platform.py \
-o pretrained_model=path_to_pretrained_models
```
可以更改configs/eval.yaml中的`ARCHITECTURE.name`字段和pretrained_model字段来配置评估模型,也可以通过-o参数更新配置。
可以更改`configs/eval.yaml`中的`ARCHITECTURE.name`字段和`pretrained_model`字段来配置评估模型,也可以通过-o参数更新配置。
**注意:** 加载预训练模型时,需要指定预训练模型的前缀,例如预训练模型参数所在的文件夹为`output/ResNet50_vd/19`,预训练模型参数的名称为`output/ResNet50_vd/19/ppcls.pdparams`,则`pretrained_model`参数需要指定为`output/ResNet50_vd/19/ppcls`,PaddleClas会自动补齐`.pdparams`的后缀。
## 二、基于Linux+GPU的模型训练与评估
## 2. 基于Linux+GPU的模型训练与评估
如果机器环境为Linux+GPU,那么推荐使用PaddleClas 提供的模型训练与评估脚本:`tools/train.py``tools/eval.py`,可以更快地完成训练与评估任务。
......@@ -108,10 +108,10 @@ python -m paddle.distributed.launch \
tools/train.py \
-c ./configs/ResNet/ResNet50_vd.yaml \
-o use_mix=1 \
--vdl_dir=./scalar/
--vdl_dir=./scalar/
```
输出日志信息同上。
输出日志信息的格式同上。
### 2.2 模型微调
......@@ -132,7 +132,7 @@ python -m paddle.distributed.launch \
### 2.3 模型恢复训练
* 如果训练任务,因为其他原因被终止,也可以加载预训练模型继续训练。
* 如果训练任务,因为其他原因被终止,也可以加载断点权重继续训练。
```
python -m paddle.distributed.launch \
......@@ -142,7 +142,7 @@ python -m paddle.distributed.launch \
-o checkpoints="./output/ResNet/0/ppcls"
```
其中配置文件不需要做任何修改,只需要在训练时添加`checkpoints`参数即可,表示加载的预训练模型路径,使用该参数会同时加载保存的模型参数权重和学习率、优化器等信息。
其中配置文件不需要做任何修改,只需要在训练时添加`checkpoints`参数即可,表示加载的断点权重路径,使用该参数会同时加载保存的模型参数权重和学习率、优化器等信息。
### 2.4 模型评估
......@@ -160,8 +160,6 @@ python -m paddle.distributed.launch \
可以更改configs/eval.yaml中的`ARCHITECTURE.name`字段和pretrained_model字段来配置评估模型,也可以通过-o参数更新配置。
**注意:** 加载预训练模型时,需要指定预训练模型的前缀,例如预训练模型参数所在的文件夹为`output/ResNet50_vd/19`,预训练模型参数的名称为`output/ResNet50_vd/19/ppcls.pdparams`,则`pretrained_model`参数需要指定为`output/ResNet50_vd/19/ppcls`,PaddleClas会自动补齐`.pdparams`的后缀。
## 三、模型推理
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册