From 728d5b3a5aa10ddcc955df0d0dae9cf5cfea8f64 Mon Sep 17 00:00:00 2001 From: wangzhen38 <41941775+wangzhen38@users.noreply.github.com> Date: Wed, 24 Aug 2022 20:09:05 +0800 Subject: [PATCH] [DOC FIX]fix code demo of auc (#45200) * [DOC FIX]fix code demo of auc * [doc fix] fix doc of auc --- python/paddle/fluid/layers/metric_op.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/python/paddle/fluid/layers/metric_op.py b/python/paddle/fluid/layers/metric_op.py index 7a4cd46dfc..f4bf01ce9e 100755 --- a/python/paddle/fluid/layers/metric_op.py +++ b/python/paddle/fluid/layers/metric_op.py @@ -164,7 +164,7 @@ def auc(input, batch_stat_pos, batch_stat_neg, stat_pos, stat_neg ] Data type is Tensor, supporting float32, float64. - Examples 1: + Examples: .. code-block:: python import paddle @@ -173,8 +173,8 @@ def auc(input, data = paddle.static.data(name="input", shape=[-1, 32,32], dtype="float32") label = paddle.static.data(name="label", shape=[-1], dtype="int") - fc_out = paddle.static.nn.fc(input=data, size=2) - predict = paddle.nn.functional.softmax(input=fc_out) + fc_out = paddle.static.nn.fc(x=data, size=2) + predict = paddle.nn.functional.softmax(x=fc_out) result=paddle.static.auc(input=predict, label=label) place = paddle.CPUPlace() @@ -186,19 +186,18 @@ def auc(input, output= exe.run(feed={"input": x,"label": y}, fetch_list=[result[0]]) print(output) - #[array([0.5])] - Examples 2: - .. code-block:: python - + + #you can learn the usage of ins_tag_weight by the following code. + ''' import paddle import numpy as np paddle.enable_static() data = paddle.static.data(name="input", shape=[-1, 32,32], dtype="float32") label = paddle.static.data(name="label", shape=[-1], dtype="int") - fc_out = paddle.static.nn.fc(input=data, size=2) - predict = paddle.nn.functional.softmax(input=fc_out) - ins_tag_weight = paddle.static.data(name='ins_tag', shape=[-1,16], lod_level=0, dtype='int64') + ins_tag_weight = paddle.static.data(name='ins_tag', shape=[-1,16], lod_level=0, dtype='float64') + fc_out = paddle.static.nn.fc(x=data, size=2) + predict = paddle.nn.functional.softmax(x=fc_out) result=paddle.static.auc(input=predict, label=label, ins_tag_weight=ins_tag_weight) place = paddle.CPUPlace() @@ -207,10 +206,12 @@ def auc(input, exe.run(paddle.static.default_startup_program()) x = np.random.rand(3,32,32).astype("float32") y = np.array([1,0,1]) - output= exe.run(feed={"input": x,"label": y}, + z = np.array([1,0,1]) + output= exe.run(feed={"input": x,"label": y, "ins_tag_weight":z}, fetch_list=[result[0]]) print(output) - #[array([0.5])] + ''' + """ helper = LayerHelper("auc", **locals()) -- GitLab