-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #231 from yfukai/metric_utils_doc
Updating metric utils doc, added __version__ and bump patch
- Loading branch information
Showing
8 changed files
with
73 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "laptrack" | ||
version = "0.9.0" | ||
version = "0.9.1" | ||
description = "LapTrack" | ||
authors = ["Yohsuke Fukai <[email protected]>"] | ||
license = "BSD-3-Clause" | ||
|
@@ -83,3 +83,5 @@ show_error_context = true | |
[build-system] | ||
requires = ["poetry-core>=1.0.0"] | ||
build-backend = "poetry.core.masonry.api" | ||
|
||
[tool.poetry_bumpversion.file."src/laptrack/__init__.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,5 @@ | |
"scores", | ||
"metric_utils", | ||
] | ||
|
||
__version__ = "0.9.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,44 @@ | ||
from itertools import product | ||
from typing import List | ||
from typing import Union | ||
|
||
import numpy as np | ||
import pytest | ||
|
||
from laptrack._typing_utils import IntArray | ||
from laptrack.metric_utils import LabelOverlap | ||
|
||
|
||
def test_label_overlap() -> None: | ||
labels = np.array( | ||
[ | ||
[[[0, 1, 1, 1, 0], [0, 1, 2, 2, 2]], [[0, 1, 2, 2, 2], [3, 3, 3, 1, 0]]], | ||
[[[0, 1, 1, 1, 2], [0, 4, 1, 2, 2]], [[0, 4, 4, 4, 4], [0, 4, 4, 4, 4]]], | ||
[[[0, 1, 1, 1, 0], [5, 5, 5, 5, 5]], [[0, 1, 1, 1, 0], [0, 1, 1, 1, 0]]], | ||
] | ||
) | ||
lo = LabelOverlap(labels) | ||
frame_labels = [np.unique(label) for label in labels] | ||
frame_labels = [x[x > 0] for x in frame_labels] | ||
for f1, f2 in [(0, 0), (0, 1), (1, 2)]: | ||
for l1, l2 in product(frame_labels[f1], frame_labels[f2]): | ||
b1 = labels[f1] == l1 | ||
b2 = labels[f2] == l2 | ||
labels = [ | ||
[[[0, 1, 1, 1, 0], [0, 1, 2, 2, 2]], [[0, 1, 2, 2, 2], [3, 3, 3, 1, 0]]], | ||
[[[0, 1, 1, 1, 2], [0, 4, 1, 2, 2]], [[0, 4, 4, 4, 4], [0, 4, 4, 4, 4]]], | ||
[[[0, 1, 1, 1, 0], [5, 5, 5, 5, 5]], [[0, 1, 1, 1, 0], [0, 1, 1, 1, 0]]], | ||
] | ||
labelss: List[Union[IntArray, List[IntArray]]] = [ | ||
np.array(labels), | ||
[np.array(label).astype(np.int64) for label in labels], | ||
] | ||
|
||
intersect = np.sum(b1 & b2) | ||
union = np.sum(b1 | b2) | ||
r1 = np.sum(b1) | ||
r2 = np.sum(b2) | ||
res = lo.calc_overlap(f1, l1, f2, l2) | ||
assert ( | ||
intersect, | ||
(intersect / union), | ||
(intersect / r1), | ||
(intersect / r2), | ||
) == res | ||
for _labels in labelss: | ||
lo = LabelOverlap(_labels) | ||
frame_labels = [np.unique(label) for label in _labels] | ||
frame_labels = [x[x > 0] for x in frame_labels] | ||
for f1, f2 in [(0, 0), (0, 1), (1, 2)]: | ||
for l1, l2 in product(frame_labels[f1], frame_labels[f2]): | ||
b1 = _labels[f1] == l1 | ||
b2 = _labels[f2] == l2 | ||
|
||
intersect = np.sum(b1 & b2) | ||
union = np.sum(b1 | b2) | ||
r1 = np.sum(b1) | ||
r2 = np.sum(b2) | ||
res = lo.calc_overlap(f1, l1, f2, l2) | ||
assert ( | ||
intersect, | ||
(intersect / union), | ||
(intersect / r1), | ||
(intersect / r2), | ||
) == res | ||
with pytest.raises(ValueError): | ||
LabelOverlap(np.array([[1, 2], [0, 1]])) |