From 5fdec3ed35696fcd16594e0e6e1b319391f7a75b Mon Sep 17 00:00:00 2001 From: Kaipeng Deng Date: Tue, 18 Aug 2020 19:43:56 +0800 Subject: [PATCH] fix test_metrics accuracy. test=develop (#26358) --- python/paddle/incubate/hapi/tests/test_metrics.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/paddle/incubate/hapi/tests/test_metrics.py b/python/paddle/incubate/hapi/tests/test_metrics.py index 3d25a275d5f..19c94b73f61 100644 --- a/python/paddle/incubate/hapi/tests/test_metrics.py +++ b/python/paddle/incubate/hapi/tests/test_metrics.py @@ -40,7 +40,8 @@ def accuracy(pred, label, topk=(1, )): def convert_to_one_hot(y, C): - oh = np.random.random((y.shape[0], C)).astype('float32') * .5 + oh = np.random.choice(np.arange(C), C, replace=False).astype('float32') / C + oh = np.tile(oh[np.newaxis, :], (y.shape[0], 1)) for i in range(y.shape[0]): oh[i, int(y[i])] = 1. return oh -- GitLab