Skip to content

Commit

Permalink
Performance Bugfixes (#778)
Browse files Browse the repository at this point in the history
  • Loading branch information
czaloom authored Oct 8, 2024
1 parent 5facad4 commit e0cabe0
Show file tree
Hide file tree
Showing 10 changed files with 368 additions and 657 deletions.
20 changes: 11 additions & 9 deletions lite/tests/detection/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -871,23 +871,24 @@ def detection_ranked_pair_ordering() -> Detection:
@pytest.fixture
def detection_ranked_pair_ordering_with_bitmasks() -> Detection:

bitmask1 = np.zeros((100, 50), dtype=np.bool_)
bitmask1[79, 31] = True

bitmask2 = np.zeros((100, 50), dtype=np.bool_)
bitmask2[80:, 32:] = True

gts = {
"bitmasks": [
np.ones((80, 32), dtype=bool),
np.ones((80, 32), dtype=bool),
np.ones((80, 32), dtype=bool),
bitmask1,
bitmask1,
bitmask1,
],
"label_values": ["label1", "label2", "label3"],
}

# labels 1 and 2 have IOU==1, labels 3 and 4 have IOU==0
preds = {
"bitmasks": [
np.ones((80, 32), dtype=bool),
np.ones((80, 32), dtype=bool),
np.zeros((80, 32), dtype=bool),
np.zeros((80, 32), dtype=bool),
],
"bitmasks": [bitmask1, bitmask1, bitmask2, bitmask2],
"label_values": ["label1", "label2", "label3", "label4"],
"scores": [
0.3,
Expand All @@ -896,6 +897,7 @@ def detection_ranked_pair_ordering_with_bitmasks() -> Detection:
0.94,
],
}

groundtruths = [
Bitmask(
mask=mask,
Expand Down
26 changes: 8 additions & 18 deletions lite/tests/detection/test_dataloader.py

Large diffs are not rendered by default.

30 changes: 14 additions & 16 deletions lite/tests/detection/test_filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_filtering_one_detection(one_detection: list[Detection]):
# test datum filtering
filter_ = evaluator.create_filter(datum_uids=["uid1"])
assert (filter_.ranked_indices == np.array([0])).all()
assert (filter_.detailed_indices == np.array([0, 1, 2, 3, 4])).all()
assert (filter_.detailed_indices == np.array([0, 1])).all()
assert (
filter_.label_metadata
== np.array(
Expand All @@ -123,12 +123,12 @@ def test_filtering_one_detection(one_detection: list[Detection]):
# test label filtering
filter_ = evaluator.create_filter(labels=["v1"])
assert (filter_.ranked_indices == np.array([0])).all()
assert (filter_.detailed_indices == np.array([0, 2])).all()
assert (filter_.detailed_indices == np.array([0])).all()
assert (filter_.label_metadata == np.array([[1, 1], [0, 0]])).all()

filter_ = evaluator.create_filter(labels=["v2"])
assert (filter_.ranked_indices == np.array([])).all()
assert (filter_.detailed_indices == np.array([1, 3])).all()
assert (filter_.detailed_indices == np.array([1])).all()
assert (filter_.label_metadata == np.array([[0, 0], [1, 0]])).all()

# test combo
Expand All @@ -137,7 +137,7 @@ def test_filtering_one_detection(one_detection: list[Detection]):
labels=["v1"],
)
assert (filter_.ranked_indices == np.array([0])).all()
assert (filter_.detailed_indices == np.array([0, 2])).all()
assert (filter_.detailed_indices == np.array([0])).all()
assert (filter_.label_metadata == np.array([[1, 1], [0, 0]])).all()

# test evaluation
Expand Down Expand Up @@ -225,12 +225,12 @@ def test_filtering_two_detections(two_detections: list[Detection]):
# test datum filtering
filter_ = evaluator.create_filter(datum_uids=["uid1"])
assert (filter_.ranked_indices == np.array([1])).all()
assert (filter_.detailed_indices == np.array([0, 1, 2, 3, 4])).all()
assert (filter_.detailed_indices == np.array([0, 1])).all()
assert (filter_.label_metadata == np.array([[1, 1], [1, 0]])).all()

filter_ = evaluator.create_filter(datum_uids=["uid2"])
assert (filter_.ranked_indices == np.array([0])).all()
assert (filter_.detailed_indices == np.array([5, 6, 7])).all()
assert (filter_.detailed_indices == np.array([2])).all()
assert (
filter_.label_metadata
== np.array(
Expand All @@ -250,12 +250,12 @@ def test_filtering_two_detections(two_detections: list[Detection]):
# test label filtering
filter_ = evaluator.create_filter(labels=["v1"])
assert (filter_.ranked_indices == np.array([0, 1])).all()
assert (filter_.detailed_indices == np.array([0, 2, 5, 6])).all()
assert (filter_.detailed_indices == np.array([0, 2])).all()
assert (filter_.label_metadata == np.array([[2, 1], [0, 0]])).all()

filter_ = evaluator.create_filter(labels=["v2"])
assert (filter_.ranked_indices == np.array([])).all()
assert (filter_.detailed_indices == np.array([1, 3])).all()
assert (filter_.detailed_indices == np.array([1])).all()
assert (filter_.label_metadata == np.array([[0, 0], [1, 1]])).all()

# test combo
Expand All @@ -264,7 +264,7 @@ def test_filtering_two_detections(two_detections: list[Detection]):
labels=["v1"],
)
assert (filter_.ranked_indices == np.array([1])).all()
assert (filter_.detailed_indices == np.array([0, 2])).all()
assert (filter_.detailed_indices == np.array([0])).all()
assert (filter_.label_metadata == np.array([[1, 1], [0, 0]])).all()

# test evaluation
Expand Down Expand Up @@ -362,25 +362,23 @@ def test_filtering_four_detections(four_detections: list[Detection]):
# test datum filtering
filter_ = evaluator.create_filter(datum_uids=["uid1"])
assert (filter_.ranked_indices == np.array([2])).all()
assert (filter_.detailed_indices == np.array([0, 1, 2, 3, 4])).all()
assert (filter_.detailed_indices == np.array([0, 1])).all()
assert (filter_.label_metadata == np.array([[1, 1], [1, 0]])).all()

filter_ = evaluator.create_filter(datum_uids=["uid2"])
assert (filter_.ranked_indices == np.array([0])).all()
assert (filter_.detailed_indices == np.array([5, 6, 7])).all()
assert (filter_.detailed_indices == np.array([2])).all()
assert (filter_.label_metadata == np.array([[1, 0], [0, 1]])).all()

# test label filtering
filter_ = evaluator.create_filter(labels=["v1"])
assert (filter_.ranked_indices == np.array([0, 1, 2, 3])).all()
assert (
filter_.detailed_indices == np.array([0, 2, 5, 6, 8, 10, 13, 14])
).all()
assert (filter_.detailed_indices == np.array([0, 2, 3, 5])).all()
assert (filter_.label_metadata == np.array([[4, 2], [0, 0]])).all()

filter_ = evaluator.create_filter(labels=["v2"])
assert (filter_.ranked_indices == np.array([])).all()
assert (filter_.detailed_indices == np.array([1, 3, 9, 11])).all()
assert (filter_.detailed_indices == np.array([1, 4])).all()
assert (filter_.label_metadata == np.array([[0, 0], [2, 2]])).all()

# test combo
Expand All @@ -389,7 +387,7 @@ def test_filtering_four_detections(four_detections: list[Detection]):
labels=["v1"],
)
assert (filter_.ranked_indices == np.array([2])).all()
assert (filter_.detailed_indices == np.array([0, 2])).all()
assert (filter_.detailed_indices == np.array([0])).all()
assert (
filter_.label_metadata
== np.array(
Expand Down
Loading

0 comments on commit e0cabe0

Please sign in to comment.