Skip to content
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

Metrics #892

Merged
merged 54 commits into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
46f224f
insert torchvision dependency and write tests for cifar10
BaruchG Aug 8, 2022
01d6f1e
removed print
BaruchG Aug 8, 2022
45c9a9d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 8, 2022
be1fa15
Merge remote-tracking branch 'upstream/master'
BaruchG Aug 19, 2022
86482ce
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 19, 2022
adc57b9
cleanup failed merge
Aug 23, 2022
a2082e3
Merge branch 'master' into BaruchG/master
Aug 23, 2022
f8ba0e6
merge master
Aug 25, 2022
7230608
Merge remote-tracking branch 'upstream/master'
BaruchG Sep 6, 2022
36d57f8
Merge remote-tracking branch 'upstream/master'
BaruchG Sep 9, 2022
88eb870
Merge remote-tracking branch 'upstream/master'
BaruchG Sep 16, 2022
b1995a7
Revert "insert torchvision dependency and write tests for cifar10"
BaruchG Sep 16, 2022
2533023
Merge remote-tracking branch 'upstream/master'
BaruchG Sep 20, 2022
a9a5ab8
ensured tests are present for object detection and removed under review
BaruchG Sep 20, 2022
6ae60a8
cifar10 revert
BaruchG Sep 20, 2022
bfdae01
revert cifar10
BaruchG Sep 20, 2022
c6b4752
revert cifar10
BaruchG Sep 20, 2022
57e99e5
revert cifar10
BaruchG Sep 20, 2022
92d3297
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 20, 2022
22019af
revert cifar10
BaruchG Sep 20, 2022
88f0ff5
Merge branch 'master' into metrics
BaruchG Sep 21, 2022
54e1110
Merge branch 'master' into metrics
BaruchG Sep 21, 2022
f9954f4
renamed variables to conform to specs
BaruchG Sep 21, 2022
f5c5af2
Merge branch 'metrics' of https://github.com/BaruchG/lightning-bolts …
BaruchG Sep 21, 2022
d38a965
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 21, 2022
6a0eacf
added newline
BaruchG Sep 21, 2022
44dedfb
added newline
BaruchG Sep 21, 2022
0d4cc23
upgraded to assert_close and modified tolerance
BaruchG Sep 21, 2022
c32979a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 21, 2022
519c1fe
modified formatting of docstring
BaruchG Sep 22, 2022
d902fa1
Merge branch 'metrics' of https://github.com/BaruchG/lightning-bolts …
BaruchG Sep 22, 2022
42cc317
Merge branch 'Lightning-AI:master' into metrics
BaruchG Sep 22, 2022
d320008
Merge branch 'master' into metrics
mergify[bot] Sep 23, 2022
63de9e8
Merge branch 'master' into metrics
mergify[bot] Sep 23, 2022
486d9f8
Merge remote-tracking branch 'upstream/master'
BaruchG Sep 30, 2022
44c6933
replaced iou and giou with torchvision version
BaruchG Sep 30, 2022
117151c
Merge branch 'metrics' of https://github.com/BaruchG/lightning-bolts …
BaruchG Sep 30, 2022
d420e69
removed torch import
BaruchG Sep 30, 2022
7292918
Merge branch 'master' into metrics
BaruchG Sep 30, 2022
62ddeae
Merge branch 'master' into metrics
otaj Oct 11, 2022
8b3133a
Merge remote-tracking branch 'upstream/master'
BaruchG Oct 27, 2022
ea387be
Merge branch 'master' into metrics
BaruchG Oct 27, 2022
8ab4343
Merge branch 'Lightning-AI:master' into master
BaruchG Oct 27, 2022
030b17c
Merge branch 'master' of https://github.com/BaruchG/lightning-bolts
BaruchG Oct 27, 2022
3516817
Merge branch 'master' into metrics
BaruchG Oct 27, 2022
d3063e8
add torchvision as hard dependency
BaruchG Oct 27, 2022
185b80d
Merge branch 'master' into metrics
BaruchG Oct 31, 2022
6566b86
Merge branch 'master' into metrics
Borda Nov 1, 2022
20dd5ba
Merge branch 'master' into metrics
otaj Nov 2, 2022
86d6a4b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 2, 2022
50ed422
Merge branch 'master' into metrics
mergify[bot] Nov 3, 2022
abba88e
Merge branch 'master' into metrics
mergify[bot] Nov 3, 2022
490ad21
Merge branch 'master' into metrics
otaj Nov 4, 2022
b862c4a
Merge branch 'master' into metrics
mergify[bot] Nov 4, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 3 additions & 27 deletions pl_bolts/metrics/object_detection.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import torch
from torch import Tensor
from torchvision.ops import box_iou, generalized_box_iou


def iou(preds: Tensor, target: Tensor) -> Tensor:
Expand All @@ -22,16 +22,7 @@ def iou(preds: Tensor, target: Tensor) -> Tensor:
IoU tensor: an NxM tensor containing the pairwise IoU values for every element in preds and target,
where N is the number of prediction bounding boxes and M is the number of target bounding boxes
"""
x_min = torch.max(preds[:, None, 0], target[:, 0])
y_min = torch.max(preds[:, None, 1], target[:, 1])
x_max = torch.min(preds[:, None, 2], target[:, 2])
y_max = torch.min(preds[:, None, 3], target[:, 3])
intersection = (x_max - x_min).clamp(min=0) * (y_max - y_min).clamp(min=0)
pred_area = (preds[:, 2] - preds[:, 0]) * (preds[:, 3] - preds[:, 1])
target_area = (target[:, 2] - target[:, 0]) * (target[:, 3] - target[:, 1])
union = pred_area[:, None] + target_area - intersection
iou_value = torch.true_divide(intersection, union)
return iou_value
return box_iou(preds, target)


def giou(preds: Tensor, target: Tensor) -> Tensor:
Expand All @@ -57,19 +48,4 @@ def giou(preds: Tensor, target: Tensor) -> Tensor:
GIoU in an NxM tensor containing the pairwise GIoU values for every element in preds and target,
where N is the number of prediction bounding boxes and M is the number of target bounding boxes
"""
x_min = torch.max(preds[:, None, 0], target[:, 0])
y_min = torch.max(preds[:, None, 1], target[:, 1])
x_max = torch.min(preds[:, None, 2], target[:, 2])
y_max = torch.min(preds[:, None, 3], target[:, 3])
intersection = (x_max - x_min).clamp(min=0) * (y_max - y_min).clamp(min=0)
pred_area = (preds[:, 2] - preds[:, 0]) * (preds[:, 3] - preds[:, 1])
target_area = (target[:, 2] - target[:, 0]) * (target[:, 3] - target[:, 1])
union = pred_area[:, None] + target_area - intersection
C_x_min = torch.min(preds[:, None, 0], target[:, 0])
C_y_min = torch.min(preds[:, None, 1], target[:, 1])
C_x_max = torch.max(preds[:, None, 2], target[:, 2])
C_y_max = torch.max(preds[:, None, 3], target[:, 3])
C_area = (C_x_max - C_x_min).clamp(min=0) * (C_y_max - C_y_min).clamp(min=0)
iou_value = torch.true_divide(intersection, union)
giou_value = iou_value - torch.true_divide((C_area - union), C_area)
return giou_value
return generalized_box_iou(preds, target)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pytorch-lightning>=1.7.0
lightning-utilities>=0.3.0, !=0.4.0 # this is needed for PL 1.7
torchvision>=0.10.*