未验证 提交 91c0f727 编写于 作者: C Chenxiao Niu 提交者: GitHub

[MLU] uncomment some interp_v2 tests. (#44053)

上级 bd06a828
...@@ -515,51 +515,55 @@ class TestBilinearInterp_attr_tensor_Case3(TestBilinearInterpOp_attr_tensor): ...@@ -515,51 +515,55 @@ class TestBilinearInterp_attr_tensor_Case3(TestBilinearInterpOp_attr_tensor):
self.scale_by_1Dtensor = True self.scale_by_1Dtensor = True
#TODO: comment this test for now until bilinear_interp_op added. class TestBilinearInterpOpAPI(unittest.TestCase):
# class TestBilinearInterpOpAPI(unittest.TestCase):
# def test_case(self): def test_case(self):
# x = fluid.data(name="x", shape=[2, 3, 6, 6], dtype="float32") x = fluid.data(name="x", shape=[2, 3, 6, 6], dtype="float32")
# dim = fluid.data(name="dim", shape=[1], dtype="int32") dim = fluid.data(name="dim", shape=[1], dtype="int32")
# shape_tensor = fluid.data(name="shape_tensor", shape=[2], dtype="int32") shape_tensor = fluid.data(name="shape_tensor", shape=[2], dtype="int32")
# actual_size = fluid.data(name="actual_size", shape=[2], dtype="int32") actual_size = fluid.data(name="actual_size", shape=[2], dtype="int32")
# scale_tensor = fluid.data( scale_tensor = fluid.data(name="scale_tensor",
# name="scale_tensor", shape=[1], dtype="float32") shape=[1],
dtype="float32")
# out1 = fluid.layers.resize_bilinear(x, out_shape=[12, 12])
# out2 = fluid.layers.resize_bilinear(x, out_shape=[12, dim]) out1 = fluid.layers.resize_bilinear(x, out_shape=[12, 12])
# out3 = fluid.layers.resize_bilinear(x, out_shape=shape_tensor) out2 = fluid.layers.resize_bilinear(x, out_shape=[12, dim])
# out4 = fluid.layers.resize_bilinear( out3 = fluid.layers.resize_bilinear(x, out_shape=shape_tensor)
# x, out_shape=[4, 4], actual_shape=actual_size) out4 = fluid.layers.resize_bilinear(x,
# out5 = fluid.layers.resize_bilinear(x, scale=scale_tensor) out_shape=[4, 4],
actual_shape=actual_size)
# x_data = np.random.random((2, 3, 6, 6)).astype("float32") out5 = fluid.layers.resize_bilinear(x, scale=scale_tensor)
# dim_data = np.array([12]).astype("int32")
# shape_data = np.array([12, 12]).astype("int32") x_data = np.random.random((2, 3, 6, 6)).astype("float32")
# actual_size_data = np.array([12, 12]).astype("int32") dim_data = np.array([12]).astype("int32")
# scale_data = np.array([2.0]).astype("float32") shape_data = np.array([12, 12]).astype("int32")
actual_size_data = np.array([12, 12]).astype("int32")
# if core.is_compiled_with_mlu(): scale_data = np.array([2.0]).astype("float32")
# place = paddle.device.MLUPlace(0)
# else: if core.is_compiled_with_mlu():
# place = core.CPUPlace() place = paddle.device.MLUPlace(0)
# exe = fluid.Executor(place) else:
# exe.run(fluid.default_startup_program()) place = core.CPUPlace()
# results = exe.run(fluid.default_main_program(), exe = fluid.Executor(place)
# feed={ exe.run(fluid.default_startup_program())
# "x": x_data, results = exe.run(fluid.default_main_program(),
# "dim": dim_data, feed={
# "shape_tensor": shape_data, "x": x_data,
# "actual_size": actual_size_data, "dim": dim_data,
# "scale_tensor": scale_data "shape_tensor": shape_data,
# }, "actual_size": actual_size_data,
# fetch_list=[out1, out2, out3, out4, out5], "scale_tensor": scale_data
# return_numpy=True) },
fetch_list=[out1, out2, out3, out4, out5],
# expect_res = bilinear_interp_np( return_numpy=True)
# x_data, out_h=12, out_w=12, align_corners=True)
# for res in results: expect_res = bilinear_interp_np(x_data,
# self.assertTrue(np.allclose(res, expect_res)) out_h=12,
out_w=12,
align_corners=True)
for res in results:
self.assertTrue(np.allclose(res, expect_res))
class TestBilinearInterpOpAPI_dy(unittest.TestCase): class TestBilinearInterpOpAPI_dy(unittest.TestCase):
......
...@@ -274,6 +274,7 @@ class TestNearestInterpOp(OpTest): ...@@ -274,6 +274,7 @@ class TestNearestInterpOp(OpTest):
self.align_corners = True self.align_corners = True
# comment out since 5-D input not supported now
# class TestNearestNeighborInterpCase1(TestNearestInterpOp): # class TestNearestNeighborInterpCase1(TestNearestInterpOp):
# def init_test_case(self): # def init_test_case(self):
# self.interp_method = 'nearest' # self.interp_method = 'nearest'
...@@ -537,56 +538,66 @@ class TestNearestInterp_attr_tensor_Case3(TestNearestInterpOp_attr_tensor): ...@@ -537,56 +538,66 @@ class TestNearestInterp_attr_tensor_Case3(TestNearestInterpOp_attr_tensor):
self.scale_by_1Dtensor = True self.scale_by_1Dtensor = True
#TODO: comment this test for now until nearest_interp_op added. class TestNearestAPI(unittest.TestCase):
# class TestNearestAPI(unittest.TestCase):
# def test_case(self): def test_case(self):
# x = fluid.data(name="x", shape=[2, 3, 6, 6], dtype="float32") x = fluid.data(name="x", shape=[2, 3, 6, 6], dtype="float32")
# y = fluid.data(name="y", shape=[2, 6, 6, 3], dtype="float32") y = fluid.data(name="y", shape=[2, 6, 6, 3], dtype="float32")
# dim = fluid.data(name="dim", shape=[1], dtype="int32") dim = fluid.data(name="dim", shape=[1], dtype="int32")
# shape_tensor = fluid.data(name="shape_tensor", shape=[2], dtype="int32") shape_tensor = fluid.data(name="shape_tensor", shape=[2], dtype="int32")
# actual_size = fluid.data(name="actual_size", shape=[2], dtype="int32") actual_size = fluid.data(name="actual_size", shape=[2], dtype="int32")
# scale_tensor = fluid.data( scale_tensor = fluid.data(name="scale_tensor",
# name="scale_tensor", shape=[1], dtype="float32") shape=[1],
dtype="float32")
# out1 = fluid.layers.resize_nearest(
# y, out_shape=[12, 12], data_format='NHWC', align_corners=False) out1 = fluid.layers.resize_nearest(y,
# out2 = fluid.layers.resize_nearest( out_shape=[12, 12],
# x, out_shape=[12, dim], align_corners=False) data_format='NHWC',
# out3 = fluid.layers.resize_nearest( align_corners=False)
# x, out_shape=shape_tensor, align_corners=False) out2 = fluid.layers.resize_nearest(x,
# out4 = fluid.layers.resize_nearest( out_shape=[12, dim],
# x, out_shape=[4, 4], actual_shape=actual_size, align_corners=False) align_corners=False)
# out5 = fluid.layers.resize_nearest( out3 = fluid.layers.resize_nearest(x,
# x, scale=scale_tensor, align_corners=False) out_shape=shape_tensor,
align_corners=False)
# x_data = np.random.random((2, 3, 6, 6)).astype("float32") out4 = fluid.layers.resize_nearest(x,
# dim_data = np.array([12]).astype("int32") out_shape=[4, 4],
# shape_data = np.array([12, 12]).astype("int32") actual_shape=actual_size,
# actual_size_data = np.array([12, 12]).astype("int32") align_corners=False)
# scale_data = np.array([2.0]).astype("float32") out5 = fluid.layers.resize_nearest(x,
scale=scale_tensor,
# place = paddle.MLUPlace(0) align_corners=False)
# exe = fluid.Executor(place)
# exe.run(fluid.default_startup_program()) x_data = np.random.random((2, 3, 6, 6)).astype("float32")
# results = exe.run(fluid.default_main_program(), dim_data = np.array([12]).astype("int32")
# feed={ shape_data = np.array([12, 12]).astype("int32")
# "x": x_data, actual_size_data = np.array([12, 12]).astype("int32")
# "y": np.transpose(x_data, (0, 2, 3, 1)), scale_data = np.array([2.0]).astype("float32")
# "dim": dim_data,
# "shape_tensor": shape_data, place = paddle.MLUPlace(0)
# "actual_size": actual_size_data, exe = fluid.Executor(place)
# "scale_tensor": scale_data exe.run(fluid.default_startup_program())
# }, results = exe.run(fluid.default_main_program(),
# fetch_list=[out1, out2, out3, out4, out5], feed={
# return_numpy=True) "x": x_data,
"y": np.transpose(x_data, (0, 2, 3, 1)),
# expect_res = nearest_neighbor_interp_np( "dim": dim_data,
# x_data, out_h=12, out_w=12, align_corners=False) "shape_tensor": shape_data,
# self.assertTrue( "actual_size": actual_size_data,
# np.allclose(results[0], np.transpose(expect_res, (0, 2, 3, 1)))) "scale_tensor": scale_data
# for i in range(len(results) - 1): },
# self.assertTrue(np.allclose(results[i + 1], expect_res)) fetch_list=[out1, out2, out3, out4, out5],
return_numpy=True)
expect_res = nearest_neighbor_interp_np(x_data,
out_h=12,
out_w=12,
align_corners=False)
self.assertTrue(
np.allclose(results[0], np.transpose(expect_res, (0, 2, 3, 1))))
for i in range(len(results) - 1):
self.assertTrue(np.allclose(results[i + 1], expect_res))
class TestNearestInterpException(unittest.TestCase): class TestNearestInterpException(unittest.TestCase):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册