From 674327a4b179286bbe7db2e2b96f8e59c0120562 Mon Sep 17 00:00:00 2001 From: yuyang18 Date: Wed, 13 Jun 2018 18:06:59 +0800 Subject: [PATCH] Polish several API --- paddle/fluid/operators/activation_op.cc | 3 +- python/paddle/fluid/layers/detection.py | 38 ++++++++++++------------- python/paddle/fluid/layers/ops.py | 28 ++++++++++++++++-- 3 files changed, 46 insertions(+), 23 deletions(-) diff --git a/paddle/fluid/operators/activation_op.cc b/paddle/fluid/operators/activation_op.cc index 5e2fa566777..89bb1e2d4fd 100644 --- a/paddle/fluid/operators/activation_op.cc +++ b/paddle/fluid/operators/activation_op.cc @@ -271,7 +271,8 @@ class HardShrinkOpMaker : public framework::OpProtoAndCheckerMaker { void Make() override { AddInput("X", "Input of HardShrink operator"); AddOutput("Out", "Output of HardShrink operator"); - AddAttr("threshold", "The value of threshold for HardShrink") + AddAttr("threshold", + "The value of threshold for HardShrink. [default: 0.5]") .SetDefault(0.5f); AddComment(R"DOC( HardShrink Activation Operator. diff --git a/python/paddle/fluid/layers/detection.py b/python/paddle/fluid/layers/detection.py index 1e8dfbe5218..d5f7e420dd1 100644 --- a/python/paddle/fluid/layers/detection.py +++ b/python/paddle/fluid/layers/detection.py @@ -403,25 +403,6 @@ def ssd_loss(location, 5.3 Compute the overall weighted loss. - >>> import paddle.fluid.layers as layers - >>> pb = layers.data( - >>> name='prior_box', - >>> shape=[10, 4], - >>> append_batch_size=False, - >>> dtype='float32') - >>> pbv = layers.data( - >>> name='prior_box_var', - >>> shape=[10, 4], - >>> append_batch_size=False, - >>> dtype='float32') - >>> loc = layers.data(name='target_box', shape=[10, 4], dtype='float32') - >>> scores = layers.data(name='scores', shape=[10, 21], dtype='float32') - >>> gt_box = layers.data( - >>> name='gt_box', shape=[4], lod_level=1, dtype='float32') - >>> gt_label = layers.data( - >>> name='gt_label', shape=[1], lod_level=1, dtype='float32') - >>> loss = layers.ssd_loss(loc, scores, gt_box, gt_label, pb, pbv) - Args: location (Variable): The location predictions are a 3D Tensor with shape [N, Np, 4], N is the batch size, Np is total number of @@ -465,6 +446,25 @@ def ssd_loss(location, Raises: ValueError: If mining_type is 'hard_example', now only support mining \ type of `max_negative`. + + Examples: + >>> pb = fluid.layers.data( + >>> name='prior_box', + >>> shape=[10, 4], + >>> append_batch_size=False, + >>> dtype='float32') + >>> pbv = fluid.layers.data( + >>> name='prior_box_var', + >>> shape=[10, 4], + >>> append_batch_size=False, + >>> dtype='float32') + >>> loc = fluid.layers.data(name='target_box', shape=[10, 4], dtype='float32') + >>> scores = fluid.layers.data(name='scores', shape=[10, 21], dtype='float32') + >>> gt_box = fluid.layers.data( + >>> name='gt_box', shape=[4], lod_level=1, dtype='float32') + >>> gt_label = fluid.layers.data( + >>> name='gt_label', shape=[1], lod_level=1, dtype='float32') + >>> loss = fluid.layers.ssd_loss(loc, scores, gt_box, gt_label, pb, pbv) """ helper = LayerHelper('ssd_loss', **locals()) diff --git a/python/paddle/fluid/layers/ops.py b/python/paddle/fluid/layers/ops.py index 46c6fd686e0..f0abd3089dc 100644 --- a/python/paddle/fluid/layers/ops.py +++ b/python/paddle/fluid/layers/ops.py @@ -40,7 +40,6 @@ __activations__ = [ 'relu6', 'pow', 'stanh', - 'hard_shrink', 'thresholded_relu', 'hard_sigmoid', 'swish', @@ -92,9 +91,32 @@ def uniform_random(shape, dtype=None, min=None, max=None, seed=None): kwargs[name] = val return _uniform_random_(**kwargs) -uniform_random.__doc__ = _uniform_random_.__doc__ + "\n"\ -+""" + +uniform_random.__doc__ = _uniform_random_.__doc__ + "\n" \ + + """ Examples: >>> result = fluid.layers.uniform_random(shape=[32, 784]) """ + +__all__ += ['hard_shrink'] + +_hard_shrink_ = generate_layer_fn('hard_shrink') + + +def hard_shrink(x, threshold=None): + kwargs = dict() + for name in locals(): + val = locals()[name] + if val is not None: + kwargs[name] = val + return _hard_shrink_(**kwargs) + + +hard_shrink.__doc__ = _hard_shrink_.__doc__ + "\n" \ + + """ +Examples: + + >>> data = fluid.layers.data(name="input", shape=[784]) + >>> result = fluid.layers.hard_shrink(x=data, threshold=0.3) +""" -- GitLab