-
Notifications
You must be signed in to change notification settings - Fork 45
/
crnn_icdar15.yaml
156 lines (146 loc) · 4.97 KB
/
crnn_icdar15.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
system:
mode: 0 # 0 for graph mode, 1 for pynative mode in MindSpore
distribute: False
amp_level: 'O3'
seed: 42
ckpt_save_policy: top_k # top_k or latest_k
ckpt_max_keep: 5
log_interval: 10
val_while_train: True
drop_overflow_update: False
common:
character_dict_path: &character_dict_path #mindocr/utils/dict/en_dict.txt
num_classes: &num_classes 37 # num_chars_in_dict+1, TODO: retreive it from dict or check correctness
max_text_len: &max_text_len 23
infer_mode: &infer_mode False
use_space_char: &use_space_char False
batch_size: &batch_size 16
model:
type: rec
transform: null
backbone:
name: rec_resnet34
pretrained: False
neck:
name: RNNEncoder
hidden_size: 256
head:
name: CTCHead
out_channels: *num_classes
pretrained: https://download.mindspore.cn/toolkits/mindocr/crnn/crnn_resnet34-83f37f07.ckpt # support local path and url
postprocess:
name: RecCTCLabelDecode
character_dict_path: *character_dict_path
use_space_char: *use_space_char
metric:
name: RecMetric
main_indicator: acc
character_dict_path: *character_dict_path
ignore_space: True
loss:
name: CTCLoss
pred_seq_len: 24 # TODO: retrieve from the network output shape.
max_label_len: *max_text_len # this value should be smaller than pre_seq_len
batch_size: *batch_size
scheduler:
scheduler: "cosine_decay"
min_lr: 0.0000006
lr: 0.00005
num_epochs: 12
warmup_epochs: 4
decay_epochs: 8
optimizer:
opt: lion
filter_bias_and_bn: False
momentum: 0.9
weight_decay: 0.0005
no_weight_decay_params: ['beta', 'gamma', 'bias'] # filter norm and bias params from weight decay
#grouping_strategy: "filter_norm_and_bias" # uncomment this line to use a predefined grouping strategy.
# only used for mixed precision training
loss_scaler:
type: dynamic
loss_scale: 512
scale_factor: 2.0
scale_window: 1000
train:
gradient_accumulation_steps: 2
clip_grad: True
clip_norm: 5.0
ema: True
ema_decay: 0.9999
ckpt_save_dir: './ckpt_rec_ic15_finetune'
dataset_sink_mode: False
pred_cast_fp32: False # let CTCLoss cast internally
dataset:
type: RecDataset
dataset_root: /path/to/data_root_dir
data_dir: ic15/rec/train/ch4_training_word_images_gt
label_file: ic15/rec/train/rec_gt.txt
sample_ratio: 1.0
shuffle: True
transform_pipeline:
- DecodeImage:
img_mode: BGR
to_float32: False
- RecCTCLabelEncode:
max_text_len: *max_text_len
character_dict_path: *character_dict_path
use_space_char: *use_space_char
lower: True
- RecResizeImg: # different from paddle (paddle converts image from HWC to CHW and rescale to [-1, 1] after resize.
image_shape: [32, 100] # H, W
infer_mode: *infer_mode
character_dict_path: *character_dict_path
padding: False # aspect ratio will be preserved if true.
- NormalizeImage: # different from paddle (paddle wrongly normalize BGR image with RGB mean/std from ImageNet for det, and simple rescale to [-1, 1] in rec.
bgr_to_rgb: True
is_hwc: True
mean : [127.0, 127.0, 127.0]
std : [127.0, 127.0, 127.0]
- ToCHWImage:
# the order of the dataloader list, matching the network input and the input labels for the loss function, and optional data for debug/visaulize
output_columns: ['image', 'text_seq'] #, 'length'] #'img_path']
net_input_column_index: [0] # input indices for network forward func in output_columns
label_column_index: [1] # input indices marked as label
loader:
shuffle: True # TODO: tbc
batch_size: *batch_size
drop_remainder: True
max_rowsize: 16
num_workers: 8
eval:
ckpt_load_path: './ckpt_rec_ic15_finetune/best.ckpt'
dataset_sink_mode: False
dataset:
type: RecDataset
dataset_root: /path/to/data_root_dir
data_dir: ic15/rec/test/ch4_test_word_images_gt
label_file: ic15/rec/test/rec_gt.txt
sample_ratio: 1.0
shuffle: False
transform_pipeline:
- DecodeImage:
img_mode: RGB
to_float32: False
- RecCTCLabelEncode:
max_text_len: *max_text_len
character_dict_path: *character_dict_path
use_space_char: *use_space_char
lower: True
- RecResizeNormForInfer:
target_height: 32
target_width: 100
keep_ratio: False
padding: False
norm_before_pad: False
- ToCHWImage:
# the order of the dataloader list, matching the network input and the input labels for the loss function, and optional data for debug/visaulize
output_columns: ['image', 'text_padded', 'text_length'] # TODO return text string padding w/ fixed length, and a scaler to indicate the length
net_input_column_index: [0] # input indices for network forward func in output_columns
label_column_index: [1, 2] # input indices marked as label
loader:
shuffle: False
batch_size: 32
drop_remainder: False
max_rowsize: 12
num_workers: 2