Skip to content

Commit 541ddf7

Browse files
committed
squash to one pr
1 parent 6e3d168 commit 541ddf7

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

python/paddle/fluid/framework.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,37 @@ def clone_variable(self, var):
10341034

10351035

10361036
class Program(object):
1037+
"""
1038+
Python Program. Beneath it is a ProgramDesc, which is used for
1039+
create c++ Program. A program is a self-contained programing
1040+
language like container. It has at least one Block, when the
1041+
control flow op like conditional_block, while_op is included,
1042+
it will contains nested block.
1043+
Please reference the framework.proto for details.
1044+
1045+
Notes: we have default_startup_program and default_main_program
1046+
by default, a pair of them will shared the parameters.
1047+
The default_startup_program only run once to initialize parameters,
1048+
default_main_program run in every minibatch and adjust the weights.
1049+
1050+
Args:
1051+
None
1052+
1053+
Returns:
1054+
Python Program
1055+
1056+
Examples:
1057+
.. code-block:: python
1058+
1059+
main_program = Program()
1060+
startup_program = Program()
1061+
with fluid.program_guard(main_program=main_program, startup_program=startup_program):
1062+
fluid.layers.data(name="x", shape=[-1, 784], dtype='float32')
1063+
fluid.layers.data(name="y", shape=[-1, 1], dtype='int32')
1064+
fluid.layers.fc(name="fc", shape=[10], dtype='float32', act="relu")
1065+
1066+
"""
1067+
10371068
def __init__(self):
10381069
self.desc = core.ProgramDesc()
10391070
self.blocks = [Block(self, 0)]

python/paddle/fluid/layers/metric.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,32 @@
2727

2828
def accuracy(input, label, k=1, correct=None, total=None):
2929
"""
30+
accuracy layer.
31+
Refer to the https://en.wikipedia.org/wiki/Precision_and_recall
32+
3033
This function computes the accuracy using the input and label.
31-
The output is the top k inputs and their indices.
34+
If the correct label occurs in top k predictions, then correct will increment by one.
35+
Note: the dtype of accuracy is determined by input. the input and label dtype can be different.
36+
37+
Args:
38+
input(Variable): The input of accuracy layer, which is the predictions of network.
39+
Carry LoD information is supported.
40+
label(Variable): The label of dataset.
41+
k(int): The top k predictions for each class will be checked.
42+
correct(Variable): The correct predictions count.
43+
total(Variable): The total entries count.
44+
45+
Returns:
46+
Variable: The correct rate.
47+
48+
Examples:
49+
.. code-block:: python
50+
51+
data = fluid.layers.data(name="data", shape=[-1, 32, 32], dtype="float32")
52+
label = fluid.layers.data(name="data", shape=[-1,1], dtype="int32")
53+
predict = fluid.layers.fc(input=data, size=10)
54+
acc = fluid.layers.accuracy(input=predict, label=label, k=5)
55+
3256
"""
3357
helper = LayerHelper("accuracy", **locals())
3458
topk_out, topk_indices = nn.topk(input, k=k)

0 commit comments

Comments
 (0)