Skip to content

Commit 674327a

Browse files
committed
Polish several API
1 parent ce6394e commit 674327a

File tree

3 files changed

+46
-23
lines changed

3 files changed

+46
-23
lines changed

paddle/fluid/operators/activation_op.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,8 @@ class HardShrinkOpMaker : public framework::OpProtoAndCheckerMaker {
271271
void Make() override {
272272
AddInput("X", "Input of HardShrink operator");
273273
AddOutput("Out", "Output of HardShrink operator");
274-
AddAttr<float>("threshold", "The value of threshold for HardShrink")
274+
AddAttr<float>("threshold",
275+
"The value of threshold for HardShrink. [default: 0.5]")
275276
.SetDefault(0.5f);
276277
AddComment(R"DOC(
277278
HardShrink Activation Operator.

python/paddle/fluid/layers/detection.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -403,25 +403,6 @@ def ssd_loss(location,
403403
404404
5.3 Compute the overall weighted loss.
405405
406-
>>> import paddle.fluid.layers as layers
407-
>>> pb = layers.data(
408-
>>> name='prior_box',
409-
>>> shape=[10, 4],
410-
>>> append_batch_size=False,
411-
>>> dtype='float32')
412-
>>> pbv = layers.data(
413-
>>> name='prior_box_var',
414-
>>> shape=[10, 4],
415-
>>> append_batch_size=False,
416-
>>> dtype='float32')
417-
>>> loc = layers.data(name='target_box', shape=[10, 4], dtype='float32')
418-
>>> scores = layers.data(name='scores', shape=[10, 21], dtype='float32')
419-
>>> gt_box = layers.data(
420-
>>> name='gt_box', shape=[4], lod_level=1, dtype='float32')
421-
>>> gt_label = layers.data(
422-
>>> name='gt_label', shape=[1], lod_level=1, dtype='float32')
423-
>>> loss = layers.ssd_loss(loc, scores, gt_box, gt_label, pb, pbv)
424-
425406
Args:
426407
location (Variable): The location predictions are a 3D Tensor with
427408
shape [N, Np, 4], N is the batch size, Np is total number of
@@ -465,6 +446,25 @@ def ssd_loss(location,
465446
Raises:
466447
ValueError: If mining_type is 'hard_example', now only support mining \
467448
type of `max_negative`.
449+
450+
Examples:
451+
>>> pb = fluid.layers.data(
452+
>>> name='prior_box',
453+
>>> shape=[10, 4],
454+
>>> append_batch_size=False,
455+
>>> dtype='float32')
456+
>>> pbv = fluid.layers.data(
457+
>>> name='prior_box_var',
458+
>>> shape=[10, 4],
459+
>>> append_batch_size=False,
460+
>>> dtype='float32')
461+
>>> loc = fluid.layers.data(name='target_box', shape=[10, 4], dtype='float32')
462+
>>> scores = fluid.layers.data(name='scores', shape=[10, 21], dtype='float32')
463+
>>> gt_box = fluid.layers.data(
464+
>>> name='gt_box', shape=[4], lod_level=1, dtype='float32')
465+
>>> gt_label = fluid.layers.data(
466+
>>> name='gt_label', shape=[1], lod_level=1, dtype='float32')
467+
>>> loss = fluid.layers.ssd_loss(loc, scores, gt_box, gt_label, pb, pbv)
468468
"""
469469

470470
helper = LayerHelper('ssd_loss', **locals())

python/paddle/fluid/layers/ops.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
'relu6',
4141
'pow',
4242
'stanh',
43-
'hard_shrink',
4443
'thresholded_relu',
4544
'hard_sigmoid',
4645
'swish',
@@ -92,9 +91,32 @@ def uniform_random(shape, dtype=None, min=None, max=None, seed=None):
9291
kwargs[name] = val
9392
return _uniform_random_(**kwargs)
9493

95-
uniform_random.__doc__ = _uniform_random_.__doc__ + "\n"\
96-
+"""
94+
95+
uniform_random.__doc__ = _uniform_random_.__doc__ + "\n" \
96+
+ """
9797
Examples:
9898
9999
>>> result = fluid.layers.uniform_random(shape=[32, 784])
100100
"""
101+
102+
__all__ += ['hard_shrink']
103+
104+
_hard_shrink_ = generate_layer_fn('hard_shrink')
105+
106+
107+
def hard_shrink(x, threshold=None):
108+
kwargs = dict()
109+
for name in locals():
110+
val = locals()[name]
111+
if val is not None:
112+
kwargs[name] = val
113+
return _hard_shrink_(**kwargs)
114+
115+
116+
hard_shrink.__doc__ = _hard_shrink_.__doc__ + "\n" \
117+
+ """
118+
Examples:
119+
120+
>>> data = fluid.layers.data(name="input", shape=[784])
121+
>>> result = fluid.layers.hard_shrink(x=data, threshold=0.3)
122+
"""

0 commit comments

Comments
 (0)