Skip to content

Commit

Permalink
bugfix: auto adapt batch size doesn't work with cls incr case (#2199)
Browse files Browse the repository at this point in the history
* auto adapt consider cls incremental case

* align with pre-commit

* update changelog
  • Loading branch information
eunwoosh authored and goodsong81 committed May 26, 2023
1 parent bc931ce commit ea8865a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ All notable changes to this project will be documented in this file.
### Bug fixes

- Fix async mode inference for demo in exportable code (<https://github.com/openvinotoolkit/training_extensions/pull/2154>)
- Fix a bug that auto adapt batch size doesn't work with cls incr case (<https://github.com/openvinotoolkit/training_extensions/pull/2199>)

### Known issues

Expand Down
4 changes: 4 additions & 0 deletions otx/algorithms/common/adapters/mmcv/utils/automatic_bs.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ def __init__(self, fullset, num_samples: int):

self.fullset = fullset
self.num_samples = num_samples
self.img_indices = { # for class incremental case
"old": [i for i in range(num_samples // 2)],
"new": [i for i in range(num_samples // 2, num_samples)],
}

def __len__(self) -> int:
"""Get length of subset."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ def set_up(self, mocker):

def test_init(self, mocker):
fullset = mocker.MagicMock()
SubDataset(fullset, 3)
subset = SubDataset(fullset, 3)

# test for class incremental case. If below assert can't be passed, ClsIncrSampler can't work well.
assert len(subset.img_indices["new"]) / len(subset.img_indices["old"]) + 1 <= self.num_samples

@pytest.mark.parametrize("num_samples", [-1, 0])
def test_init_w_wrong_num_samples(self, mocker, num_samples):
Expand Down

0 comments on commit ea8865a

Please sign in to comment.