pytorch填充

Signature: F.pad(input, pad, mode=‘constant’, value=0)
Docstring:
Pads tensor.

Padding size:
The padding size by which to pad some dimensions of :attr:input
are described starting from the last dimension and moving forward.
:math:\left\lfloor\frac{\text{len(pad)}}{2}\right\rfloor dimensions
of input will be padded.
For example, to pad only the last dimension of the input tensor, then
:attr:pad has the form
:math:(\text{padding\_left}, \text{padding\_right});
to pad the last 2 dimensions of the input tensor, then use
:math:(\text{padding\_left}, \text{padding\_right},
:math:\text{padding\_top}, \text{padding\_bottom});
to pad the last 3 dimensions, use
:math:(\text{padding\_left}, \text{padding\_right},
:math:\text{padding\_top}, \text{padding\_bottom}
:math:\text{padding\_front}, \text{padding\_back}).

Padding mode:
See :class:torch.nn.ConstantPad2d, :class:torch.nn.ReflectionPad2d, and
:class:torch.nn.ReplicationPad2d for concrete examples on how each of the
padding modes works. Constant padding is implemented for arbitrary dimensions.
Replicate padding is implemented for padding the last 3 dimensions of 5D input
tensor, or the last 2 dimensions of 4D input tensor, or the last dimension of
3D input tensor. Reflect padding is only implemented for padding the last 2
dimensions of 4D input tensor, or the last dimension of 3D input tensor.

… include:: cuda_deterministic_backward.rst

Args:
input (Tensor): N-dimensional tensor
pad (tuple): m-elements tuple, where
:math:\frac{m}{2} \leq input dimensions and :math:m is even.
mode: 'constant', 'reflect', 'replicate' or 'circular'.
Default: 'constant'
value: fill value for 'constant' padding. Default: 0

Examples::

>>> t4d = torch.empty(3, 3, 4, 2)
>>> p1d = (1, 1) # pad last dim by 1 on each side
>>> out = F.pad(t4d, p1d, "constant", 0)  # effectively zero padding
>>> print(out.data.size())
torch.Size([3, 3, 4, 4])
>>> p2d = (1, 1, 2, 2) # pad last dim by (1, 1) and 2nd to last by (2, 2)
>>> out = F.pad(t4d, p2d, "constant", 0)
>>> print(out.data.size())
torch.Size([3, 3, 8, 4])
>>> t4d = torch.empty(3, 3, 4, 2)
>>> p3d = (0, 1, 2, 1, 3, 3) # pad by (0, 1), (2, 1), and (3, 3)
>>> out = F.pad(t4d, p3d, "constant", 0)
>>> print(out.data.size())
torch.Size([3, 9, 7, 3])

File: ~/anaconda3/lib/python3.6/site-packages/torch/nn/functional.py
Type: function

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值