diff --git a/paddle/fluid/operators/interpolate_v2_op.cu b/paddle/fluid/operators/interpolate_v2_op.cu index d335e1a2f9d58bc4ea95710facf04ad33cd5b4e0..6f8b89ce64523d1cc10be5fbf8e1063d31cca289 100644 --- a/paddle/fluid/operators/interpolate_v2_op.cu +++ b/paddle/fluid/operators/interpolate_v2_op.cu @@ -1035,9 +1035,9 @@ static void Interpolate1DCUDAFwd(const framework::ExecutionContext& ctx, : static_cast(new_scale_w); } - int in_cw = c * in_w; - int out_cw = c * out_w; - int pixelNum = n * out_cw; + int64_t in_cw = c * in_w; + int64_t out_cw = c * out_w; + auto pixelNum = n * out_cw; platform::GpuLaunchConfig config = platform::GetGpuLaunchConfig1D(ctx.cuda_device_context(), pixelNum); @@ -1169,12 +1169,12 @@ static void Interpolate2DCUDAFwd(const framework::ExecutionContext& ctx, : static_cast(new_scale_w); } - int in_hw = in_h * in_w; - int out_hw = out_h * out_w; - int in_chw = c * in_hw; - int out_chw = c * out_hw; + int64_t in_hw = in_h * in_w; + int64_t out_hw = out_h * out_w; + int64_t in_chw = c * in_hw; + int64_t out_chw = c * out_hw; - int pixelNum = n * out_chw; + auto pixelNum = n * out_chw; platform::GpuLaunchConfig config = platform::GetGpuLaunchConfig1D(ctx.cuda_device_context(), pixelNum); @@ -1355,12 +1355,12 @@ static void Interpolate3DCUDAFwd(const framework::ExecutionContext& ctx, : static_cast(new_scale_w); } - int in_dhw = in_d * in_h * in_w; - int out_dhw = out_d * out_h * out_w; - int in_cdhw = c * in_dhw; - int out_cdhw = c * out_dhw; + int64_t in_dhw = in_d * in_h * in_w; + int64_t out_dhw = out_d * out_h * out_w; + int64_t in_cdhw = c * in_dhw; + int64_t out_cdhw = c * out_dhw; - int pixelNum = n * out_cdhw; + auto pixelNum = n * out_cdhw; platform::GpuLaunchConfig config = platform::GetGpuLaunchConfig1D(ctx.cuda_device_context(), pixelNum); @@ -1456,9 +1456,9 @@ static void Interpolate1DCUDABwd(const framework::ExecutionContext& ctx, ratio_w = (align_corners) ? static_cast(in_w - 1) / (out_w - 1) : static_cast(new_scale_w); } - int in_cw = c * in_w; - int out_cw = c * out_w; - int pixelNum = n * out_cw; + int64_t in_cw = c * in_w; + int64_t out_cw = c * out_w; + auto pixelNum = n * out_cw; platform::GpuLaunchConfig config = platform::GetGpuLaunchConfig1D(ctx.cuda_device_context(), pixelNum); @@ -1587,11 +1587,11 @@ static void Interpolate2DCUDABwd(const framework::ExecutionContext& ctx, : static_cast(new_scale_w); } - int in_hw = in_h * in_w; - int out_hw = out_h * out_w; - int in_chw = c * in_hw; - int out_chw = c * out_hw; - int pixelNum = n * out_chw; + int64_t in_hw = in_h * in_w; + int64_t out_hw = out_h * out_w; + int64_t in_chw = c * in_hw; + int64_t out_chw = c * out_hw; + auto pixelNum = n * out_chw; platform::GpuLaunchConfig config = platform::GetGpuLaunchConfig1D(ctx.cuda_device_context(), pixelNum); @@ -1773,12 +1773,12 @@ static void Interpolate3DCUDABwd(const framework::ExecutionContext& ctx, : static_cast(new_scale_w); } - int in_dhw = in_d * in_h * in_w; - int out_dhw = out_d * out_h * out_w; - int in_cdhw = c * in_dhw; - int out_cdhw = c * out_dhw; + int64_t in_dhw = in_d * in_h * in_w; + int64_t out_dhw = out_d * out_h * out_w; + int64_t in_cdhw = c * in_dhw; + int64_t out_cdhw = c * out_dhw; - int pixelNum = n * out_cdhw; + auto pixelNum = n * out_cdhw; platform::GpuLaunchConfig config = platform::GetGpuLaunchConfig1D(ctx.cuda_device_context(), pixelNum); diff --git a/python/paddle/nn/functional/common.py b/python/paddle/nn/functional/common.py index 7cda9a90ff07b0f2306149d5b2d10759091be2d1..323a8af52bccae5dc9f19f13b31c1d2a889e4145 100644 --- a/python/paddle/nn/functional/common.py +++ b/python/paddle/nn/functional/common.py @@ -295,13 +295,16 @@ def interpolate(x, "align_corners option can only be set with the interpolating modes: linear | bilinear | bicubic | trilinear" ) - if resample == 'AREA' and len(x.shape) == 3: - return paddle.nn.functional.adaptive_avg_pool1d(x, size) - - if resample == 'AREA' and len(x.shape) == 4: - return paddle.nn.functional.adaptive_avg_pool2d(x, size) - if resample == 'AREA' and len(x.shape) == 5: - return paddle.nn.functional.adaptive_avg_pool3d(x, size) + if resample == 'AREA': + if isinstance(size, list) or isinstance(size, tuple): + if len(size) == 0: + raise ValueError("output size can not be empty") + if len(x.shape) == 3: + return paddle.nn.functional.adaptive_avg_pool1d(x, size) + elif len(x.shape) == 4: + return paddle.nn.functional.adaptive_avg_pool2d(x, size) + elif len(x.shape) == 5: + return paddle.nn.functional.adaptive_avg_pool3d(x, size) helper = LayerHelper('{}_interp_v2'.format(resample_type), **locals()) dtype = helper.input_dtype(input_param_name='x') @@ -342,14 +345,13 @@ def interpolate(x, out_shape = size scale = scale_factor + if out_shape is not None and scale is not None: raise ValueError("Only one of size or scale_factor should be defined.") if out_shape is not None: - if isinstance(out_shape, Variable) and not in_dygraph_mode(): out_shape.stop_gradient = True inputs['OutSize'] = out_shape - else: if in_dygraph_mode(): if isinstance(out_shape, Variable):