add d2t train support of svtr (#9479)
* add d2s train for slanet and v3 * fix bug * udpate tipc to_static * update db * remove_print * update benchmark_train.sh * update maybe_download_params * add d2t train support of svtrpull/9510/head^2
parent
6001b1a07b
commit
20cb993cb6
|
@ -20,6 +20,7 @@ Global:
|
||||||
infer_mode: False
|
infer_mode: False
|
||||||
use_space_char: False
|
use_space_char: False
|
||||||
save_res_path: ./output/rec/predicts_svtr_tiny.txt
|
save_res_path: ./output/rec/predicts_svtr_tiny.txt
|
||||||
|
d2s_train_image_shape: [3, 64, 256]
|
||||||
|
|
||||||
|
|
||||||
Optimizer:
|
Optimizer:
|
||||||
|
|
|
@ -19,6 +19,7 @@ Global:
|
||||||
infer_mode: false
|
infer_mode: false
|
||||||
use_space_char: true
|
use_space_char: true
|
||||||
save_res_path: ./output/rec/predicts_svtr_tiny_ch_all.txt
|
save_res_path: ./output/rec/predicts_svtr_tiny_ch_all.txt
|
||||||
|
d2s_train_image_shape: [3, 32, 320]
|
||||||
Optimizer:
|
Optimizer:
|
||||||
name: AdamW
|
name: AdamW
|
||||||
beta1: 0.9
|
beta1: 0.9
|
||||||
|
|
|
@ -40,7 +40,9 @@ def apply_to_static(model, config, logger):
|
||||||
return model
|
return model
|
||||||
assert "d2s_train_image_shape" in config[
|
assert "d2s_train_image_shape" in config[
|
||||||
"Global"], "d2s_train_image_shape must be assigned for static training mode..."
|
"Global"], "d2s_train_image_shape must be assigned for static training mode..."
|
||||||
supported_list = ["DB", "SVTR_LCNet", "TableMaster", "LayoutXLM", "SLANet"]
|
supported_list = [
|
||||||
|
"DB", "SVTR_LCNet", "TableMaster", "LayoutXLM", "SLANet", "SVTR"
|
||||||
|
]
|
||||||
if config["Architecture"]["algorithm"] in ["Distillation"]:
|
if config["Architecture"]["algorithm"] in ["Distillation"]:
|
||||||
algo = list(config["Architecture"]["Models"].values())[0]["algorithm"]
|
algo = list(config["Architecture"]["Models"].values())[0]["algorithm"]
|
||||||
else:
|
else:
|
||||||
|
@ -104,6 +106,13 @@ def apply_to_static(model, config, logger):
|
||||||
InputSpec(
|
InputSpec(
|
||||||
[None, 6], dtype='float64'),
|
[None, 6], dtype='float64'),
|
||||||
])
|
])
|
||||||
|
elif algo == "SVTR":
|
||||||
|
specs.append([
|
||||||
|
InputSpec(
|
||||||
|
[None, config["Global"]["max_text_length"]], dtype='int64'),
|
||||||
|
InputSpec(
|
||||||
|
[None], dtype='int64')
|
||||||
|
])
|
||||||
model = to_static(model, input_spec=specs)
|
model = to_static(model, input_spec=specs)
|
||||||
logger.info("Successfully to apply @to_static with specs: {}".format(specs))
|
logger.info("Successfully to apply @to_static with specs: {}".format(specs))
|
||||||
return model
|
return model
|
||||||
|
|
|
@ -140,7 +140,9 @@ class TPSSpatialTransformer(nn.Layer):
|
||||||
|
|
||||||
padding_matrix = paddle.expand(
|
padding_matrix = paddle.expand(
|
||||||
self.padding_matrix, shape=[batch_size, 3, 2])
|
self.padding_matrix, shape=[batch_size, 3, 2])
|
||||||
Y = paddle.concat([source_control_points, padding_matrix], 1)
|
Y = paddle.concat([
|
||||||
|
source_control_points.astype(padding_matrix.dtype), padding_matrix
|
||||||
|
], 1)
|
||||||
mapping_matrix = paddle.matmul(self.inverse_kernel, Y)
|
mapping_matrix = paddle.matmul(self.inverse_kernel, Y)
|
||||||
source_coordinate = paddle.matmul(self.target_coordinate_repr,
|
source_coordinate = paddle.matmul(self.target_coordinate_repr,
|
||||||
mapping_matrix)
|
mapping_matrix)
|
||||||
|
|
|
@ -20,6 +20,7 @@ Global:
|
||||||
infer_mode: False
|
infer_mode: False
|
||||||
use_space_char: False
|
use_space_char: False
|
||||||
save_res_path: ./output/rec/predicts_svtr_tiny.txt
|
save_res_path: ./output/rec/predicts_svtr_tiny.txt
|
||||||
|
d2s_train_image_shape: [3, 64, 256]
|
||||||
|
|
||||||
|
|
||||||
Optimizer:
|
Optimizer:
|
||||||
|
|
|
@ -51,3 +51,11 @@ inference:tools/infer/predict_rec.py --rec_char_dict_path=./ppocr/utils/ic15_dic
|
||||||
null:null
|
null:null
|
||||||
===========================infer_benchmark_params==========================
|
===========================infer_benchmark_params==========================
|
||||||
random_infer_input:[{float32,[3,64,256]}]
|
random_infer_input:[{float32,[3,64,256]}]
|
||||||
|
===========================train_benchmark_params==========================
|
||||||
|
batch_size:512
|
||||||
|
fp_items:fp32|fp16
|
||||||
|
epoch:2
|
||||||
|
--profiler_options:batch_range=[10,20];state=GPU;tracer_option=Default;profile_path=model.profile
|
||||||
|
flags:FLAGS_eager_delete_tensor_gb=0.0;FLAGS_fraction_of_gpu_memory_to_use=0.98;FLAGS_conv_workspace_size_limit=4096
|
||||||
|
===========================to_static_train_benchmark_params===========================
|
||||||
|
to_static_train:Global.to_static=true
|
|
@ -145,6 +145,19 @@ if [ ${MODE} = "benchmark_train" ];then
|
||||||
cd ./train_data/ && tar xf StructureLabel_val_500.tar
|
cd ./train_data/ && tar xf StructureLabel_val_500.tar
|
||||||
cd ../
|
cd ../
|
||||||
fi
|
fi
|
||||||
|
if [ ${model_name} == "rec_svtrnet" ]; then
|
||||||
|
wget -nc -P ./train_data/ https://paddleocr.bj.bcebos.com/dataset/ic15_data_benckmark.tar --no-check-certificate
|
||||||
|
cd ./train_data/ && tar xf ic15_data_benckmark.tar
|
||||||
|
ln -s ./ic15_data_benckmark ./ic15_data
|
||||||
|
cd ic15_data
|
||||||
|
mv rec_gt_train4w.txt rec_gt_train.txt
|
||||||
|
|
||||||
|
for i in `seq 10`;do cp rec_gt_train.txt dup$i.txt;done
|
||||||
|
cat dup* > rec_gt_train.txt && rm -rf dup*
|
||||||
|
|
||||||
|
cd ../
|
||||||
|
cd ../
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ${MODE} = "lite_train_lite_infer" ];then
|
if [ ${MODE} = "lite_train_lite_infer" ];then
|
||||||
|
|
Loading…
Reference in New Issue