@@ -389,7 +389,7 @@ def dynamic_lstm(input,
389
389
390
390
hidden_dim = 512
391
391
forward_proj = fluid.layers.fc(input=input_seq, size=hidden_dim * 4,
392
- act=None, bias_attr=None )
392
+ bias_attr=False )
393
393
forward, _ = fluid.layers.dynamic_lstm(
394
394
input=forward_proj, size=hidden_dim * 4, use_peepholes=False)
395
395
"""
@@ -1277,7 +1277,9 @@ def sequence_conv(input,
1277
1277
filter_size (int): the filter size (H and W).
1278
1278
filter_stride (int): stride of the filter.
1279
1279
padding (bool): if True, add paddings.
1280
- bias_attr (ParamAttr|None): attributes for bias
1280
+ bias_attr (ParamAttr): The parameter attribute for the bias of this layer.
1281
+ If it is set to False, no bias will be added to the output units.
1282
+ If it is set to None, the bias is initialized zero. Default: None.
1281
1283
param_attr (ParamAttr|None): attributes for parameter
1282
1284
act (str): the activation type
1283
1285
@@ -1308,7 +1310,7 @@ def sequence_conv(input,
1308
1310
return helper .append_activation (pre_act )
1309
1311
1310
1312
1311
- def sequence_softmax (input , param_attr = None , bias_attr = None , use_cudnn = False ):
1313
+ def sequence_softmax (input , use_cudnn = False ):
1312
1314
"""
1313
1315
This function computes the softmax activation among all time-steps for each
1314
1316
sequence. The dimension of each time-step should be 1. Thus, the shape of
@@ -1328,8 +1330,6 @@ def sequence_softmax(input, param_attr=None, bias_attr=None, use_cudnn=False):
1328
1330
1329
1331
Args:
1330
1332
input (Variable): The input variable which is a LoDTensor.
1331
- bias_attr (ParamAttr|None): attributes for bias
1332
- param_attr (ParamAttr|None): attributes for parameter
1333
1333
use_cudnn (bool): Use cudnn kernel or not, it is valid only when the cudnn \
1334
1334
library is installed. Default: False
1335
1335
@@ -1355,7 +1355,7 @@ def sequence_softmax(input, param_attr=None, bias_attr=None, use_cudnn=False):
1355
1355
return softmax_out
1356
1356
1357
1357
1358
- def softmax (input , param_attr = None , bias_attr = None , use_cudnn = True , name = None ):
1358
+ def softmax (input , use_cudnn = True , name = None ):
1359
1359
"""
1360
1360
The input of the softmax operator is a tensor of any rank. The output tensor
1361
1361
has the same shape as the input.
@@ -1382,8 +1382,6 @@ def softmax(input, param_attr=None, bias_attr=None, use_cudnn=True, name=None):
1382
1382
1383
1383
Args:
1384
1384
input (Variable): The input variable.
1385
- bias_attr (ParamAttr): attributes for bias
1386
- param_attr (ParamAttr): attributes for parameter
1387
1385
use_cudnn (bool): Use cudnn kernel or not, it is valid only when the cudnn \
1388
1386
library is installed.
1389
1387
@@ -1492,13 +1490,19 @@ def conv2d(input,
1492
1490
the first half of the filters is only connected to the first half
1493
1491
of the input channels, while the second half of the filters is only
1494
1492
connected to the second half of the input channels. Default: groups=1
1495
- param_attr (ParamAttr): The parameters to the Conv2d Layer. Default: None
1496
- bias_attr (ParamAttr): Bias parameter for the Conv2d layer. Default: None
1493
+ param_attr (ParamAttr): The parameter attribute for learnable parameters/weights
1494
+ of this layer. If it is set to None, the parameter is initialized with
1495
+ :math:`Normal(0.0, std)`, and the :math:`std` is :math:`(\\ frac{2.0 }{filter\_elem\_num})^{0.5}`.
1496
+ Default: None.
1497
+ bias_attr (ParamAttr): The parameter attribute for the bias of this layer.
1498
+ If it is set to False, no bias will be added to the output units.
1499
+ If it is set to None, the bias is initialized zero. Default: None.
1497
1500
use_cudnn (bool): Use cudnn kernel or not, it is valid only when the cudnn
1498
1501
library is installed. Default: True
1499
- act (str): Activation type. Default: None
1502
+ act (str): Activation type, if it is set to None, activation is not appended.
1503
+ Default: None
1500
1504
name (str|None): A name for this layer(optional). If set None, the layer
1501
- will be named automatically.
1505
+ will be named automatically. Default: None
1502
1506
1503
1507
Returns:
1504
1508
Variable: The tensor variable storing the convolution and \
@@ -1516,7 +1520,7 @@ def conv2d(input,
1516
1520
"""
1517
1521
1518
1522
num_channels = input .shape [1 ]
1519
-
1523
+ assert param_attr is not False , "param_attr should not be False here."
1520
1524
l_type = 'conv2d'
1521
1525
if (num_channels == groups and num_filters % num_channels == 0 and
1522
1526
not use_cudnn ):
@@ -1544,7 +1548,8 @@ def conv2d(input,
1544
1548
filter_shape = [num_filters , int (num_filter_channels )] + filter_size
1545
1549
1546
1550
def _get_default_param_initializer ():
1547
- std = (2.0 / (filter_size [0 ]** 2 * num_channels ))** 0.5
1551
+ filter_num_elem = filter_size [0 ] * filter_size [1 ] * num_channels
1552
+ std = (2.0 / (filter_num_elem ))** 0.5
1548
1553
return Normal (0.0 , std , 0 )
1549
1554
1550
1555
filter_param = helper .create_parameter (
@@ -1655,13 +1660,19 @@ def conv3d(input,
1655
1660
the first half of the filters is only connected to the first half
1656
1661
of the input channels, while the second half of the filters is only
1657
1662
connected to the second half of the input channels. Default: groups=1
1658
- param_attr (ParamAttr): The parameters to the Conv3d Layer. Default: None
1659
- bias_attr (ParamAttr): Bias parameter for the Conv3d layer. Default: None
1663
+ param_attr (ParamAttr): The parameter attribute for learnable parameters/weights
1664
+ of this layer. If it is set to None, the parameter is initialized with
1665
+ :math:`Normal(0.0, std)`, and the :math:`std` is :math:`(\\ frac{2.0 }{filter\_elem\_num})^{0.5}`.
1666
+ Default: None.
1667
+ bias_attr (ParamAttr): The parameter attribute for the bias of this layer.
1668
+ If it is set to False, no bias will be added to the output units.
1669
+ If it is set to None, the bias is initialized zero. Default: None.
1660
1670
use_cudnn (bool): Use cudnn kernel or not, it is valid only when the cudnn
1661
1671
library is installed. Default: True
1662
- act (str): Activation type. Default: None
1672
+ act (str): Activation type, if it is set to None, activation is not appended.
1673
+ Default: None.
1663
1674
name (str|None): A name for this layer(optional). If set None, the layer
1664
- will be named automatically.
1675
+ will be named automatically. Default: None.
1665
1676
1666
1677
Returns:
1667
1678
Variable: The tensor variable storing the convolution and \
@@ -1679,7 +1690,7 @@ def conv3d(input,
1679
1690
"""
1680
1691
1681
1692
l_type = 'conv3d'
1682
-
1693
+ assert param_attr is not False , "param_attr should not be False here."
1683
1694
helper = LayerHelper (l_type , ** locals ())
1684
1695
dtype = helper .input_dtype ()
1685
1696
@@ -1704,7 +1715,9 @@ def conv3d(input,
1704
1715
filter_shape = [num_filters , num_filter_channels ] + filter_size
1705
1716
1706
1717
def _get_default_param_initializer ():
1707
- std = (2.0 / (filter_size [0 ]** 3 * num_channels ))** 0.5
1718
+ filter_elem_num = filter_size [0 ] * filter_size [1 ] * filter_size [
1719
+ 2 ] * num_channels
1720
+ std = (2.0 / filter_elem_num )** 0.5
1708
1721
return Normal (0.0 , std , 0 )
1709
1722
1710
1723
filter_param = helper .create_parameter (
@@ -2396,15 +2409,19 @@ def conv2d_transpose(input,
2396
2409
when group=2, the first half of the filters is only connected to the
2397
2410
first half of the input channels, while the second half of the
2398
2411
filters is only connected to the second half of the input channels.
2399
- Default: groups=1
2400
- param_attr(ParamAttr): The parameters to the Conv2d_transpose Layer.
2401
- Default: None
2402
- bias_attr(ParamAttr): Bias parameter for the Conv2d layer. Default: None
2412
+ Default: groups = 1.
2413
+ param_attr (ParamAttr): The parameter attribute for learnable parameters/weights
2414
+ of this layer. If it is set to None, the parameter is initialized with
2415
+ Xavier. Default: None.
2416
+ bias_attr (ParamAttr): The parameter attribute for the bias of this layer.
2417
+ If it is set to False, no bias will be added to the output units.
2418
+ If it is set to None, the bias is initialized zero. Default: None.
2403
2419
use_cudnn(bool): Use cudnn kernel or not, it is valid only when the cudnn
2404
- library is installed. Default: True
2405
- act(str): Activation type. Default: None
2420
+ library is installed. Default: True.
2421
+ act (str): Activation type, if it is set to None, activation is not appended.
2422
+ Default: None.
2406
2423
name(str|None): A name for this layer(optional). If set None, the layer
2407
- will be named automatically.
2424
+ will be named automatically. Default: True.
2408
2425
2409
2426
Returns:
2410
2427
Variable: The tensor variable storing the convolution transpose result.
@@ -2455,6 +2472,7 @@ def conv2d_transpose(input,
2455
2472
else :
2456
2473
filter_size = utils .convert_to_list (filter_size , 2 ,
2457
2474
'conv2d_transpose.filter_size' )
2475
+
2458
2476
if output_size is None :
2459
2477
output_size = []
2460
2478
elif isinstance (output_size , list ) or isinstance (output_size , int ):
@@ -2464,6 +2482,7 @@ def conv2d_transpose(input,
2464
2482
padding = utils .convert_to_list (padding , 2 , 'padding' )
2465
2483
groups = 1 if groups is None else groups
2466
2484
filter_shape = [input_channel , num_filters // groups ] + filter_size
2485
+
2467
2486
img_filter = helper .create_parameter (
2468
2487
dtype = input .dtype , shape = filter_shape , attr = helper .param_attr )
2469
2488
@@ -2576,12 +2595,16 @@ def conv3d_transpose(input,
2576
2595
first half of the input channels, while the second half of the
2577
2596
filters is only connected to the second half of the input channels.
2578
2597
Default: groups=1
2579
- param_attr(ParamAttr): The parameters to the Conv3d_transpose Layer.
2580
- Default: None
2581
- bias_attr(ParamAttr): Bias parameter for the Conv3d layer. Default: None
2598
+ param_attr (ParamAttr): The parameter attribute for learnable parameters/weights
2599
+ of this layer. If it is set to None, the parameter is initialized with
2600
+ Xavier. Default: None.
2601
+ bias_attr (ParamAttr): The parameter attribute for the bias of this layer.
2602
+ If it is set to False, no bias will be added to the output units.
2603
+ If it is set to None, the bias is initialized zero. Default: None.
2582
2604
use_cudnn(bool): Use cudnn kernel or not, it is valid only when the cudnn
2583
2605
library is installed. Default: True
2584
- act(str): Activation type. Default: None
2606
+ act (str): Activation type, if it is set to None, activation is not appended.
2607
+ Default: None.
2585
2608
name(str|None): A name for this layer(optional). If set None, the layer
2586
2609
will be named automatically.
2587
2610
0 commit comments