Skip to content

Commit 1f4bb05

Browse files
authored
Merge pull request #160 from HaoyangLee/main
update config explanation in crnn doc
2 parents 3d6b3af + 19cbc63 commit 1f4bb05

File tree

2 files changed

+139
-6
lines changed

2 files changed

+139
-6
lines changed

configs/rec/crnn/README.md

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ According to our experiments, the evaluation results on public benchmark dataset
5050
- To reproduce the result on other contexts, please ensure the global batch size is the same.
5151
- Both VGG and ResNet models are trained from scratch without any pre-training.
5252
- The above models are trained with MJSynth (MJ) and SynthText (ST) datasets. For more data details, please refer to [Data Preparation](#dataset-preparation)
53-
- Evaluations are tested individually on each benchmark dataset, and Avg Accuracy is the average of accuracies across all sub-datasets.
53+
- **Evaluations are tested individually on each benchmark dataset, and Avg Accuracy is the average of accuracies across all sub-datasets.**
5454
- For the PaddleOCR version of CRNN, the performance is reported on the trained model provided on their [github](https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.6/doc/doc_en/algorithm_rec_crnn_en.md).
5555

5656

@@ -66,7 +66,75 @@ Please download lmdb dataset for traininig and evaluation from [here](https://w
6666
- `validation.zip` is the union dataset for Validation
6767
- `evaluation.zip` contains several benchmarking datasets.
6868

69-
### Training
69+
Unzip the data and after preparation, the data structure should be like
70+
71+
``` text
72+
.
73+
├── train
74+
│   ├── MJ
75+
│   │   ├── data.mdb
76+
│   │   ├── lock.mdb
77+
│   ├── ST
78+
│   │   ├── data.mdb
79+
│   │   ├── lock.mdb
80+
└── validation
81+
|   ├── data.mdb
82+
|   ├── lock.mdb
83+
└── evaluation
84+
├── IC03
85+
│   ├── data.mdb
86+
│   ├── lock.mdb
87+
├── IC13
88+
│   ├── data.mdb
89+
│   ├── lock.mdb
90+
└── ...
91+
```
92+
93+
#### Check YAML Config Files
94+
Please check the following important args: `system.distribute`, `system.val_while_train`, `common.batch_size`, `train.dataset.dataset_root`, `train.dataset.data_dir`, `train.dataset.label_file`,
95+
`eval.dataset.dataset_root`, `eval.dataset.data_dir`, `eval.dataset.label_file`, `eval.loader.batch_size`. Explanations of these important args:
96+
97+
```yaml
98+
system:
99+
distribute: True # `True` for distributed training, `False` for standalone training
100+
amp_level: 'O3'
101+
seed: 42
102+
val_while_train: True # Validate while training
103+
drop_overflow_update: False
104+
common:
105+
...
106+
batch_size: &batch_size 64 # Batch size for training
107+
...
108+
train:
109+
ckpt_save_dir: './tmp_det'
110+
dataset_sink_mode: True
111+
dataset:
112+
type: DetDataset
113+
dataset_root: /data/ocr_datasets # Root dir of training dataset
114+
data_dir: ic15/text_localization/train # Dir of training dataset, concatenated with `dataset_root` to be the complete dir of training dataset
115+
label_file: ic15/text_localization/train/train_icdar15_label.txt # Path of training label file, concatenated with `dataset_root` to be the complete path of training label file
116+
...
117+
eval:
118+
dataset_sink_mode: False
119+
dataset:
120+
type: DetDataset
121+
dataset_root: /data/ocr_datasets # Root dir of validation/evaluation dataset
122+
data_dir: ic15/text_localization/test # Dir of validation/evaluation dataset, concatenated with `dataset_root` to be the complete dir of validation/evaluation dataset
123+
label_file: ic15/text_localization/test/test_icdar2015_label.txt # Path of validation/evaluation label file, concatenated with `dataset_root` to be the complete path of validation/evaluation label file
124+
...
125+
loader:
126+
shuffle: False
127+
batch_size: 64 # Batch size for validation/evaluation
128+
...
129+
```
130+
131+
**Notes:**
132+
- As the global batch size (batch_size x num_devices) is important for reproducing the result, please adjust `batch_size` accordingly to keep the global batch size unchanged for a different number of GPUs/NPUs, or adjust the learning rate linearly to a new global batch size.
133+
- When performing **Model Training**, if `system.val_while_train` is `True`, validation is performed while training. In this case, you should set `eval.dataset.dataset_root` as root dir of **validation** dataset, and set `eval.dataset.data_dir` as dir of **validation** dataset (e.g., `validation/`).
134+
- When performing **Model Evaluation**, you should set `eval.dataset.dataset_root` as root dir of **evaluation** dataset, and set `eval.dataset.data_dir` as dir of **evaluation** dataset (e.g., `evaluation/DATASET_NAME/`).
135+
136+
137+
### Model Training
70138
<!--- Guideline: Avoid using shell script in the command line. Python script preferred. -->
71139

72140
* Distributed Training
@@ -90,9 +158,8 @@ If you want to train or finetune the model on a smaller dataset without distribu
90158
python tools/train.py --config configs/rec/crnn/crnn_resnet34.yaml
91159
```
92160

93-
**Note:** As the global batch size (batch_size x num_devices) is important for reproducing the result, please adjust `batch_size` accordingly to keep the global batch size unchanged for a different number of GPUs/NPUs, or adjust the learning rate linearly to a new global batch size.
94161

95-
### Evaluation
162+
### Model Evaluation
96163

97164
To evaluate the accuracy of the trained model, you can use `eval.py`. Please set the checkpoint path to the arg `ckpt_load_path` in the `eval` section of yaml config file and then run:
98165

configs/rec/crnn/README_CN.md

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Table Format:
4949
- 环境配置:训练的环境配置表示为 {处理器}x{处理器数量}-{MS模式},其中 Mindspore 模式可以是 G-graph 模式或 F-pynative 模式。例如,D910x8-MS1.8-G 用于使用图形模式在8张昇腾910 NPU上依赖Mindspore1.8版本进行训练。
5050
- VGG 和 ResNet 模型都是从头开始训练的,无需任何预训练。
5151
- 上述模型是用 MJSynth(MJ)和 SynthText(ST)数据集训练的。更多数据详情,请参考 [数据集准备](#数据集准备)
52-
- 评估在每个基准数据集上单独测试,平均准确度是所有子数据集的精度平均值。
52+
- **评估在每个基准数据集上单独测试,平均准确度是所有子数据集的精度平均值。**
5353
- PaddleOCR版CRNN,我们直接用的是其[github](https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.6/doc/doc_en/algorithm_rec_crnn_en.md)上面提供的已训练好的模型。
5454

5555

@@ -65,6 +65,73 @@ LMDB格式的训练及验证数据集可以从[这里](https://www.dropbox.com/s
6565
- `validation.zip` 是一个整合的验证集。
6666
- `evaluation.zip` 包含多个基准评估数据集。
6767

68+
解压文件并完成数据准备操作后,数据文件夹结构如下:
69+
70+
``` text
71+
.
72+
├── train
73+
│   ├── MJ
74+
│   │   ├── data.mdb
75+
│   │   ├── lock.mdb
76+
│   ├── ST
77+
│   │   ├── data.mdb
78+
│   │   ├── lock.mdb
79+
└── validation
80+
|   ├── data.mdb
81+
|   ├── lock.mdb
82+
└── evaluation
83+
├── IC03
84+
│   ├── data.mdb
85+
│   ├── lock.mdb
86+
├── IC13
87+
│   ├── data.mdb
88+
│   ├── lock.mdb
89+
└── ...
90+
```
91+
92+
#### 检查配置文件
93+
请重点关注以下变量的配置:`system.distribute`, `system.val_while_train`, `common.batch_size`, `train.dataset.dataset_root`, `train.dataset.data_dir`, `train.dataset.label_file`,
94+
`eval.dataset.dataset_root`, `eval.dataset.data_dir`, `eval.dataset.label_file`, `eval.loader.batch_size`。说明如下:
95+
96+
```yaml
97+
system:
98+
distribute: True # 分布式训练为True,单卡训练为False
99+
amp_level: 'O3'
100+
seed: 42
101+
val_while_train: True # 边训练边验证
102+
drop_overflow_update: False
103+
common:
104+
...
105+
batch_size: &batch_size 64 # 训练批大小
106+
...
107+
train:
108+
ckpt_save_dir: './tmp_det'
109+
dataset_sink_mode: True
110+
dataset:
111+
type: DetDataset
112+
dataset_root: /data/ocr_datasets # 训练数据集根目录
113+
data_dir: ic15/text_localization/train # 训练数据集目录,将与`dataset_root`拼接形成完整训练数据集目录
114+
label_file: ic15/text_localization/train/train_icdar15_label.txt # 训练数据的标签文件路径,将与`dataset_root`拼接形成完整的训练数据的标签文件路径
115+
...
116+
eval:
117+
dataset_sink_mode: False
118+
dataset:
119+
type: DetDataset
120+
dataset_root: /data/ocr_datasets # 验证或评估数据集根目录
121+
data_dir: ic15/text_localization/test # 验证或评估数据集目录,将与`dataset_root`拼接形成完整验证或评估数据集目录
122+
label_file: ic15/text_localization/test/test_icdar2015_label.txt # 验证或评估数据的标签文件路径,将与`dataset_root`拼接形成完整的验证或评估数据的标签文件路径
123+
...
124+
loader:
125+
shuffle: False
126+
batch_size: 64 # 验证或评估批大小
127+
...
128+
```
129+
130+
**注意:**
131+
- 由于全局批大小 (batch_size x num_devices) 是对结果复现很重要,因此当GPU/NPU卡数发生变化时,调整`batch_size`以保持全局批大小不变,或将学习率线性调整为新的全局批大小。
132+
- 进行**模型训练**时,若`system.val_while_train`参数为`True`,将开启边训练边验证模式,此时需将`eval.dataset.dataset_root`设置为**验证**数据集根目录,将`eval.dataset.data_dir`设置为**验证**数据集目录(如`validation/`)。
133+
- 进行**模型评估**时,请将`eval.dataset.dataset_root`设置为**评估**数据集根目录,将`eval.dataset.data_dir`设置为**评估**数据集目录(如`evaluation/DATASET_NAME/`)。
134+
68135
### 模型训练
69136
<!--- Guideline: Avoid using shell script in the command line. Python script preferred. -->
70137

@@ -90,7 +157,6 @@ mpirun -n 8 python tools/train.py --config configs/rec/crnn/crnn_resnet34.yaml
90157
python tools/train.py --config configs/rec/crnn/crnn_resnet34.yaml
91158
```
92159

93-
**注意:** 由于全局批大小 (batch_size x num_devices) 是对结果复现很重要,因此当GPU/NPU卡数发生变化时,调整`batch_size`以保持全局批大小不变,或将学习率线性调整为新的全局批大小。
94160

95161
### 模型评估
96162

0 commit comments

Comments
 (0)