From 914e4418516bdc7411e0e765c4449af2d8de5623 Mon Sep 17 00:00:00 2001 From: Abhijit Deo <72816663+abhi-glitchhg@users.noreply.github.com> Date: Sun, 10 Apr 2022 23:20:15 +0530 Subject: [PATCH 1/8] Update focal_loss.py updated docstring for the `sigmoid_focal_loss` --- torchvision/ops/focal_loss.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/torchvision/ops/focal_loss.py b/torchvision/ops/focal_loss.py index f38855ea459..6d4f320eecc 100644 --- a/torchvision/ops/focal_loss.py +++ b/torchvision/ops/focal_loss.py @@ -16,19 +16,20 @@ def sigmoid_focal_loss( Loss used in RetinaNet for dense detection: https://arxiv.org/abs/1708.02002. Args: - inputs: A float tensor of arbitrary shape. + inputs: (Tensor) A float tensor of arbitrary shape. The predictions for each example. - targets: A float tensor with the same shape as inputs. Stores the binary + targets: (Tensor) A float tensor with the same shape as inputs. Stores the binary classification label for each element in inputs (0 for the negative class and 1 for the positive class). - alpha: (optional) Weighting factor in range (0,1) to balance + alpha: (float) Weighting factor in range (0,1) to balance positive vs negative examples or -1 for ignore. Default = 0.25 - gamma: Exponent of the modulating factor (1 - p_t) to + gamma: (float) Exponent of the modulating factor (1 - p_t) to balance easy vs hard examples. - reduction: 'none' | 'mean' | 'sum' + reduction: (string) 'none' | 'mean' | 'sum' 'none': No reduction will be applied to the output. 'mean': The output will be averaged. 'sum': The output will be summed. + Default is 'none' Returns: Loss tensor with the reduction option applied. """ From 6d14a56e890a1e1f8956b0d473f79d493fc93c76 Mon Sep 17 00:00:00 2001 From: abhijit_linux Date: Mon, 11 Apr 2022 00:03:39 +0530 Subject: [PATCH 2/8] edited docstring of focal_loss --- torchvision/ops/focal_loss.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/torchvision/ops/focal_loss.py b/torchvision/ops/focal_loss.py index 6d4f320eecc..1f2ae755d56 100644 --- a/torchvision/ops/focal_loss.py +++ b/torchvision/ops/focal_loss.py @@ -25,11 +25,11 @@ def sigmoid_focal_loss( positive vs negative examples or -1 for ignore. Default = 0.25 gamma: (float) Exponent of the modulating factor (1 - p_t) to balance easy vs hard examples. - reduction: (string) 'none' | 'mean' | 'sum' - 'none': No reduction will be applied to the output. - 'mean': The output will be averaged. - 'sum': The output will be summed. - Default is 'none' + reduction: (string) ``'none'`` | ``'mean'`` | ``'sum'`` + ``'none'``: No reduction will be applied to the output. + ``'mean'``: The output will be averaged. + ``'sum'``: The output will be summed. + Default is ``'none'``. Returns: Loss tensor with the reduction option applied. """ From 5e877d62ed198f6d49b5c8d66665db9b6556f0e2 Mon Sep 17 00:00:00 2001 From: Abhijit Deo <72816663+abhi-glitchhg@users.noreply.github.com> Date: Mon, 11 Apr 2022 10:54:46 +0530 Subject: [PATCH 3/8] Update focal_loss.py --- torchvision/ops/focal_loss.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torchvision/ops/focal_loss.py b/torchvision/ops/focal_loss.py index 1f2ae755d56..d44c51ac6da 100644 --- a/torchvision/ops/focal_loss.py +++ b/torchvision/ops/focal_loss.py @@ -24,7 +24,7 @@ def sigmoid_focal_loss( alpha: (float) Weighting factor in range (0,1) to balance positive vs negative examples or -1 for ignore. Default = 0.25 gamma: (float) Exponent of the modulating factor (1 - p_t) to - balance easy vs hard examples. + balance easy vs hard examples. Default = 2 reduction: (string) ``'none'`` | ``'mean'`` | ``'sum'`` ``'none'``: No reduction will be applied to the output. ``'mean'``: The output will be averaged. From 788e90edde20e438179d51e5796e5cdc7797e8f9 Mon Sep 17 00:00:00 2001 From: abhijit_linux Date: Mon, 11 Apr 2022 14:19:43 +0530 Subject: [PATCH 4/8] fix doc style. --- torchvision/ops/focal_loss.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/torchvision/ops/focal_loss.py b/torchvision/ops/focal_loss.py index 1f2ae755d56..2f81d27b75c 100644 --- a/torchvision/ops/focal_loss.py +++ b/torchvision/ops/focal_loss.py @@ -16,16 +16,16 @@ def sigmoid_focal_loss( Loss used in RetinaNet for dense detection: https://arxiv.org/abs/1708.02002. Args: - inputs: (Tensor) A float tensor of arbitrary shape. + inputs (Tensor) : A float tensor of arbitrary shape. The predictions for each example. - targets: (Tensor) A float tensor with the same shape as inputs. Stores the binary + targets (Tensor) : A float tensor with the same shape as inputs. Stores the binary classification label for each element in inputs (0 for the negative class and 1 for the positive class). - alpha: (float) Weighting factor in range (0,1) to balance + alpha (float) : Weighting factor in range (0,1) to balance positive vs negative examples or -1 for ignore. Default = 0.25 - gamma: (float) Exponent of the modulating factor (1 - p_t) to + gamma (float) : Exponent of the modulating factor (1 - p_t) to balance easy vs hard examples. - reduction: (string) ``'none'`` | ``'mean'`` | ``'sum'`` + reduction (string) : ``'none'`` | ``'mean'`` | ``'sum'`` ``'none'``: No reduction will be applied to the output. ``'mean'``: The output will be averaged. ``'sum'``: The output will be summed. From e719a1b7006077bf67b1bd02d3f34c133c6c8e68 Mon Sep 17 00:00:00 2001 From: abhijit_linux Date: Tue, 12 Apr 2022 14:52:28 +0530 Subject: [PATCH 5/8] formatting --- torchvision/ops/focal_loss.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/torchvision/ops/focal_loss.py b/torchvision/ops/focal_loss.py index 81d016c2c0d..1d6ccec6996 100644 --- a/torchvision/ops/focal_loss.py +++ b/torchvision/ops/focal_loss.py @@ -10,26 +10,26 @@ def sigmoid_focal_loss( alpha: float = 0.25, gamma: float = 2, reduction: str = "none", -): +) -> torch.Tensor: """ Original implementation from https://github.com/facebookresearch/fvcore/blob/master/fvcore/nn/focal_loss.py . Loss used in RetinaNet for dense detection: https://arxiv.org/abs/1708.02002. Args: - inputs (Tensor) : A float tensor of arbitrary shape. + inputs (Tensor): A float tensor of arbitrary shape. The predictions for each example. - targets (Tensor) : A float tensor with the same shape as inputs. Stores the binary + targets (Tensor): A float tensor with the same shape as inputs. Stores the binary classification label for each element in inputs (0 for the negative class and 1 for the positive class). - alpha (float) : Weighting factor in range (0,1) to balance - positive vs negative examples or -1 for ignore. Default = 0.25 - gamma (float) : Exponent of the modulating factor (1 - p_t) to - balance easy vs hard examples. Default = 2 - reduction (string) : ``'none'`` | ``'mean'`` | ``'sum'`` - ``'none'``: No reduction will be applied to the output. - ``'mean'``: The output will be averaged. - ``'sum'``: The output will be summed. - Default is ``'none'``. + alpha (float, optional): Weighting factor in range (0,1) to balance + positive vs negative examples or -1 for ignore. Default: 0.25 + gamma (float, optional): Exponent of the modulating factor (1 - p_t) to + balance easy vs hard examples. Default: 2 + reduction (string, optional): ``'none'`` | ``'mean'`` | ``'sum'`` + ``'none'``: No reduction will be applied to the output. + ``'mean'``: The output will be averaged. + ``'sum'``: The output will be summed. + Default: ``'none'`` Returns: Loss tensor with the reduction option applied. """ From 2533b2056e6279d3eed14edeee9c651a3cbb40eb Mon Sep 17 00:00:00 2001 From: abhijit_linux Date: Tue, 12 Apr 2022 14:54:58 +0530 Subject: [PATCH 6/8] formatting --- torchvision/ops/focal_loss.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/torchvision/ops/focal_loss.py b/torchvision/ops/focal_loss.py index 1d6ccec6996..b8f2910e0a4 100644 --- a/torchvision/ops/focal_loss.py +++ b/torchvision/ops/focal_loss.py @@ -28,8 +28,7 @@ def sigmoid_focal_loss( reduction (string, optional): ``'none'`` | ``'mean'`` | ``'sum'`` ``'none'``: No reduction will be applied to the output. ``'mean'``: The output will be averaged. - ``'sum'``: The output will be summed. - Default: ``'none'`` + ``'sum'``: The output will be summed. Default: ``'none'`` Returns: Loss tensor with the reduction option applied. """ From 6b5cb3ac06c07a89511e25fbdd482ae39110b63d Mon Sep 17 00:00:00 2001 From: abhijit_linux Date: Fri, 15 Apr 2022 11:00:41 +0530 Subject: [PATCH 7/8] minor edits --- torchvision/ops/focal_loss.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/torchvision/ops/focal_loss.py b/torchvision/ops/focal_loss.py index b8f2910e0a4..2739f837979 100644 --- a/torchvision/ops/focal_loss.py +++ b/torchvision/ops/focal_loss.py @@ -21,14 +21,14 @@ def sigmoid_focal_loss( targets (Tensor): A float tensor with the same shape as inputs. Stores the binary classification label for each element in inputs (0 for the negative class and 1 for the positive class). - alpha (float, optional): Weighting factor in range (0,1) to balance - positive vs negative examples or -1 for ignore. Default: 0.25 - gamma (float, optional): Exponent of the modulating factor (1 - p_t) to - balance easy vs hard examples. Default: 2 - reduction (string, optional): ``'none'`` | ``'mean'`` | ``'sum'`` + alpha (float): Weighting factor in range (0,1) to balance + positive vs negative examples or -1 for ignore. Default: ``0.25``. + gamma (float): Exponent of the modulating factor (1 - p_t) to + balance easy vs hard examples. Default: ``2``. + reduction (string): ``'none'`` | ``'mean'`` | ``'sum'`` ``'none'``: No reduction will be applied to the output. ``'mean'``: The output will be averaged. - ``'sum'``: The output will be summed. Default: ``'none'`` + ``'sum'``: The output will be summed. Default: ``'none'``. Returns: Loss tensor with the reduction option applied. """ From dd7027c3a14609b12237a5868626f3fbd6e8f19e Mon Sep 17 00:00:00 2001 From: Vasilis Vryniotis Date: Tue, 19 Apr 2022 09:24:00 +0100 Subject: [PATCH 8/8] move attribution link --- torchvision/ops/focal_loss.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torchvision/ops/focal_loss.py b/torchvision/ops/focal_loss.py index 2739f837979..c8cc9a8ac14 100644 --- a/torchvision/ops/focal_loss.py +++ b/torchvision/ops/focal_loss.py @@ -12,7 +12,6 @@ def sigmoid_focal_loss( reduction: str = "none", ) -> torch.Tensor: """ - Original implementation from https://github.com/facebookresearch/fvcore/blob/master/fvcore/nn/focal_loss.py . Loss used in RetinaNet for dense detection: https://arxiv.org/abs/1708.02002. Args: @@ -32,6 +31,7 @@ def sigmoid_focal_loss( Returns: Loss tensor with the reduction option applied. """ + # Original implementation from https://github.com/facebookresearch/fvcore/blob/master/fvcore/nn/focal_loss.py if not torch.jit.is_scripting() and not torch.jit.is_tracing(): _log_api_usage_once(sigmoid_focal_loss) p = torch.sigmoid(inputs)