Shape:
- Input: :math:`(N, C)` where `C = number of classes`, or
- :math:`(N, C, d_1, d_2, ..., d_K)` with :math:`K \geq 2`
- in the case of `K`-dimensional loss.
+ :math:`(N, C, d_1, d_2, ..., d_K)` with :math:`K \geq 2`
+ in the case of `K`-dimensional loss.
- Target: :math:`(N)` where each value is :math:`0 \leq \text{targets}[i] \leq C-1`, or
- :math:`(N, d_1, d_2, ..., d_K)` with :math:`K \geq 2` in the case of
- K-dimensional loss.
+ :math:`(N, d_1, d_2, ..., d_K)` with :math:`K \geq 2` in the case of
+ K-dimensional loss.
- Output: scalar. If reduce is ``False``, then the same size
- as the target: :math:`(N)`, or
- :math:`(N, d_1, d_2, ..., d_K)` with :math:`K \geq 2` in the case
- of K-dimensional loss.
+ as the target: :math:`(N)`, or
+ :math:`(N, d_1, d_2, ..., d_K)` with :math:`K \geq 2` in the case
+ of K-dimensional loss.
Examples::
dimensions
- target: :math:`(N, *)`, same shape as the input
- output: scalar by default. If `reduce` is ``False``, then :math:`(N, *)`,
- the same shape as the input
+ the same shape as the input
"""
__constants__ = ['reduction']
- Input: :math:`(N, *)` where `*` means, any number of additional
dimensions
- Target: :math:`(N, *)`, same shape as the input
- - Output: scalar. If `reduce` is False, then `(N, *)`, same shape as
- input.
+ - Output: scalar. If `reduce` is False, then :math:`(N, *)`, same
+ shape as input.
Examples::
- Input: :math:`(C)` or :math:`(N, C)` where `N` is the batch size and `C`
is the number of classes.
- Target: :math:`(C)` or :math:`(N, C)`, same shape as the input.
- - Output: scalar. If `reduce` is False, then `(N)`.
+ - Output: scalar. If `reduce` is False, then :math:`(N)`.
"""
__constants__ = ['reduction']
Shape:
- Input: :math:`(N, C)` where `C = number of classes`, or
- :math:`(N, C, d_1, d_2, ..., d_K)` with :math:`K \geq 2`
- in the case of `K`-dimensional loss.
+ :math:`(N, C, d_1, d_2, ..., d_K)` with :math:`K \geq 2`
+ in the case of `K`-dimensional loss.
- Target: :math:`(N)` where each value is :math:`0 \leq \text{targets}[i] \leq C-1`, or
- :math:`(N, d_1, d_2, ..., d_K)` with :math:`K \geq 2` in the case of
- K-dimensional loss.
+ :math:`(N, d_1, d_2, ..., d_K)` with :math:`K \geq 2` in the case of
+ K-dimensional loss.
- Output: scalar. If reduce is ``False``, then the same size
- as the target: :math:`(N)`, or
- :math:`(N, d_1, d_2, ..., d_K)` with :math:`K \geq 2` in the case
- of K-dimensional loss.
+ as the target: :math:`(N)`, or
+ :math:`(N, d_1, d_2, ..., d_K)` with :math:`K \geq 2` in the case
+ of K-dimensional loss.
Examples::
Shape:
- Input: :math:`(N, C)` where `N` is the batch size and `C` is the number of classes.
- Target: :math:`(N, C)`, same shape as the input.
- - Output: scalar. If `reduce` is False, then `(N)`.
+ - Output: scalar. If `reduce` is False, then :math:`(N)`.
"""
__constants__ = ['weight', 'reduction']
Shape:
- Input: :math:`(N, D)` where `N` is the batch size and `D` is the size of a sample.
- Target: :math:`(N)`
- - Output: scalar. If `reduce` is False, then `(N)`.
+ - Output: scalar. If `reduce` is False, then :math:`(N)`.
"""
__constants__ = ['margin', 'reduction']
Shape:
- Input: :math:`(N, D)` where `D` is the vector dimension.
- - Output: scalar. If `reduce` is False, then `(N)`.
+ - Output: scalar. If `reduce` is False, then :math:`(N)`.
>>> triplet_loss = nn.TripletMarginLoss(margin=1.0, p=2)
>>> input1 = torch.randn(100, 128, requires_grad=True)