From 14adbd09f2ab768e14ba7e9b5564b21ae776702a Mon Sep 17 00:00:00 2001
From: topduke <784990967@qq.com>
Date: Tue, 7 Feb 2023 14:12:06 +0800
Subject: [PATCH] fix piecewise boundaries and droppath dtype (#8990)

* fix tipc piecewise boundaries and droppath dtype

* fix piecewise boundaries and droppath dtype
---
 configs/rec/PP-OCRv3/ch_PP-OCRv3_rec_distillation.yml         | 2 +-
 configs/rec/ch_PP-OCRv2/ch_PP-OCRv2_rec.yml                   | 2 +-
 configs/rec/ch_PP-OCRv2/ch_PP-OCRv2_rec_distillation.yml      | 2 +-
 configs/rec/ch_PP-OCRv2/ch_PP-OCRv2_rec_enhanced_ctc_loss.yml | 2 +-
 configs/rec/rec_resnet_stn_bilstm_att.yml                     | 4 ++--
 ppocr/modeling/backbones/rec_svtrnet.py                       | 2 +-
 .../configs/ch_PP-OCRv2_rec/ch_PP-OCRv2_rec_distillation.yml  | 2 +-
 .../configs/ch_PP-OCRv3_rec/ch_PP-OCRv3_rec_distillation.yml  | 2 +-
 8 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/configs/rec/PP-OCRv3/ch_PP-OCRv3_rec_distillation.yml b/configs/rec/PP-OCRv3/ch_PP-OCRv3_rec_distillation.yml
index 427255738..afa012b60 100644
--- a/configs/rec/PP-OCRv3/ch_PP-OCRv3_rec_distillation.yml
+++ b/configs/rec/PP-OCRv3/ch_PP-OCRv3_rec_distillation.yml
@@ -27,7 +27,7 @@ Optimizer:
   beta2: 0.999
   lr:
     name: Piecewise
-    decay_epochs : [700, 800]
+    decay_epochs : [700]
     values : [0.0005, 0.00005]
     warmup_epoch: 5
   regularizer:
diff --git a/configs/rec/ch_PP-OCRv2/ch_PP-OCRv2_rec.yml b/configs/rec/ch_PP-OCRv2/ch_PP-OCRv2_rec.yml
index e2aa50106..793bb5c91 100644
--- a/configs/rec/ch_PP-OCRv2/ch_PP-OCRv2_rec.yml
+++ b/configs/rec/ch_PP-OCRv2/ch_PP-OCRv2_rec.yml
@@ -27,7 +27,7 @@ Optimizer:
   beta2: 0.999
   lr:
     name: Piecewise
-    decay_epochs : [700, 800]
+    decay_epochs : [700]
     values : [0.001, 0.0001]
     warmup_epoch: 5
   regularizer:
diff --git a/configs/rec/ch_PP-OCRv2/ch_PP-OCRv2_rec_distillation.yml b/configs/rec/ch_PP-OCRv2/ch_PP-OCRv2_rec_distillation.yml
index ab48b9979..dddfc3315 100644
--- a/configs/rec/ch_PP-OCRv2/ch_PP-OCRv2_rec_distillation.yml
+++ b/configs/rec/ch_PP-OCRv2/ch_PP-OCRv2_rec_distillation.yml
@@ -27,7 +27,7 @@ Optimizer:
   beta2: 0.999
   lr:
     name: Piecewise
-    decay_epochs : [700, 800]
+    decay_epochs : [700]
     values : [0.001, 0.0001]
     warmup_epoch: 5
   regularizer:
diff --git a/configs/rec/ch_PP-OCRv2/ch_PP-OCRv2_rec_enhanced_ctc_loss.yml b/configs/rec/ch_PP-OCRv2/ch_PP-OCRv2_rec_enhanced_ctc_loss.yml
index 5be96969f..ef0e893fa 100644
--- a/configs/rec/ch_PP-OCRv2/ch_PP-OCRv2_rec_enhanced_ctc_loss.yml
+++ b/configs/rec/ch_PP-OCRv2/ch_PP-OCRv2_rec_enhanced_ctc_loss.yml
@@ -27,7 +27,7 @@ Optimizer:
   beta2: 0.999
   lr:
     name: Piecewise
-    decay_epochs : [700, 800]
+    decay_epochs : [700]
     values : [0.001, 0.0001]
     warmup_epoch: 5
   regularizer:
diff --git a/configs/rec/rec_resnet_stn_bilstm_att.yml b/configs/rec/rec_resnet_stn_bilstm_att.yml
index 0bb90b352..20ed9533c 100644
--- a/configs/rec/rec_resnet_stn_bilstm_att.yml
+++ b/configs/rec/rec_resnet_stn_bilstm_att.yml
@@ -1,6 +1,6 @@
 Global:
   use_gpu: True
-  epoch_num: 400
+  epoch_num: 6
   log_smooth_window: 20
   print_batch_step: 10
   save_model_dir: ./output/rec/seed
@@ -27,7 +27,7 @@ Optimizer:
   momentum: 0.9
   lr:
     name: Piecewise
-    decay_epochs: [4,5,8]
+    decay_epochs: [4, 5]
     values: [1.0, 0.1, 0.01]
   regularizer:
     name: 'L2'
diff --git a/ppocr/modeling/backbones/rec_svtrnet.py b/ppocr/modeling/backbones/rec_svtrnet.py
index c2c07f447..de5920c63 100644
--- a/ppocr/modeling/backbones/rec_svtrnet.py
+++ b/ppocr/modeling/backbones/rec_svtrnet.py
@@ -32,7 +32,7 @@ def drop_path(x, drop_prob=0., training=False):
     """
     if drop_prob == 0. or not training:
         return x
-    keep_prob = paddle.to_tensor(1 - drop_prob)
+    keep_prob = paddle.to_tensor(1 - drop_prob, dtype=x.dtype)
     shape = (paddle.shape(x)[0], ) + (1, ) * (x.ndim - 1)
     random_tensor = keep_prob + paddle.rand(shape, dtype=x.dtype)
     random_tensor = paddle.floor(random_tensor)  # binarize
diff --git a/test_tipc/configs/ch_PP-OCRv2_rec/ch_PP-OCRv2_rec_distillation.yml b/test_tipc/configs/ch_PP-OCRv2_rec/ch_PP-OCRv2_rec_distillation.yml
index 3eb82d42b..43e14b84d 100644
--- a/test_tipc/configs/ch_PP-OCRv2_rec/ch_PP-OCRv2_rec_distillation.yml
+++ b/test_tipc/configs/ch_PP-OCRv2_rec/ch_PP-OCRv2_rec_distillation.yml
@@ -27,7 +27,7 @@ Optimizer:
   beta2: 0.999
   lr:
     name: Piecewise
-    decay_epochs : [700, 800]
+    decay_epochs : [700]
     values : [0.001, 0.0001]
     warmup_epoch: 5
   regularizer:
diff --git a/test_tipc/configs/ch_PP-OCRv3_rec/ch_PP-OCRv3_rec_distillation.yml b/test_tipc/configs/ch_PP-OCRv3_rec/ch_PP-OCRv3_rec_distillation.yml
index 4c8ba0a6f..8150d95e3 100644
--- a/test_tipc/configs/ch_PP-OCRv3_rec/ch_PP-OCRv3_rec_distillation.yml
+++ b/test_tipc/configs/ch_PP-OCRv3_rec/ch_PP-OCRv3_rec_distillation.yml
@@ -27,7 +27,7 @@ Optimizer:
   beta2: 0.999
   lr:
     name: Piecewise
-    decay_epochs : [700, 800]
+    decay_epochs : [700]
     values : [0.0005, 0.00005]
     warmup_epoch: 5
   regularizer: