From c07c5de1edc513606b0909dec341a5fd8b5795ef Mon Sep 17 00:00:00 2001 From: jm12138 <2286040843@qq.com> Date: Mon, 25 Jan 2021 11:00:43 +0800 Subject: [PATCH] Fix a bug of DropPath (#575) --- ppcls/modeling/architectures/vision_transformer.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ppcls/modeling/architectures/vision_transformer.py b/ppcls/modeling/architectures/vision_transformer.py index 43c87d11..8ff59cf1 100644 --- a/ppcls/modeling/architectures/vision_transformer.py +++ b/ppcls/modeling/architectures/vision_transformer.py @@ -42,14 +42,13 @@ def drop_path(x, drop_prob=0., training=False): """ if drop_prob == 0. or not training: return x - keep_prob = 1 - drop_prob + keep_prob = paddle.to_tensor(1 - drop_prob) shape = (x.shape[0],) + (1,) * (x.ndim - 1) random_tensor = keep_prob + paddle.rand(shape, dtype=x.dtype) - random_tensor.floor_() # binarize - output = x.div(keep_prob) * random_tensor + random_tensor = paddle.floor(random_tensor) # binarize + output = x.divide(keep_prob) * random_tensor return output - class DropPath(nn.Layer): """Drop paths (Stochastic Depth) per sample (when applied in main path of residual blocks). """ -- GitLab