未验证 提交 20cb993c 编写于 作者: Z zhoujun 提交者: GitHub

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 svtr
上级 6001b1a0
......@@ -20,6 +20,7 @@ Global:
infer_mode: False
use_space_char: False
save_res_path: ./output/rec/predicts_svtr_tiny.txt
d2s_train_image_shape: [3, 64, 256]
Optimizer:
......
......@@ -19,6 +19,7 @@ Global:
infer_mode: false
use_space_char: true
save_res_path: ./output/rec/predicts_svtr_tiny_ch_all.txt
d2s_train_image_shape: [3, 32, 320]
Optimizer:
name: AdamW
beta1: 0.9
......
......@@ -40,7 +40,9 @@ def apply_to_static(model, config, logger):
return model
assert "d2s_train_image_shape" in config[
"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"]:
algo = list(config["Architecture"]["Models"].values())[0]["algorithm"]
else:
......@@ -104,6 +106,13 @@ def apply_to_static(model, config, logger):
InputSpec(
[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)
logger.info("Successfully to apply @to_static with specs: {}".format(specs))
return model
......@@ -140,7 +140,9 @@ class TPSSpatialTransformer(nn.Layer):
padding_matrix = paddle.expand(
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)
source_coordinate = paddle.matmul(self.target_coordinate_repr,
mapping_matrix)
......@@ -153,4 +155,4 @@ class TPSSpatialTransformer(nn.Layer):
# the input to grid_sample is normalized [-1, 1], but what we get is [0, 1]
grid = 2.0 * grid - 1.0
output_maps = grid_sample(input, grid, canvas=None)
return output_maps, source_coordinate
\ No newline at end of file
return output_maps, source_coordinate
......@@ -20,6 +20,7 @@ Global:
infer_mode: False
use_space_char: False
save_res_path: ./output/rec/predicts_svtr_tiny.txt
d2s_train_image_shape: [3, 64, 256]
Optimizer:
......
......@@ -51,3 +51,11 @@ inference:tools/infer/predict_rec.py --rec_char_dict_path=./ppocr/utils/ic15_dic
null:null
===========================infer_benchmark_params==========================
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
\ No newline at end of file
......@@ -145,6 +145,19 @@ if [ ${MODE} = "benchmark_train" ];then
cd ./train_data/ && tar xf StructureLabel_val_500.tar
cd ../
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
if [ ${MODE} = "lite_train_lite_infer" ];then
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册