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] Support different filename templates in GenerateSegmentIndices #325

Merged
merged 7 commits into from
May 24, 2021
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
6 changes: 5 additions & 1 deletion demo/restoration_video_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ def parse_args():
parser.add_argument('checkpoint', help='checkpoint file')
parser.add_argument('input_dir', help='directory of the input video')
parser.add_argument('output_dir', help='directory of the output video')
parser.add_argument(
'--filename_tmpl',
default='{:08d}.png',
help='template of the file names')
parser.add_argument(
'--window_size',
type=int,
Expand All @@ -30,7 +34,7 @@ def main():
args.config, args.checkpoint, device=torch.device('cuda', args.device))

output = restoration_video_inference(model, args.input_dir,
args.window_size)
args.window_size, args.filename_tmpl)
for i in range(0, output.size(1)):
output_i = output[:, i, :, :, :]
output_i = tensor2img(output_i)
Expand Down
8 changes: 6 additions & 2 deletions mmedit/apis/restoration_video_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def pad_sequence(data, window_size):
return data


def restoration_video_inference(model, img_dir, window_size):
def restoration_video_inference(model, img_dir, window_size, filename_tmpl):
innerlee marked this conversation as resolved.
Show resolved Hide resolved
"""Inference image with the model.

innerlee marked this conversation as resolved.
Show resolved Hide resolved
Args:
Expand All @@ -31,11 +31,15 @@ def restoration_video_inference(model, img_dir, window_size):
Returns:
Tensor: The predicted restoration result.
"""

device = next(model.parameters()).device # model device

# pipeline
test_pipeline = [
dict(type='GenerateSegmentIndices', interval_list=[1]),
dict(
type='GenerateSegmentIndices',
interval_list=[1],
filename_tmpl=filename_tmpl),
dict(
type='LoadImageFromFileList',
io_backend='disk',
Expand Down
8 changes: 5 additions & 3 deletions mmedit/datasets/pipelines/augmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -927,10 +927,12 @@ class GenerateSegmentIndices:
interval_list (list[int]): Interval list for temporal augmentation.
It will randomly pick an interval from interval_list and sample
frame index with the interval.
filename_tmpl (str): Template for file name. Default: '{:08d}.png'.
"""

def __init__(self, interval_list):
def __init__(self, interval_list, filename_tmpl='{:08d}.png'):
self.interval_list = interval_list
self.filename_tmpl = filename_tmpl

def __call__(self, results):
"""Call function.
Expand Down Expand Up @@ -964,11 +966,11 @@ def __call__(self, results):
lq_path_root = results['lq_path']
gt_path_root = results['gt_path']
lq_path = [
osp.join(lq_path_root, clip_name, f'{v:08d}.png')
osp.join(lq_path_root, clip_name, self.filename_tmpl.format(v))
for v in neighbor_list
]
gt_path = [
osp.join(gt_path_root, clip_name, f'{v:08d}.png')
osp.join(gt_path_root, clip_name, self.filename_tmpl.format(v))
for v in neighbor_list
]

Expand Down