diff --git a/paddle/fluid/operators/interpolate_op.cu b/paddle/fluid/operators/interpolate_op.cu index 1effcf751f170d228ad1075e053119141aa11143..5beaa64664f69f1caa053b2f166ea8aced687290 100644 --- a/paddle/fluid/operators/interpolate_op.cu +++ b/paddle/fluid/operators/interpolate_op.cu @@ -553,13 +553,13 @@ __global__ void KeBicubicInterpFw( T in_img_idy = align_corners ? static_cast(ratio_h * out_img_idy) : static_cast(ratio_h * (out_img_idy + 0.5) - 0.5); - int input_y = static_cast(in_img_idy); + int input_y = floorf(in_img_idy); const T y_t = in_img_idy - input_y; T in_img_idx = align_corners ? static_cast(ratio_w * out_img_idx) : static_cast(ratio_w * (out_img_idx + 0.5) - 0.5); - int input_x = static_cast(in_img_idx); + int input_x = floorf(in_img_idx); const T x_t = in_img_idx - input_x; T coefficients[4]; @@ -665,13 +665,13 @@ __global__ void KeBicubicInterpBw( T in_img_idy = align_corners ? static_cast(ratio_h * out_img_idy) : static_cast(ratio_h * (out_img_idy + 0.5) - 0.5); - int input_y = static_cast(in_img_idy); + int input_y = floorf(in_img_idy); const T y_t = in_img_idy - input_y; T in_img_idx = align_corners ? static_cast(ratio_w * out_img_idx) : static_cast(ratio_w * (out_img_idx + 0.5) - 0.5); - int input_x = static_cast(in_img_idx); + int input_x = floorf(in_img_idx); const T x_t = in_img_idx - input_x; diff --git a/paddle/fluid/operators/interpolate_op.h b/paddle/fluid/operators/interpolate_op.h index 11c4e9f385e47bcc65e41cb42f5e84cefc99472e..8acd54200ecbb999be76c26f7ef999a2a7120ff9 100644 --- a/paddle/fluid/operators/interpolate_op.h +++ b/paddle/fluid/operators/interpolate_op.h @@ -389,13 +389,13 @@ static void BicubicInterpolation(const Tensor& input, Tensor* output, for (int k = 0; k < out_h; k++) { // loop for images T y_n = align_corners ? static_cast(ratio_h * k) : static_cast(ratio_h * (k + 0.5) - 0.5); - int input_y = static_cast(y_n); + int input_y = floorf(y_n); const T y_t = y_n - input_y; for (int l = 0; l < out_w; l++) { T x_n = align_corners ? static_cast(ratio_w * l) : static_cast(ratio_w * (l + 0.5) - 0.5); - int input_x = static_cast(x_n); + int input_x = floorf(x_n); const T x_t = x_n - input_x; for (int i = 0; i < n; i++) { // loop for batches @@ -625,13 +625,13 @@ static void BicubicInterpolationGrad(const Tensor& output_grad, for (int k = 0; k < out_h; k++) { // loop for images T y_n = align_corners ? static_cast(ratio_h * k) : static_cast(ratio_h * (k + 0.5) - 0.5); - int input_y = static_cast(y_n); + int input_y = floorf(y_n); T y_t = y_n - input_y; for (int l = 0; l < out_w; l++) { T x_n = align_corners ? static_cast(ratio_w * l) : static_cast(ratio_w * (l + 0.5) - 0.5); - int input_x = static_cast(x_n); + int input_x = floorf(x_n); T x_t = x_n - input_x; T x_coeffs[4]; diff --git a/python/paddle/fluid/tests/unittests/test_bicubic_interp_op.py b/python/paddle/fluid/tests/unittests/test_bicubic_interp_op.py index 68f98da8119b20d315aa86a103a5d0fd391613f4..616f9c5a392ebfac0b04735fd285c3c836b203b6 100644 --- a/python/paddle/fluid/tests/unittests/test_bicubic_interp_op.py +++ b/python/paddle/fluid/tests/unittests/test_bicubic_interp_op.py @@ -88,14 +88,14 @@ def bicubic_interp_np(input, h = ratio_h * k else: h = ratio_h * (k + 0.5) - 0.5 - input_y = int(h) + input_y = np.floor(h) y_t = h - input_y for l in range(out_w): if (align_corners): w = ratio_w * l else: w = ratio_w * (l + 0.5) - 0.5 - input_x = int(w) + input_x = np.floor(w) x_t = w - input_x for i in range(batch_size): for j in range(channel): @@ -265,7 +265,7 @@ class TestBicubicInterpDataLayout(TestBicubicInterpOp): class TestBicubicInterpOpAPI(unittest.TestCase): def test_case(self): - + np.random.seed(200) x_data = np.random.random((2, 3, 6, 6)).astype("float32") dim_data = np.array([12]).astype("int32") shape_data = np.array([12, 12]).astype("int32")