-
Notifications
You must be signed in to change notification settings - Fork 724
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hackathon No.30 #4644
Hackathon No.30 #4644
Changes from 19 commits
de3d418
8e80927
b1eab7c
0b59483
6d80ea4
817a924
f271539
8ea441d
9654503
7c7f772
36cb64c
21674d5
8fd9e9e
0aedc77
ced2866
58fe4d3
824d904
35687d7
b2204f3
2f7d3f8
6aa92a1
ba6b33d
a5e4d8d
988c79f
899c9b5
532ad3e
580cc9d
ed91ef5
bf3ae2c
f1d8878
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
.. _cn_api_paddle_nn_TripletMarginWithDistanceLoss: | ||
|
||
TripletMarginWithDistanceLoss | ||
------------------------------- | ||
|
||
.. py:class:: paddle.nn.TripletMarginWithDistanceLoss(distance_function=None, margin: float = 1.0, swap: bool = False, reduction: str = 'mean') | ||
|
||
创建一个TripletMarginWithDistanceLoss的可调用类,通过计算输入 `input` 和 `positive` 和 `negative` 间的 `triplet margin loss` 损失,测量样本之间,即 `input` 与 `positive examples` 和 `negative examples` 的相对相似性。 | ||
|
||
|
||
损失函数按照下列公式计算 | ||
|
||
.. math:: | ||
L(input, pos, neg) = \max \{d(input_i, pos_i) - d(input_i, neg_i) + {\rm margin}, 0\} | ||
|
||
|
||
其中的距离函数可以由用户自定义,使用lambda或是def都可以。如果未定义则调用2范数计算距离 | ||
|
||
.. math:: | ||
d(x_i, y_i) = \left\lVert {\bf x}_i - {\bf y}_i \right\rVert_2 | ||
|
||
|
||
其中 ``distance_function`` 为距离函数,默认为2范数。 ``margin`` 为(input,positive)与(input,negative)的距离间隔, ``swap`` 的内容可以看论文 `Learning shallow convolutional feature descriptors with triplet losses <http://www.bmva.org/bmvc/2016/papers/paper119/paper119.pdf>`_。 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
最后,该api会添加 `reduce` 操作到前面的输出Out上。当 `reduction` 为 `none` 时,直接返回最原始的 `Out` 结果。当 `reduction` 为 `mean` 时, | ||
返回输出的均值 :math:`Out = MEAN(Out)` 。当 `reduction` 为 `sum` 时,返回输出的求和 :math:`Out = SUM(Out)` 。 | ||
|
||
|
||
参数 | ||
::::::::: | ||
- **distance_function** (可选) - 手动指定范数,默认为None, 使用欧式距离。 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
- **swap** (bool,可选) - 默认为False | ||
- **margin** (float,可选) - 手动指定间距,默认为1。 | ||
- **reduction** (str,可选) - 指定应用于输出结果的计算方式,可选值有: ``'none'``, ``'mean'``, ``'sum'`` 。默认为 ``'mean'``,计算 Loss 的均值;设置为 ``'sum'`` 时,计算 Loss 的总和;设置为 ``'none'`` 时,则返回原始Loss。 | ||
- **name** (str,可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name` 。 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 已修改 |
||
|
||
形状 | ||
::::::::: | ||
- **input** (Tensor) - :math:`[N, *]` , 其中N是batch_size, `*` 是任意其他维度。数据类型是float32、float64。 | ||
- **positive** (Tensor) - :math:`[N, *]` ,标签 ``positive`` 的维度、数据类型与输入 ``input`` 相同。 | ||
- **negative** (Tensor) - :math:`[N, *]` ,标签 ``negative`` 的维度、数据类型与输入 ``input`` 相同。 | ||
- **output** (Tensor) - 输出的Tensor。如果 :attr:`reduction` 是 ``'none'``, 则输出的维度为 :math:`[N, *]` , 与输入 ``input`` 的形状相同。如果 :attr:`reduction` 是 ``'mean'`` 或 ``'sum'``, 则输出的维度为 :math:`[1]` 。 | ||
|
||
返回 | ||
::::::::: | ||
返回计算TripletMarginWithDistanceLoss的可调用对象。 | ||
|
||
代码示例 | ||
::::::::: | ||
COPY-FROM: paddle.nn.TripletMarginWithDistanceLoss |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
.. _cn_api_paddle_nn_functional_triplet_margin_with_distance_loss: | ||
|
||
triplet_margin_with_distance_loss | ||
------------------------------- | ||
|
||
.. py:class:: paddle.nn.functional.triplet_margin_with_distance_loss(input, positive, negative, distance_function=None, margin: float = 1.0, swap: bool = False, reduction: str = 'mean') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 已修改 |
||
|
||
该api计算输入 `input` 和 `positive` 和 `negative` 间的 `triplet margin loss` 损失。 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 去掉「该api」 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 已修改 |
||
|
||
|
||
损失函数按照下列公式计算 | ||
|
||
.. math:: | ||
L(input, pos, neg) = \max \{d(input_i, pos_i) - d(input_i, neg_i) + {\rm margin}, 0\} | ||
|
||
|
||
其中的距离函数可以由用户自定义,使用lambda或是def都可以。如果未定义则调用2范数计算距离 | ||
|
||
.. math:: | ||
d(x_i, y_i) = \left\lVert {\bf x}_i - {\bf y}_i \right\rVert_2 | ||
|
||
|
||
然后, ``distance_function`` 为距离函数,默认为2范数。 ``margin`` 为(input,positive)与(input,negative)的距离间隔, ``swap`` 的内容可以看论文 `Learning shallow convolutional feature descriptors with triplet losses <http://www.bmva.org/bmvc/2016/papers/paper119/paper119.pdf>`_。 | ||
|
||
最后,该算子会添加 `reduce` 操作到前面的输出Out上。当 `reduction` 为 `none` 时,直接返回最原始的 `Out` 结果。当 `reduction` 为 `mean` 时,返回输出的均值 :math:`Out = MEAN(Out)` 。当 `reduction` 为 `sum` 时,返回输出的求和 :math:`Out = SUM(Out)` 。 | ||
|
||
|
||
参数 | ||
::::::::: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 参考TripletMarginWithDistanceLoss进行修改 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 已修改 |
||
- **input** (Tensor) - :math:`[N, * ]` , 其中N是batch_size, `*` 是任意其他维度。数据类型是float32、float64。 | ||
- **positive** (Tensor) - :math:`[N, *]` ,正样本。 | ||
- **negative** (Tensor) - :math:`[N, *]` ,负样本。 | ||
- **distance_function** (可选) - 手动指定范数,默认为None, 计算欧式距离。 | ||
- **swap** (bool,可选) | ||
- **margin** (float,可选) - 手动指定间距,默认为1。 | ||
- **reduction** (str,可选) - 指定应用于输出结果的计算方式,可选值有: ``'none'``, ``'mean'``, ``'sum'`` 。默认为 ``'mean'``,计算 Loss 的均值;设置为 ``'sum'`` 时,计算 Loss 的总和;设置为 ``'none'`` 时,则返回原始Loss。 | ||
- **name** (str,可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name` 。 | ||
|
||
形状 | ||
::::::::: | ||
- **input** (Tensor) - :math:`[N, *]` , 其中N是batch_size, `*` 是任意其他维度。数据类型是float32、float64。 | ||
- **positive** (Tensor) - :math:`[N, *]` ,标签 ``positive`` 的维度、数据类型与输入 ``input`` 相同。 | ||
- **negative** (Tensor) - :math:`[N, *]` ,标签 ``negative`` 的维度、数据类型与输入 ``input`` 相同。 | ||
- **output** (Tensor) - 输出的Tensor。如果 :attr:`reduction` 是 ``'none'``, 则输出的维度为 :math:`[N, *]` , 与输入 ``input`` 的形状相同。如果 :attr:`reduction` 是 ``'mean'`` 或 ``'sum'``, 则输出的维度为 :math:`[1]` 。 | ||
|
||
返回 | ||
::::::::: | ||
返回计算的Loss。 | ||
|
||
代码示例 | ||
::::::::: | ||
COPY-FROM: paddle.nn.functional.triplet_margin_with_distance_loss |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里是不是缺少了nn.functional.triplet_margin_with_distance_loss的API文档?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已添加
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已添加