From c61027e8f95d4ba25c90172ab43f28b649bcf4df Mon Sep 17 00:00:00 2001 From: HydrogenSulfate <490868991@qq.com> Date: Sun, 15 Aug 2021 21:06:10 +0800 Subject: [PATCH] Update test_cross_entropy_loss.py --- .../unittests/test_cross_entropy_loss.py | 66 ------------------- 1 file changed, 66 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_cross_entropy_loss.py b/python/paddle/fluid/tests/unittests/test_cross_entropy_loss.py index 689515511e..3ed8a69475 100644 --- a/python/paddle/fluid/tests/unittests/test_cross_entropy_loss.py +++ b/python/paddle/fluid/tests/unittests/test_cross_entropy_loss.py @@ -1564,72 +1564,6 @@ class TestCrossEntropyFAPIError(unittest.TestCase): self.assertRaises(ValueError, static_test_WeightLength_NotEqual) - def static_test_LabelValue_ExceedMax(): - input_np = np.random.random([2, 4]).astype(self.dtype) - label_np = np.random.randint(0, 4, size=(2)).astype(np.int64) - label_np[0] = 255 - weight_np = np.random.random([4]).astype(self.dtype) #shape:C - paddle.enable_static() - prog = fluid.Program() - startup_prog = fluid.Program() - place = fluid.CUDAPlace(0) if fluid.core.is_compiled_with_cuda( - ) else fluid.CPUPlace() - with fluid.program_guard(prog, startup_prog): - input = fluid.data( - name='input', shape=[2, 4], dtype=self.dtype) - label = fluid.data(name='label', shape=[2], dtype='int64') - weight = fluid.data( - name='weight', shape=[4], - dtype=self.dtype) #weight for each class - cross_entropy_loss = paddle.nn.loss.CrossEntropyLoss( - weight=weight) - ret = cross_entropy_loss(input, label) - - exe = fluid.Executor(place) - static_ret = exe.run(prog, - feed={ - 'input': input_np, - 'label': label_np, - "weight": weight_np - }, - fetch_list=[ret]) - self.assertIsNotNone(static_ret) - - self.assertRaises(ValueError, static_test_LabelValue_ExceedMax) - - def static_test_LabelValue_ExceedMin(): - input_np = np.random.random([2, 4]).astype(self.dtype) - label_np = np.random.randint(0, 4, size=(2)).astype(np.int64) - label_np[0] = -1 - weight_np = np.random.random([4]).astype(self.dtype) #shape:C - paddle.enable_static() - prog = fluid.Program() - startup_prog = fluid.Program() - place = fluid.CUDAPlace(0) if fluid.core.is_compiled_with_cuda( - ) else fluid.CPUPlace() - with fluid.program_guard(prog, startup_prog): - input = fluid.data( - name='input', shape=[2, 4], dtype=self.dtype) - label = fluid.data(name='label', shape=[2], dtype='int64') - weight = fluid.data( - name='weight', shape=[4], - dtype=self.dtype) #weight for each class - cross_entropy_loss = paddle.nn.loss.CrossEntropyLoss( - weight=weight) - ret = cross_entropy_loss(input, label) - - exe = fluid.Executor(place) - static_ret = exe.run(prog, - feed={ - 'input': input_np, - 'label': label_np, - "weight": weight_np - }, - fetch_list=[ret]) - self.assertIsNotNone(static_ret) - - self.assertRaises(ValueError, static_test_LabelValue_ExceedMin) - if __name__ == "__main__": unittest.main() -- GitLab