未验证 提交 907cef57 编写于 作者: T Tingquan Gao 提交者: GitHub

Fix some bugs (#357)

fix getting started doc
上级 5704a255
......@@ -95,15 +95,20 @@ The model evaluation process can be started as follows.
```bash
python tools/eval.py \
-c ./configs/eval.yaml \
-o ARCHITECTURE.name="MobileNetV3_large_x1_0" \
-o pretrained_model=path_to_pretrained_models
-c ./configs/quick_start/MobileNetV3_large_x1_0_finetune.yaml \
-o pretrained_model="./output/MobileNetV3_large_x1_0/best_model/ppcls"\
-o load_static_weights=False
```
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.
The above command will use `./configs/quick_start/MobileNetV3_large_x1_0_finetune.yaml` as the configuration file to evaluate the model `./output/MobileNetV3_large_x1_0/best_model/ppcls`. You can also set the evaluation by changing the parameters in the configuration file, or you can update the configuration with the `-o` parameter, as shown above.
Some of the configurable evaluation parameters are described as follows:
* `ARCHITECTURE.name`: Model name
* `pretrained_model`: The path of the model file to be evaluated
* `load_static_weights`: Whether the model to be evaluated is a static graph model
**Note:** When loading the pre-trained model, you need to specify the prefix of the pretrained model, such as [1.3 Resume Training](#13-resume-training).
**Note:** If the model is a dygraph type, you only need to specify the prefix of the model file when loading the model, instead of specifying the suffix, such as [1.3 Resume Training](#13-resume-training).
<a name="2"></a>
### 2. Training and evaluation on Linux+GPU
......@@ -120,7 +125,7 @@ export CUDA_VISIBLE_DEVICES=0,1,2,3
python -m paddle.distributed.launch \
--selected_gpus="0,1,2,3" \
tools/train.py \
-c ./configs/quick_start/MobileNetV3_large_x1_0_finetune.yaml \
-c ./configs/quick_start/MobileNetV3_large_x1_0_finetune.yaml
```
The configuration can be updated by adding the `-o` parameter.
......@@ -146,8 +151,8 @@ export CUDA_VISIBLE_DEVICES=0,1,2,3
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"
-c ./configs/quick_start/MobileNetV3_large_x1_0_finetune.yaml \
-o pretrained_model="./pretrained/MobileNetV3_large_x1_0_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.
......@@ -166,7 +171,7 @@ python -m paddle.distributed.launch \
--selected_gpus="0,1,2,3" \
tools/train.py \
-c ./configs/quick_start/MobileNetV3_large_x1_0_finetune.yaml \
-o checkpoints="./output/ResNet/0/ppcls"
-o checkpoints="./output/MobileNetV3_large_x1_0/5/ppcls" \
-o last_epoch=5 \
-o use_gpu=True
```
......@@ -179,12 +184,12 @@ The model evaluation process can be started as follows.
```bash
python tools/eval.py \
-c ./configs/eval.yaml \
-o ARCHITECTURE.name="MobileNetV3_large_x1_0" \
-o pretrained_model=path_to_pretrained_models
-c ./configs/quick_start/MobileNetV3_large_x1_0_finetune.yaml \
-o pretrained_model="./output/MobileNetV3_large_x1_0/best_model/ppcls"\
-o load_static_weights=False
```
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.
About parameter description, see [1.4 Model evaluation](#14-model-evaluation) for details.
<a name="model_infer"></a>
## 3. Use the pre-trained model to predict
......@@ -192,9 +197,9 @@ After the training is completed, you can predict by using the pre-trained model
```python
python tools/infer/infer.py \
--i image path \
--m model name \
--p path to persistence model \
-i image path \
-m MobileNetV3_large_x1_0 \
--pretrained_model "./output/MobileNetV3_large_x1_0/best_model/ppcls" \
--use_gpu True \
--load_static_weights False
```
......@@ -202,7 +207,7 @@ python tools/infer/infer.py \
Among them:
+ `image_file`(i): The path of the image file to be predicted, such as `./test.jpeg`;
+ `model`(m): Model name, such as `MobileNetV3_large_x1_0`;
+ `pretrained_model`(p): Weight file path, such as `./pretrained/MobileNetV3_large_x1_0_pretrained/`;
+ `pretrained_model`: Weight file path, such as `./pretrained/MobileNetV3_large_x1_0_pretrained/`;
+ `use_gpu`: Whether to use the GPU, default by `True`;
+ `load_static_weights`: Whether to load the pre-trained model obtained from static image training, default by `False`;
+ `pre_label_image`: Whether to pre-label the image data, default value: `False`;
......@@ -219,17 +224,11 @@ Firstly, you should export inference model using `tools/export_model.py`.
```bash
python tools/export_model.py \
--model=MobileNetV3_large_x1_0 \
--pretrained_model=./output/MobileNetV3_large_x1_0/best_model/ppcls \
--output_path=./inference/cls_infer
```python
50 # Please modify the 'shape' according to actual needs
51 @to_static(input_spec=[
52 paddle.static.InputSpec(
53 shape=[None, 3, 224, 224], dtype='float32')
54 ])
--model MobileNetV3_large_x1_0 \
--pretrained_model ./output/MobileNetV3_large_x1_0/best_model/ppcls \
--output_path ./inference/cls_infer
```
Among them, the `--model` parameter is used to specify the model name, `--pretrained_model` parameter is used to specify the model file path, the path does not need to include the model file suffix name, and `--output_path` is used to specify the storage path of the converted model.
**Note**:
......@@ -248,14 +247,14 @@ The above command will generate the model structure file (`cls_infer.pdmodel`) a
```bash
python tools/infer/predict.py \
-i image path \
-m path of __model__ \
-p path of __variables__ \
--use_gpu=1 \
--use_tensorrt=True
--image_file image path \
-m "./inference/cls_infer.pdmodel" \
-p "./inference/cls_infer.pdiparams" \
--use_gpu=True \
--use_tensorrt=False
```
Among them:
+ `image_file`(i): The path of the image file to be predicted, such as `./test.jpeg`;
+ `image_file`: The path of the image file to be predicted, such as `./test.jpeg`;
+ `model_file`(m): Model file path, such as `./MobileNetV3_large_x1_0/cls_infer.pdmodel`;
+ `params_file`(p): Weight file path, such as `./MobileNetV3_large_x1_0/cls_infer.pdiparams`;
+ `use_tensorrt`: Whether to use the TesorRT, default by `True`;
......
......@@ -103,14 +103,19 @@ python tools/train.py \
```bash
python tools/eval.py \
-c ./configs/eval.yaml \
-o ARCHITECTURE.name="MobileNetV3_large_x1_0" \
-o pretrained_model=path_to_pretrained_models
-c ./configs/quick_start/MobileNetV3_large_x1_0_finetune.yaml \
-o pretrained_model="./output/MobileNetV3_large_x1_0/best_model/ppcls"\
-o load_static_weights=False
```
可以通过更改`configs/eval.yaml`中的`ARCHITECTURE.name`参数和`pretrained_model`参数来配置评估模型,也可以通过`-o`参数更新配置,如上所示。
上述命令将使用`./configs/quick_start/MobileNetV3_large_x1_0_finetune.yaml`作为配置文件,对上述训练得到的模型`./output/MobileNetV3_large_x1_0/best_model/ppcls`进行评估。你也可以通过更改配置文件中的参数来设置评估,也可以通过`-o`参数更新配置,如上所示。
**注意:** 加载预训练模型时,需要指定预训练模型文件的路径,但无需包含文件后缀名,PaddleClas会自动补齐`.pdparams`的后缀,如[1.3 模型恢复训练](#1.3)
可配置的部分评估参数说明如下:
* `ARCHITECTURE.name`:模型名称
* `pretrained_model`:待评估的模型文件路径
* `load_static_weights`:待评估模型是否为静态图模型
**注意:** 如果模型为动态图模型,则在加载待评估模型时,需要指定模型文件的路径,但无需包含文件后缀名,PaddleClas会自动补齐`.pdparams`的后缀,如[1.3 模型恢复训练](#1.3)
<a name="2"></a>
## 2. 基于Linux+GPU的模型训练与评估
......@@ -157,7 +162,7 @@ python -m paddle.distributed.launch \
--selected_gpus="0,1,2,3" \
tools/train.py \
-c ./configs/quick_start/MobileNetV3_large_x1_0_finetune.yaml \
-o pretrained_model="./pretrained_model/ \ MobileNetV3_large_x1_0_pretrained"
-o pretrained_model="./pretrained/MobileNetV3_large_x1_0_pretrained"
```
其中`pretrained_model`用于设置加载预训练权重文件的路径,使用时需要换成自己的预训练模型权重文件路径,也可以直接在配置文件中修改该路径。
......@@ -177,7 +182,7 @@ python -m paddle.distributed.launch \
--selected_gpus="0,1,2,3" \
tools/train.py \
-c ./configs/quick_start/MobileNetV3_large_x1_0_finetune.yaml \
-o checkpoints="./output/ResNet/0/ppcls"
-o checkpoints="./output/MobileNetV3_large_x1_0/5/ppcls" \
-o last_epoch=5 \
-o use_gpu=True
```
......@@ -190,12 +195,10 @@ python -m paddle.distributed.launch \
可以通过以下命令进行模型评估。
```bash
python -m paddle.distributed.launch \
--selected_gpus="0" \
tools/eval.py \
-c ./configs/eval.yaml \
-o ARCHITECTURE.name="MobileNetV3_large_x1_0" \
-o pretrained_model=path_to_pretrained_models
python tools/eval.py \
-c ./configs/quick_start/MobileNetV3_large_x1_0_finetune.yaml \
-o pretrained_model="./output/MobileNetV3_large_x1_0/best_model/ppcls"\
-o load_static_weights=False
```
参数说明详见[1.4 模型评估](#1.4)
......@@ -208,19 +211,19 @@ python -m paddle.distributed.launch \
```python
python tools/infer/infer.py \
--i=待预测的图片文件路径 \
--m=模型名称 \
--p=persistable 模型路径 \
--use_gpu=True \
--load_static_weights=False
-i 待预测的图片文件路径 \
-m MobileNetV3_large_x1_0 \
--pretrained_model "./output/MobileNetV3_large_x1_0/best_model/ppcls" \
--use_gpu True \
--load_static_weights False
```
参数说明:
+ `image_file`(简写 i):待预测的图片文件路径或者批量预测时的图片文件夹,如 `./test.jpeg`
+ `model`(简写 m):模型名称,如 `ResNet50_vd`
+ `pretrained_model`(简写 p):权重文件路径,如 `./pretrained/ResNet50_vd_pretrained/`
+ `model`(简写 m):模型名称,如 `MobileNetV3_large_x1_0`
+ `pretrained_model`:模型权重文件路径,如 `./output/MobileNetV3_large_x1_0/best_model/ppcls`
+ `use_gpu` : 是否开启GPU训练,默认值:`True`
+ `load_static_weights` : 是否加载静态图训练得到的预训练模型,默认值:`False`
+ `load_static_weights` : 模型权重文件是否为静态图训练得到的,默认值:`False`
+ `pre_label_image` : 是否对图像数据进行预标注,默认值:`False`
+ `pre_label_out_idr` : 预标注图像数据的输出文件夹,当`pre_label_image=True`时,会在该文件夹下面生成很多个子文件夹,每个文件夹名称为类别id,其中存储模型预测属于该类别的所有图像。
......@@ -233,9 +236,9 @@ python tools/infer/infer.py \
```bash
python tools/export_model.py \
--model=MobileNetV3_large_x1_0 \
--pretrained_model=./output/MobileNetV3_large_x1_0/best_model/ppcls \
--output_path=./inference/cls_infer
--model MobileNetV3_large_x1_0 \
--pretrained_model ./output/MobileNetV3_large_x1_0/best_model/ppcls \
--output_path ./inference/cls_infer
```
其中,参数`--model`用于指定模型名称,`--pretrained_model`用于指定模型文件路径,该路径仍无需包含模型文件后缀名(如[1.3 模型恢复训练](#1.3)),`--output_path`用于指定转换后模型的存储路径。
......@@ -250,22 +253,21 @@ python tools/export_model.py \
53 shape=[None, 3, 224, 224], dtype='float32')
54 ])
```
2.
上述命令将生成模型结构文件(`cls_infer.pdmodel`)和模型权重文件(`cls_infer.pdiparams`),然后可以使用预测引擎进行推理:
```bash
python tools/infer/predict.py \
-i 图片路径 \
-m __model__文件路径 \
-p __variables__文件路径 \
--image_file 图片路径 \
-m "./inference/cls_infer.pdmodel" \
-p "./inference/cls_infer.pdiparams" \
--use_gpu=True \
--use_tensorrt=False
```
其中:
+ `image_file`(简写 i):待预测的图片文件路径,如 `./test.jpeg`
+ `model_file`(简写 m):模型文件路径,如 `./MobileNetV3_large_x1_0/cls_infer.pdmodel`
+ `params_file`(简写 p):权重文件路径,如 `./MobileNetV3_large_x1_0/cls_infer.pdiparams`
+ `image_file`:待预测的图片文件路径,如 `./test.jpeg`
+ `model_file`(简写 m):模型结构文件路径,如 `./inference/cls_infer.pdmodel`
+ `params_file`(简写 p):模型权重文件路径,如 `./inference/cls_infer.pdiparams`
+ `use_tensorrt`:是否使用 TesorRT 预测引擎,默认值:`True`
+ `use_gpu`:是否使用 GPU 预测,默认值:`True`
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册