From e03171b7c7de5557599922d529d833416cd10022 Mon Sep 17 00:00:00 2001 From: littletomatodonkey <2120160898@bit.edu.cn> Date: Fri, 8 Jan 2021 16:47:14 +0800 Subject: [PATCH] fix pad (#30222) --- python/paddle/nn/functional/common.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/paddle/nn/functional/common.py b/python/paddle/nn/functional/common.py index 7319b860db8..fac5ca2f793 100644 --- a/python/paddle/nn/functional/common.py +++ b/python/paddle/nn/functional/common.py @@ -1276,6 +1276,9 @@ def pad(x, pad, mode='constant', value=0, data_format="NCHW", name=None): x_dim = len(x.shape) + if mode == "constant" and isinstance(pad, list) and len(pad) == x_dim * 2: + return layers.pad(x, pad, pad_value=value) + assert x_dim in [ 3, 4, 5 ], "input tesor dimension must be in [3, 4, 5] but got {}".format(x_dim) @@ -1291,9 +1294,6 @@ def pad(x, pad, mode='constant', value=0, data_format="NCHW", name=None): unsqueezed_dim = [] - if mode == "constant" and isinstance(pad, list) and len(pad) == x_dim * 2: - return layers.pad(x, pad, pad_value=value) - if isinstance(pad, Variable): if data_format in ["NCL", "NCHW", "NCDHW"]: data_format = "NCDHW" -- GitLab