未验证 提交 96ffebef 编写于 作者: X xiaoting 提交者: GitHub

fix bicubic, change int to floor (#24063)

* change int to floor, test=develop

* fix unittest, test=develop
上级 a67eea9f
......@@ -553,13 +553,13 @@ __global__ void KeBicubicInterpFw(
T in_img_idy = align_corners
? static_cast<T>(ratio_h * out_img_idy)
: static_cast<T>(ratio_h * (out_img_idy + 0.5) - 0.5);
int input_y = static_cast<int>(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<T>(ratio_w * out_img_idx)
: static_cast<T>(ratio_w * (out_img_idx + 0.5) - 0.5);
int input_x = static_cast<int>(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<T>(ratio_h * out_img_idy)
: static_cast<T>(ratio_h * (out_img_idy + 0.5) - 0.5);
int input_y = static_cast<int>(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<T>(ratio_w * out_img_idx)
: static_cast<T>(ratio_w * (out_img_idx + 0.5) - 0.5);
int input_x = static_cast<int>(in_img_idx);
int input_x = floorf(in_img_idx);
const T x_t = in_img_idx - input_x;
......
......@@ -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<T>(ratio_h * k)
: static_cast<T>(ratio_h * (k + 0.5) - 0.5);
int input_y = static_cast<int>(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<T>(ratio_w * l)
: static_cast<T>(ratio_w * (l + 0.5) - 0.5);
int input_x = static_cast<int>(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<T>(ratio_h * k)
: static_cast<T>(ratio_h * (k + 0.5) - 0.5);
int input_y = static_cast<int>(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<T>(ratio_w * l)
: static_cast<T>(ratio_w * (l + 0.5) - 0.5);
int input_x = static_cast<int>(x_n);
int input_x = floorf(x_n);
T x_t = x_n - input_x;
T x_coeffs[4];
......
......@@ -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")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册