|
|
|
@ -608,5 +608,20 @@ class TestBatchNormOpError(unittest.TestCase):
|
|
|
|
|
self.assertRaises(TypeError, fluid.layers.batch_norm, x2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestDygraphBatchNormAPIError(unittest.TestCase):
|
|
|
|
|
def test_errors(self):
|
|
|
|
|
with program_guard(Program(), Program()):
|
|
|
|
|
batch_norm = fluid.dygraph.BatchNorm(10)
|
|
|
|
|
# the input of BatchNorm must be Variable.
|
|
|
|
|
x1 = fluid.create_lod_tensor(
|
|
|
|
|
np.array([-1, 3, 5, 5]), [[1, 1, 1, 1]], fluid.CPUPlace())
|
|
|
|
|
self.assertRaises(TypeError, batch_norm, x1)
|
|
|
|
|
|
|
|
|
|
# the input dtype of BatchNorm must be float16 or float32 or float64
|
|
|
|
|
# float16 only can be set on GPU place
|
|
|
|
|
x2 = fluid.layers.data(name='x2', shape=[3, 4, 5, 6], dtype="int32")
|
|
|
|
|
self.assertRaises(TypeError, batch_norm, x2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
unittest.main()
|
|
|
|
|