Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RecResizeNormImg in Rec Transform to manage padding and norm in resize, add yaml of crnn for server version [WIP] #428

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions configs/rec/crnn/crnn_icdar15.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,12 @@ train:
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.
- RecResizeNormImg:
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]
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_seq'] #, 'length'] #'img_path']
Expand Down
10 changes: 3 additions & 7 deletions configs/rec/crnn/crnn_resnet34.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,23 +80,19 @@ train:
shuffle: True
transform_pipeline:
- DecodeImage:
img_mode: BGR
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
- RecResizeImg: # different from paddle (paddle converts image from HWC to CHW and rescale to [-1, 1] after resize.
- RecResizeNormImg:
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]
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_seq'] #, 'length'] #'img_path']
Expand Down
14 changes: 5 additions & 9 deletions configs/rec/crnn/crnn_resnet34_ch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ train:
max_text_len: *max_text_len
transform_pipeline:
- DecodeImage:
img_mode: BGR
img_mode: RGB
to_float32: False
- RecCTCLabelEncode:
max_text_len: *max_text_len
Expand All @@ -94,16 +94,12 @@ train:
- Rotate90IfVertical:
threshold: 2.0
direction: counterclockwise
- RecResizeImg:
image_shape: [32, 320]
- RecResizeNormImg:
image_shape: [32, 320] # H, W
infer_mode: *infer_mode
character_dict_path: *character_dict_path
padding: True
- NormalizeImage:
bgr_to_rgb: True
is_hwc: True
mean: [127.0, 127.0, 127.0]
std: [127.0, 127.0, 127.0]
padding: True # aspect ratio will be preserved if true.
norm_before_pad: False
- ToCHWImage:
output_columns: ["image", "text_seq"]
net_input_column_index: [0]
Expand Down
150 changes: 150 additions & 0 deletions configs/rec/crnn/crnn_resnet34_server.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
system:
mode: 0 # 0 for graph mode, 1 for pynative mode in MindSpore
distribute: True
amp_level: 'O3'
seed: 42
log_interval: 100
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 96 # num_chars_in_dict+1, TODO: retreive it from dict or check correctness
max_text_len: &max_text_len 24
infer_mode: &infer_mode False
use_space_char: &use_space_char True
lower: &lower False
batch_size: &batch_size 64

model:
type: rec
transform: null
backbone:
name: rec_resnet34
pretrained: False
neck:
name: RNNEncoder
hidden_size: 256
head:
name: CTCHead
weight_init: crnn_customised
bias_init: crnn_customised
out_channels: *num_classes

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
print_flag: False

loss:
name: CTCLoss
pred_seq_len: 25 # 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: warmup_cosine_decay
min_lr: 0.000001
lr: 0.001
num_epochs: 30
warmup_epochs: 2
decay_epochs: 28

optimizer:
opt: adamw
filter_bias_and_bn: True
momentum: 0.95
weight_decay: 0.0001
nesterov: False

loss_scaler:
type: dynamic
loss_scale: 512
scale_factor: 2.0
scale_window: 1000

train:
ckpt_save_dir: './crnn_resnet34_server'
pred_cast_fp32: False # let CTCLoss cast internally
ema: True # added
dataset_sink_mode: False
dataset:
type: LMDBDataset
dataset_root: /path/to/data_lmdb_release/
data_dir: training/
# label_file: # not required when using LMDBDataset
sample_ratio: 1.0
shuffle: True
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: *lower
- RecResizeNormImg:
image_shape: [32, 100] # H, W
infer_mode: *infer_mode
character_dict_path: *character_dict_path
padding: True # aspect ratio will be preserved if true.
norm_before_pad: True
- 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
#keys_for_loss: 4 # num labels for loss func

loader:
shuffle: True
batch_size: *batch_size
drop_remainder: True
max_rowsize: 12
num_workers: 8

eval:
ckpt_load_path: ./crnn_resnet34_server/best.ckpt
dataset_sink_mode: False
dataset:
type: LMDBDataset
dataset_root: /path/to/data_lmdb_release/
data_dir: validation/
# label_file: # not required when using LMDBDataset
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: *lower
- RecResizeNormImg:
image_shape: [32, 100] # H, W
infer_mode: *infer_mode
character_dict_path: *character_dict_path
padding: True # aspect ratio will be preserved if true.
norm_before_pad: True
- 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 # TODO: tbc
batch_size: 64
drop_remainder: False
max_rowsize: 12
num_workers: 8
10 changes: 3 additions & 7 deletions configs/rec/crnn/crnn_vgg7.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,19 @@ train:
shuffle: True
transform_pipeline:
- DecodeImage:
img_mode: BGR
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
- RecResizeImg: # different from paddle (paddle converts image from HWC to CHW and rescale to [-1, 1] after resize.
- RecResizeNormImg:
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]
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_seq'] #, 'length'] #'img_path']
Expand Down
8 changes: 2 additions & 6 deletions configs/rec/rare/rare_resnet34.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,12 @@ train:
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.
- RecResizeNormImg:
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]
norm_before_pad: False
- ToCHWImage:
output_columns: ["image", "text_seq"]
net_input_column_index: [0, 1] # input indices for network forward func in output_columns
Expand Down
12 changes: 4 additions & 8 deletions configs/rec/rare/rare_resnet34_ch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,12 @@ train:
- Rotate90IfVertical:
threshold: 2.0
direction: counterclockwise
- RecResizeImg:
image_shape: [32, 320]
- RecResizeNormImg:
image_shape: [32, 320] # H, W
infer_mode: *infer_mode
character_dict_path: *character_dict_path
padding: True
- NormalizeImage:
bgr_to_rgb: True
is_hwc: True
mean: [127.0, 127.0, 127.0]
std: [127.0, 127.0, 127.0]
padding: True # aspect ratio will be preserved if true.
norm_before_pad: False
- ToCHWImage:
output_columns: ["image", "text_seq"]
net_input_column_index: [0, 1]
Expand Down
Loading