2020-06-05 12:10:25 +00:00
# Getting Started
2020-06-05 08:55:47 +00:00
---
2020-06-05 12:10:25 +00:00
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 )
2020-06-05 08:55:47 +00:00
2020-06-05 12:10:25 +00:00
## Setup
2020-06-05 08:55:47 +00:00
2020-06-05 12:10:25 +00:00
**Setup PYTHONPATH: **
2020-06-05 08:55:47 +00:00
```bash
export PYTHONPATH=path_to_PaddleClas:$PYTHONPATH
```
2020-06-05 12:10:25 +00:00
## Training and validating
2020-06-05 08:55:47 +00:00
2020-06-05 12:10:25 +00:00
PaddleClas support `tools/train.py` and `tools/eval.py` to start training and validating.
2020-06-05 08:55:47 +00:00
2020-06-05 12:10:25 +00:00
### Training
2020-06-05 08:55:47 +00:00
```bash
2020-06-05 12:10:25 +00:00
# PaddleClas use paddle.distributed.launch to start multi-cards and multiprocess training.
# Set FLAGS_selected_gpus to indicate GPU cards
2020-06-05 08:55:47 +00:00
python -m paddle.distributed.launch \
--selected_gpus="0,1,2,3" \
tools/train.py \
-c ./configs/ResNet/ResNet50_vd.yaml
```
2020-06-05 12:10:25 +00:00
- log:
2020-06-05 08:55:47 +00:00
```
epoch:0 train step:13 loss:7.9561 top1:0.0156 top5:0.1094 lr:0.100000 elapse:0.193
```
2020-06-05 12:10:25 +00:00
add -o params to update configuration
2020-06-05 08:55:47 +00:00
```bash
python -m paddle.distributed.launch \
--selected_gpus="0,1,2,3" \
tools/train.py \
-c ./configs/ResNet/ResNet50_vd.yaml \
-o use_mix=1 \
2020-06-05 12:10:25 +00:00
--vdl_dir=./scalar/
2020-06-05 08:55:47 +00:00
```
2020-06-05 12:10:25 +00:00
- log:
2020-06-05 08:55:47 +00:00
```
epoch:0 train step:522 loss:1.6330 lr:0.100000 elapse:0.210
```
2020-06-05 12:10:25 +00:00
or modify configuration directly to config fileds, please refer to [config ](config.md ) for more details.
2020-06-05 08:55:47 +00:00
2020-06-05 12:10:25 +00:00
use visuldl to visulize training loss in the real time
2020-06-05 08:55:47 +00:00
```bash
visualdl --logdir ./scalar --host < host_IP > --port < port_num >
```
2020-06-05 12:10:25 +00:00
### finetune
2020-06-05 08:55:47 +00:00
2020-06-05 12:10:25 +00:00
* please refer to [Trial ](./quick_start.md ) for more details.
2020-06-05 08:55:47 +00:00
2020-06-18 11:45:11 +00:00
### validation
2020-06-05 08:55:47 +00:00
```bash
python tools/eval.py \
-c ./configs/eval.yaml \
-o ARCHITECTURE.name="ResNet50_vd" \
-o pretrained_model=path_to_pretrained_models
2020-06-05 12:10:25 +00:00
modify `configs/eval.yaml filed: ` ARCHITECTURE.name` and filed: ` pretrained_model` to config valid model or add -o params to update config directly.
2020-06-05 08:55:47 +00:00
2020-06-05 12:10:25 +00:00
**NOTE: ** when loading the pretrained model, should ignore the suffix ```.pdparams` ``
2020-06-05 08:55:47 +00:00
2020-06-05 12:10:25 +00:00
## Predict
PaddlePaddle supprot three predict interfaces
Use predicator interface to predict
First, export inference model
2020-06-05 08:55:47 +00:00
```bash
python tools/export_model.py \
2020-06-05 12:10:25 +00:00
--model=model_name \
--pretrained_model=pretrained_model_dir \
--output_path=save_inference_dir
2020-06-05 08:55:47 +00:00
```
2020-06-05 12:10:25 +00:00
Second, start predicator enginee:
2020-06-05 08:55:47 +00:00
```bash
python tools/infer/predict.py \
2020-06-05 12:10:25 +00:00
-m model_path \
-p params_path \
-i image path \
2020-06-05 08:55:47 +00:00
--use_gpu=1 \
--use_tensorrt=True
```
2020-06-05 12:10:25 +00:00
please refer to [inference ](../extension/paddle_inference.md ) for more details.