Skip to content

Commit

Permalink
Add more unitest for grid sample API
Browse files Browse the repository at this point in the history
test=develop
  • Loading branch information
wanghaoshuang committed Aug 24, 2020
1 parent de31410 commit dd46209
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions python/paddle/fluid/tests/unittests/test_affine_grid_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@ def __init__(self,
theta_shape=(20, 2, 3),
output_shape=[20, 2, 5, 7],
align_corners=True,
dtype="float32"):
dtype="float32",
invalid_theta=False,
variable_output_shape=False):
super(AffineGridTestCase, self).__init__(methodName)

self.theta_shape = theta_shape
self.output_shape = output_shape
self.align_corners = align_corners
self.dtype = dtype
self.invalid_theta = invalid_theta
self.variable_output_shape = variable_output_shape

def setUp(self):
self.theta = np.random.randn(*(self.theta_shape)).astype(self.dtype)
Expand Down Expand Up @@ -70,9 +74,12 @@ def functional(self, place):
return y_np

def paddle_dygraph_layer(self):
theta_var = dg.to_variable(self.theta)
theta_var = dg.to_variable(
self.theta) if not self.invalid_theta else "invalid"
output_shape = dg.to_variable(
self.output_shape) if variable_output_shape else self.output_shape
y_var = F.affine_grid(
theta_var, self.output_shape, align_corners=self.align_corners)
theta_var, output_shape, align_corners=self.align_corners)
y_np = y_var.numpy()
return y_np

Expand Down Expand Up @@ -108,6 +115,9 @@ def add_cases(suite):
suite.addTest(AffineGridTestCase(methodName='runTest', align_corners=True))

suite.addTest(AffineGridTestCase(methodName='runTest', align_corners=False))
suite.addTest(
AffineGridTestCase(
methodName='runTest', variable_output_shape=True))

suite.addTest(
AffineGridTestCase(
Expand All @@ -121,6 +131,10 @@ def add_error_cases(suite):
suite.addTest(
AffineGridErrorTestCase(
methodName='runTest', output_shape="not_valid"))
suite.addTest(
AffineGridErrorTestCase(
methodName='runTest',
invalid_theta=True)) # to test theta not variable error checking


def load_tests(loader, standard_tests, pattern):
Expand Down

0 comments on commit dd46209

Please sign in to comment.