提交 40405d13 编写于 作者: D dengkaipeng

add doc and API.spec. test=develop

上级 e90e0bdf
...@@ -220,6 +220,7 @@ paddle.fluid.layers.py_func (ArgSpec(args=['func', 'x', 'out', 'backward_func', ...@@ -220,6 +220,7 @@ paddle.fluid.layers.py_func (ArgSpec(args=['func', 'x', 'out', 'backward_func',
paddle.fluid.layers.psroi_pool (ArgSpec(args=['input', 'rois', 'output_channels', 'spatial_scale', 'pooled_height', 'pooled_width', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '1546136806fef5c08f6918544bd9151d')) paddle.fluid.layers.psroi_pool (ArgSpec(args=['input', 'rois', 'output_channels', 'spatial_scale', 'pooled_height', 'pooled_width', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '1546136806fef5c08f6918544bd9151d'))
paddle.fluid.layers.teacher_student_sigmoid_loss (ArgSpec(args=['input', 'label', 'soft_max_up_bound', 'soft_max_lower_bound'], varargs=None, keywords=None, defaults=(15.0, -15.0)), ('document', '2f6ff96864054a31aa4bb659c6722c99')) paddle.fluid.layers.teacher_student_sigmoid_loss (ArgSpec(args=['input', 'label', 'soft_max_up_bound', 'soft_max_lower_bound'], varargs=None, keywords=None, defaults=(15.0, -15.0)), ('document', '2f6ff96864054a31aa4bb659c6722c99'))
paddle.fluid.layers.huber_loss (ArgSpec(args=['input', 'label', 'delta'], varargs=None, keywords=None, defaults=None), ('document', '431a4301c35032166ec029f7432c80a7')) paddle.fluid.layers.huber_loss (ArgSpec(args=['input', 'label', 'delta'], varargs=None, keywords=None, defaults=None), ('document', '431a4301c35032166ec029f7432c80a7'))
paddle.fluid.layers.kldiv_loss (ArgSpec(args=['x', 'target', 'reduction', 'name'], varargs=None, keywords=None, defaults=('mean', None)), ('document', '26e3842d408b0af4653433ce1591a473449a78f6'))
paddle.fluid.layers.tree_conv (ArgSpec(args=['nodes_vector', 'edge_set', 'output_size', 'num_filters', 'max_depth', 'act', 'param_attr', 'bias_attr', 'name'], varargs=None, keywords=None, defaults=(1, 2, 'tanh', None, None, None)), ('document', '34ea12ac9f10a65dccbc50100d12e607')) paddle.fluid.layers.tree_conv (ArgSpec(args=['nodes_vector', 'edge_set', 'output_size', 'num_filters', 'max_depth', 'act', 'param_attr', 'bias_attr', 'name'], varargs=None, keywords=None, defaults=(1, 2, 'tanh', None, None, None)), ('document', '34ea12ac9f10a65dccbc50100d12e607'))
paddle.fluid.layers.data (ArgSpec(args=['name', 'shape', 'append_batch_size', 'dtype', 'lod_level', 'type', 'stop_gradient'], varargs=None, keywords=None, defaults=(True, 'float32', 0, VarType.LOD_TENSOR, True)), ('document', '33bbd42027d872b3818b3d64ec52e139')) paddle.fluid.layers.data (ArgSpec(args=['name', 'shape', 'append_batch_size', 'dtype', 'lod_level', 'type', 'stop_gradient'], varargs=None, keywords=None, defaults=(True, 'float32', 0, VarType.LOD_TENSOR, True)), ('document', '33bbd42027d872b3818b3d64ec52e139'))
paddle.fluid.layers.open_files (ArgSpec(args=['filenames', 'shapes', 'lod_levels', 'dtypes', 'thread_num', 'buffer_size', 'pass_num', 'is_test'], varargs=None, keywords=None, defaults=(None, None, 1, None)), ('document', 'b1ae2e1cc0750e58726374061ea90ecc')) paddle.fluid.layers.open_files (ArgSpec(args=['filenames', 'shapes', 'lod_levels', 'dtypes', 'thread_num', 'buffer_size', 'pass_num', 'is_test'], varargs=None, keywords=None, defaults=(None, None, 1, None)), ('document', 'b1ae2e1cc0750e58726374061ea90ecc'))
......
...@@ -89,6 +89,24 @@ class KLDivLossOpMaker : public framework::OpProtoAndCheckerMaker { ...@@ -89,6 +89,24 @@ class KLDivLossOpMaker : public framework::OpProtoAndCheckerMaker {
This operator calculates the Kullback-Leibler divergence loss This operator calculates the Kullback-Leibler divergence loss
between Input(X) and Input(Target). between Input(X) and Input(Target).
KL divergence loss calculates as follows:
$$l(x, y) = y * (\log y - x)$$
While :attr:`reduction` is :attr:`none`, output loss is in
same shape with Input(X), loss in each point is calculated
seperately and no reduction applied.
While :attr:`reduction` is :attr:`mean`, output loss in in
shape of [1] and loss value is the mean value of all losses.
While :attr:`reduction` is :attr:`sum`, output loss in in
shape of [1] and loss value is the sum value of all losses.
While :attr:`reduction` is :attr:`batchmean`, output loss in
in shape of [1] and loss value is the sum value of all losses
divided by batch size.
)DOC"); )DOC");
} }
}; };
......
...@@ -186,6 +186,7 @@ __all__ = [ ...@@ -186,6 +186,7 @@ __all__ = [
'psroi_pool', 'psroi_pool',
'teacher_student_sigmoid_loss', 'teacher_student_sigmoid_loss',
'huber_loss', 'huber_loss',
'kldiv_loss',
'tree_conv', 'tree_conv',
] ]
...@@ -10588,6 +10589,38 @@ def huber_loss(input, label, delta): ...@@ -10588,6 +10589,38 @@ def huber_loss(input, label, delta):
return out return out
@templatedoc()
def kldiv_loss(x, target, reduction='mean', name=None):
"""
${comment}
Args:
x (Variable): ${x_comment}
target (Variable): ${target_comment}
reduction (Variable): ${reduction_comment}
name (str, default None): The name of this layer.
Returns:
kldiv\_loss (Variable): The KL divergence loss.
Examples:
.. code-block:: python
x = fluid.layers.data(name='x', shape=[4,2,2], dtype='float32')
target = fluid.layers.data(name='target', shape=[4,2,2], dtype='float32')
loss = fluid.layers.kldiv_loss(x=x, target=target, reduction='batchmean')
"""
helper = LayerHelper('kldiv_loss', **locals())
loss = helper.create_variable_for_type_inference(dtype=x.dtype)
helper.append_op(
type='kldiv_loss',
inputs={'X': x,
'Target': target},
outputs={'Loss': loss},
attrs={'reduction': reduction})
return loss
@templatedoc() @templatedoc()
def tree_conv(nodes_vector, def tree_conv(nodes_vector,
edge_set, edge_set,
......
...@@ -1046,6 +1046,15 @@ class TestBook(unittest.TestCase): ...@@ -1046,6 +1046,15 @@ class TestBook(unittest.TestCase):
out = layers.spectral_norm(weight, dim=1, power_iters=1) out = layers.spectral_norm(weight, dim=1, power_iters=1)
self.assertIsNotNone(out) self.assertIsNotNone(out)
def test_kldiv_loss(self):
program = Program()
with program_guard(program):
x = layers.data(name='x', shape=[32, 128, 128], dtype="float32")
target = layers.data(
name='target', shape=[32, 128, 128], dtype="float32")
loss = layers.kldiv_loss(x=x, target=target, reduction='batchmean')
self.assertIsNotNone(loss)
print(str(program)) print(str(program))
def test_shuffle_channel(self): def test_shuffle_channel(self):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册