提交 483d0512 编写于 作者: Z Zhang Ting 提交者: Aurelius84

Add choice of CUDA Place and remove fluid.layers.data for python API test of resize Ops (#20689)

* add cuda place and remove fluid.layers.data for test of python API, test=develop

* add cuda place and remove fluid.layers.data for test of python API, test=develop

* modified batch size for Python API test, test=develop
上级 ba44f654
......@@ -486,25 +486,13 @@ class TestBilinearInterp_attr_tensor_Case3(TestBilinearInterpOp_attr_tensor):
class TestBilinearInterpOpAPI(OpTest):
def test_case(self):
x = fluid.layers.data(name="x", shape=[3, 6, 6], dtype="float32")
dim = fluid.layers.data(
name="dim", shape=[1], dtype="int32", append_batch_size=False)
shape_tensor = fluid.layers.data(
name="shape_tensor",
shape=[2],
dtype="int32",
append_batch_size=False)
actual_size = fluid.layers.data(
name="actual_size",
shape=[2],
dtype="int32",
append_batch_size=False)
scale_tensor = fluid.layers.data(
name="scale_tensor",
shape=[1],
dtype="float32",
append_batch_size=False)
x = fluid.data(name="x", shape=[2, 3, 6, 6], dtype="float32")
dim = fluid.data(name="dim", shape=[1], dtype="int32")
shape_tensor = fluid.data(name="shape_tensor", shape=[2], dtype="int32")
actual_size = fluid.data(name="actual_size", shape=[2], dtype="int32")
scale_tensor = fluid.data(
name="scale_tensor", shape=[1], dtype="float32")
out1 = fluid.layers.resize_bilinear(x, out_shape=[12, 12])
out2 = fluid.layers.resize_bilinear(x, out_shape=[12, dim])
......@@ -513,14 +501,18 @@ class TestBilinearInterpOpAPI(OpTest):
x, out_shape=[4, 4], actual_shape=actual_size)
out5 = fluid.layers.resize_bilinear(x, scale=scale_tensor)
x_data = np.random.random((1, 3, 6, 6)).astype("float32")
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")
actual_size_data = np.array([12, 12]).astype("int32")
scale_data = np.array([2.0]).astype("float32")
if core.is_compiled_with_cuda():
place = core.CUDAPlace(0)
else:
place = core.CPUPlace()
exe = fluid.Executor(place)
exe.run(fluid.default_startup_program())
results = exe.run(fluid.default_main_program(),
feed={
"x": x_data,
......
......@@ -425,8 +425,8 @@ class TestNearestInterp_attr_tensor_Case3(TestNearestInterpOp_attr_tensor):
class TestNearestAPI(OpTest):
def test_case(self):
x = fluid.data(name="x", shape=[1, 3, 6, 6], dtype="float32")
y = fluid.data(name="y", shape=[1, 6, 6, 3], 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")
dim = fluid.data(name="dim", shape=[1], dtype="int32")
shape_tensor = fluid.data(name="shape_tensor", shape=[2], dtype="int32")
......@@ -442,14 +442,18 @@ class TestNearestAPI(OpTest):
x, out_shape=[4, 4], actual_shape=actual_size)
out5 = fluid.layers.resize_nearest(x, scale=scale_tensor)
x_data = np.random.random((1, 3, 6, 6)).astype("float32")
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")
actual_size_data = np.array([12, 12]).astype("int32")
scale_data = np.array([2.0]).astype("float32")
if core.is_compiled_with_cuda():
place = core.CUDAPlace(0)
else:
place = core.CPUPlace()
exe = fluid.Executor(place)
exe.run(fluid.default_startup_program())
results = exe.run(fluid.default_main_program(),
feed={
"x": x_data,
......
......@@ -570,25 +570,14 @@ class TestTrilinearInterp_attr_tensor_Case3(TestTrilinearInterpOp_attr_tensor):
class TestTrilinearInterpAPI(OpTest):
def test_case(self):
x = fluid.layers.data(name="x", shape=[3, 6, 9, 4], dtype="float32")
y = fluid.layers.data(name="y", shape=[6, 9, 4, 3], dtype="float32")
dim = fluid.layers.data(name="dim", shape=[1], dtype="int32")
shape_tensor = fluid.layers.data(
name="shape_tensor",
shape=[3],
dtype="int32",
append_batch_size=False)
actual_size = fluid.layers.data(
name="actual_size",
shape=[3],
dtype="int32",
append_batch_size=False)
scale_tensor = fluid.layers.data(
name="scale_tensor",
shape=[1],
dtype="float32",
append_batch_size=False)
x = fluid.data(name="x", shape=[2, 3, 6, 9, 4], dtype="float32")
y = fluid.data(name="y", shape=[2, 6, 9, 4, 3], dtype="float32")
dim = fluid.data(name="dim", shape=[1], dtype="int32")
shape_tensor = fluid.data(name="shape_tensor", shape=[3], dtype="int32")
actual_size = fluid.data(name="actual_size", shape=[3], dtype="int32")
scale_tensor = fluid.data(
name="scale_tensor", shape=[1], dtype="float32")
out1 = fluid.layers.resize_trilinear(
y, out_shape=[12, 18, 8], data_format='NDHWC')
......@@ -598,14 +587,18 @@ class TestTrilinearInterpAPI(OpTest):
x, out_shape=[4, 4, 8], actual_shape=actual_size)
out5 = fluid.layers.resize_trilinear(x, scale=scale_tensor)
x_data = np.random.random((1, 3, 6, 9, 4)).astype("float32")
x_data = np.random.random((2, 3, 6, 9, 4)).astype("float32")
dim_data = np.array([18]).astype("int32")
shape_data = np.array([12, 18, 8]).astype("int32")
actual_size_data = np.array([12, 18, 8]).astype("int32")
scale_data = np.array([2.0]).astype("float32")
if core.is_compiled_with_cuda():
place = core.CUDAPlace(0)
else:
place = core.CPUPlace()
exe = fluid.Executor(place)
exe.run(fluid.default_startup_program())
results = exe.run(fluid.default_main_program(),
feed={
"x": x_data,
......@@ -628,8 +621,7 @@ class TestTrilinearInterpAPI(OpTest):
class TestTrilinearInterpOpException(OpTest):
def test_exception(self):
input = fluid.layers.data(
name="input", shape=[3, 6, 9, 4], dtype="float32")
input = fluid.data(name="input", shape=[2, 3, 6, 9, 4], dtype="float32")
def attr_data_format():
# for 5-D input, data_format only can be NCDHW or NDHWC
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册