Loading...
Loading...
Compare original and translation side by side
torch/_tensor_docs.pytorch/nn/functional.pytorch/_tensor_docs.pytorch/nn/functional.pyr"""..."""r"""..."""r"""function_name(param1, param2, *, kwarg1=default1, kwarg2=default2) -> ReturnType*r"""function_name(param1, param2, *, kwarg1=default1, kwarg2=default2) -> ReturnType*r"""conv2d(input, weight, bias=None, stride=1, padding=0, dilation=1, groups=1) -> Tensor
Applies a 2D convolution over an input image composed of several input
planes.r"""conv2d(input, weight, bias=None, stride=1, padding=0, dilation=1, groups=1) -> Tensor
对由多个输入平面组成的输入图像应用二维卷积。.. math::
\text{Softmax}(x_{i}) = \frac{\exp(x_i)}{\sum_j \exp(x_j)}:math:\.. math::
\text{Softmax}(x_{i}) = \frac{\exp(x_i)}{\sum_j \exp(x_j)}:math:\:class:\:func:\:meth:\:attr:\~Conv2dtorch.nn.Conv2dSee :class:`~torch.nn.Conv2d` for details and output shape.:class:\:func:\:meth:\:attr:\~Conv2dtorch.nn.Conv2d详情和输出形状请参见:class:`~torch.nn.Conv2d`。.. note::
This function doesn't work directly with NLLLoss,
which expects the Log to be computed between the Softmax and itself.
Use log_softmax instead (it's faster and has better numerical properties).
.. warning::
:func:`new_tensor` always copies :attr:`data`. If you have a Tensor
``data`` and want to avoid a copy, use :func:`torch.Tensor.requires_grad_`
or :func:`torch.Tensor.detach`... note::
该函数无法直接与NLLLoss配合使用,NLLLoss要求在Softmax和自身之间计算Log。
请改用log_softmax(速度更快,数值特性更好)。
.. warning::
:func:`new_tensor`始终会复制:attr:`data`。如果您已有一个Tensor
``data``且想避免复制,请使用:func:`torch.Tensor.requires_grad_`
或:func:`torch.Tensor.detach`。Args:
input (Tensor): input tensor of shape :math:`(\text{minibatch} , \text{in\_channels} , iH , iW)`
weight (Tensor): filters of shape :math:`(\text{out\_channels} , kH , kW)`
bias (Tensor, optional): optional bias tensor of shape :math:`(\text{out\_channels})`. Default: ``None``
stride (int or tuple): the stride of the convolving kernel. Can be a single number or a
tuple `(sH, sW)`. Default: 1(Type)(Type, optional)value``None``Args:
input (Tensor): 形状为:math:`(\text{minibatch} , \text{in\_channels} , iH , iW)`的输入张量
weight (Tensor): 形状为:math:`(\text{out\_channels} , kH , kW)`的滤波器
bias (Tensor, optional): 形状为:math:`(\text{out\_channels})`的可选偏置张量。默认值:``None``
stride (int or tuple): 卷积核的步长。可以是单个数字或
元组`(sH, sW)`。默认值:1(Type)(Type, optional)value``None``Keyword args:
dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
Default: if None, same :class:`torch.dtype` as this tensor.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if None, same :class:`torch.device` as this tensor.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.Keyword args:
dtype (:class:`torch.dtype`, optional): 返回张量的期望类型。
默认值:如果为None,则与当前张量的:class:`torch.dtype`相同。
device (:class:`torch.device`, optional): 返回张量的期望设备。
默认值:如果为None,则与当前张量的:class:`torch.device`相同。
requires_grad (bool, optional): 是否让autograd记录返回张量上的操作。默认值:``False``。Returns:
Tensor: Sampled tensor of same shape as `logits` from the Gumbel-Softmax distribution.
If ``hard=True``, the returned samples will be one-hot, otherwise they will
be probability distributions that sum to 1 across `dim`.Returns:
Tensor: 从Gumbel-Softmax分布采样得到的与`logits`形状相同的张量。
如果``hard=True``,返回的样本将是独热编码形式,否则将是
在`dim`维度上求和为1的概率分布。Examples::
>>> inputs = torch.randn(33, 16, 30)
>>> filters = torch.randn(20, 16, 5)
>>> F.conv1d(inputs, filters)
>>> # With square kernels and equal stride
>>> filters = torch.randn(8, 4, 3, 3)
>>> inputs = torch.randn(1, 4, 5, 5)
>>> F.conv2d(inputs, filters, padding=1)Examples::>>>#>>>Examples::
>>> inputs = torch.randn(33, 16, 30)
>>> filters = torch.randn(20, 16, 5)
>>> F.conv1d(inputs, filters)
>>> # 使用方形核和相等步长
>>> filters = torch.randn(8, 4, 3, 3)
>>> inputs = torch.randn(1, 4, 5, 5)
>>> F.conv2d(inputs, filters, padding=1)Examples::>>>#>>>.. _Link Name:
https://arxiv.org/abs/1611.00712See `Link Name`_.. _Link Name:
https://arxiv.org/abs/1611.00712请参见`Link Name`_def relu(input: Tensor, inplace: bool = False) -> Tensor:
r"""relu(input, inplace=False) -> Tensor
Applies the rectified linear unit function element-wise. See
:class:`~torch.nn.ReLU` for more details.
"""
# implementationdef relu(input: Tensor, inplace: bool = False) -> Tensor:
r"""relu(input, inplace=False) -> Tensor
逐元素应用整流线性单元函数。详情请参见
:class:`~torch.nn.ReLU`。
"""
# 实现代码_add_docstrconv1d = _add_docstr(
torch.conv1d,
r"""
conv1d(input, weight, bias=None, stride=1, padding=0, dilation=1, groups=1) -> Tensor
Applies a 1D convolution over an input signal composed of several input
planes.
See :class:`~torch.nn.Conv1d` for details and output shape.
Args:
input: input tensor of shape :math:`(\text{minibatch} , \text{in\_channels} , iW)`
weight: filters of shape :math:`(\text{out\_channels} , kW)`
...
""",
)_add_docstrconv1d = _add_docstr(
torch.conv1d,
r"""
conv1d(input, weight, bias=None, stride=1, padding=0, dilation=1, groups=1) -> Tensor
对由多个输入平面组成的输入信号应用一维卷积。
详情和输出形状请参见:class:`~torch.nn.Conv1d`。
Args:
input: 形状为:math:`(\text{minibatch} , \text{in\_channels} , iW)`的输入张量
weight: 形状为:math:`(\text{out\_channels} , kW)`的滤波器
...
""",
)_add_docstr_all(
"abs_",
r"""
abs_() -> Tensor
In-place version of :meth:`~Tensor.abs`
""",
)_add_docstr_all(
"abs_",
r"""
abs_() -> Tensor
:meth:`~Tensor.abs`的原地版本
""",
)add_docstr_all(
"absolute",
r"""
absolute() -> Tensor
Alias for :func:`abs`
""",
)add_docstr_all(
"absolute",
r"""
absolute() -> Tensor
:func:`abs`的别名
""",
):math:`(\text{minibatch} , \text{in\_channels} , iH , iW)`:math:`(\text{minibatch} , \text{in\_channels} , iH , iW)`common_args = parse_kwargs(
"""
dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
Default: if None, same as this tensor.
"""
)common_args = parse_kwargs(
"""
dtype (:class:`torch.dtype`, optional): 返回张量的期望类型。
默认值:如果为None,则与当前张量相同。
"""
)undefinedundefinedr"""
{tf32_note}
{cudnn_reproducibility_note}
""".format(**reproducibility_notes, **tf32_notes)r"""
{tf32_note}
{cudnn_reproducibility_note}
""".format(**reproducibility_notes, **tf32_notes)def gumbel_softmax(
logits: Tensor,
tau: float = 1,
hard: bool = False,
eps: float = 1e-10,
dim: int = -1,
) -> Tensor:
r"""
Sample from the Gumbel-Softmax distribution and optionally discretize.
Args:
logits (Tensor): `[..., num_features]` unnormalized log probabilities
tau (float): non-negative scalar temperature
hard (bool): if ``True``, the returned samples will be discretized as one-hot vectors,
but will be differentiated as if it is the soft sample in autograd. Default: ``False``
dim (int): A dimension along which softmax will be computed. Default: -1
Returns:
Tensor: Sampled tensor of same shape as `logits` from the Gumbel-Softmax distribution.
If ``hard=True``, the returned samples will be one-hot, otherwise they will
be probability distributions that sum to 1 across `dim`.
.. note::
This function is here for legacy reasons, may be removed from nn.Functional in the future.
Examples::
>>> logits = torch.randn(20, 32)
>>> # Sample soft categorical using reparametrization trick:
>>> F.gumbel_softmax(logits, tau=1, hard=False)
>>> # Sample hard categorical using "Straight-through" trick:
>>> F.gumbel_softmax(logits, tau=1, hard=True)
.. _Link 1:
https://arxiv.org/abs/1611.00712
"""
# implementationdef gumbel_softmax(
logits: Tensor,
tau: float = 1,
hard: bool = False,
eps: float = 1e-10,
dim: int = -1,
) -> Tensor:
r"""
从Gumbel-Softmax分布中采样并可选地进行离散化。
Args:
logits (Tensor): `[..., num_features]`形状的未归一化对数概率
tau (float): 非负标量温度
hard (bool): 如果为``True``,返回的样本将被离散化为独热向量,
但在自动微分中会被视为软样本。默认值:``False``
dim (int): 计算softmax的维度。默认值:-1
Returns:
Tensor: 与`logits`形状相同的Gumbel-Softmax分布采样张量。
如果``hard=True``,返回的样本为独热编码形式,否则为
在`dim`维度上求和为1的概率分布。
.. note::
该函数仅为兼容保留,未来可能会从nn.Functional中移除。
Examples::
>>> logits = torch.randn(20, 32)
>>> # 使用重参数化技巧采样软分类变量:
>>> F.gumbel_softmax(logits, tau=1, hard=False)
>>> # 使用"直通"技巧采样硬分类变量:
>>> F.gumbel_softmax(logits, tau=1, hard=True)
.. _Link 1:
https://arxiv.org/abs/1611.00712
"""
# 实现代码r""":func::class::meth::class:r""":func::class::meth::class::class:\:func:\:meth:\:attr:\:math:\:ref:\``code``:class:\:func:\:meth:\:attr:\:math:\:ref:\``code````True`` ``None`` ``False``Tensorintfloatboolstrtuplelist``True`` ``None`` ``False``Tensorintfloatboolstrtuplelist