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

[Feature] Add argument 'repeat' to SRREDSMultipleGTDataset #672

Merged
merged 4 commits into from
Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
pipeline=test_pipeline,
scale=4,
val_partition='REDS4',
repeat=2,
test_mode=True),
# test
test=dict(
Expand Down
11 changes: 11 additions & 0 deletions mmedit/datasets/sr_reds_multiple_gt_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class SRREDSMultipleGTDataset(BaseSRDataset):
scale (int): Upsampling scale ratio.
val_partition (str): Validation partition mode. Choices ['official' or
'REDS4']. Default: 'official'.
repeat (int): Number of replication of the validation set. This is used
to allow training REDS4 with more than 4 GPUs. For example, if
8 GPUs are used, this number can be set to 2. Default: 1.
test_mode (bool): Store `True` when building test dataset.
Default: `False`.
"""
Expand All @@ -30,7 +33,14 @@ def __init__(self,
pipeline,
scale,
val_partition='official',
repeat=1,
test_mode=False):

self.repeat = repeat
if not isinstance(repeat, int):
raise TypeError('"repeat" must be an integer, but got '
f'{type(repeat)}.')

super().__init__(pipeline, scale, test_mode)
self.lq_folder = str(lq_folder)
self.gt_folder = str(gt_folder)
Expand Down Expand Up @@ -58,6 +68,7 @@ def load_annotations(self):

if self.test_mode:
keys = [v for v in keys if v in val_partition]
keys *= self.repeat
else:
keys = [v for v in keys if v not in val_partition]

Expand Down
31 changes: 31 additions & 0 deletions tests/test_data/test_datasets/test_sr_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,37 @@ def test_sr_reds_multiple_gt_dataset():
sequence_length=100,
num_input_frames=5)

# REDS4 val partition (repeat > 1)
reds_dataset = SRREDSMultipleGTDataset(
lq_folder=root_path,
gt_folder=root_path,
num_input_frames=5,
pipeline=[],
scale=4,
val_partition='REDS4',
repeat=2,
test_mode=True)

assert len(reds_dataset.data_infos) == 8 # 4 test clips
assert reds_dataset.data_infos[5] == dict(
lq_path=str(root_path),
gt_path=str(root_path),
key='011',
sequence_length=100,
num_input_frames=5)

# REDS4 val partition (repeat != int)
with pytest.raises(TypeError):
SRREDSMultipleGTDataset(
lq_folder=root_path,
gt_folder=root_path,
num_input_frames=5,
pipeline=[],
scale=4,
val_partition='REDS4',
repeat=1.5,
test_mode=True)


def test_sr_vimeo90k_mutiple_gt_dataset():
root_path = Path(__file__).parent.parent.parent / 'data/vimeo90k'
Expand Down