未验证 提交 6da552a2 编写于 作者: Z zhulei 提交者: GitHub

Update initializer examples of Bilinear (#27709)

上级 7ecbc465
...@@ -729,31 +729,32 @@ class BilinearInitializer(Initializer): ...@@ -729,31 +729,32 @@ class BilinearInitializer(Initializer):
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
import math import math
import paddle
import paddle.nn as nn
from paddle.regularizer import L2Decay
factor = 2 factor = 2
C = 2 C = 2
B = 8 B = 8
H = W = 32 H = W = 32
w_attr = fluid.param_attr.ParamAttr( w_attr = paddle.ParamAttr(learning_rate=0.,
learning_rate=0., regularizer=L2Decay(0.),
regularizer=fluid.regularizer.L2Decay(0.), initializer=nn.initializer.Bilinear())
initializer=fluid.initializer.Bilinear()) data = paddle.rand([B, 3, H, W], dtype='float32')
x = fluid.data(name="data", shape=[B, 3, H, W], conv_up = nn.ConvTranspose2d(3,
dtype="float32") out_channels=C,
conv_up = fluid.layers.conv2d_transpose( kernel_size=2 * factor - factor % 2,
input=x, padding=int(
num_filters=C, math.ceil((factor - 1) / 2.)),
output_size=None, stride=factor,
filter_size=2 * factor - factor % 2, weight_attr=w_attr,
padding=int(math.ceil((factor - 1) / 2.)), bias_attr=False)
stride=factor, x = conv_up(data)
groups=C,
param_attr=w_attr, Where, `out_channels=C` and `groups=C` means this is channel-wise transposed
bias_attr=False) convolution. The filter shape will be (C, 1, K, K) where K is `kernel_size`,
Where, `num_filters=C` and `groups=C` means this is channel-wise transposed
convolution. The filter shape will be (C, 1, K, K) where K is `filer_size`,
This initializer will set a (K, K) interpolation kernel for every channel This initializer will set a (K, K) interpolation kernel for every channel
of the filter identically. The resulting shape of the output feature map of the filter identically. The resulting shape of the output feature map
will be (B, C, factor * H, factor * W). Note that the learning rate and the will be (B, C, factor * H, factor * W). Note that the learning rate and the
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册