RobustVideoMatting icon indicating copy to clipboard operation
RobustVideoMatting copied to clipboard

Allow users to provide a custom video background

Open Ahuge opened this issue 3 years ago • 7 comments

This PR allows users to bring their own background image/imageSequence/video instead of the default green background.

It creates a new parameter in convert_video called bgr_source: Optional[str] = None that, when passed will attempt to load either an ImageSequenceReader, VideoReader, or an ImageReader.

I have moved the green background into a dummy class called ConstantImage which implements the Dataset interface so that it can be indexed into per frame.

Ahuge avatar Oct 15 '21 20:10 Ahuge

I don't know if you are accepting PRs on this repo. I just found this functionality useful and wanted to offer it upstream

Ahuge avatar Oct 15 '21 20:10 Ahuge

Right now I am very busy with other projects. I won't have time to review those pull requests. So I am just gonna leave them open for now.

PeterL1n avatar Oct 15 '21 20:10 PeterL1n

All good, thanks for the awesome research!

Ahuge avatar Oct 15 '21 22:10 Ahuge

thank you for your share

  1. the file inference.py line in 123 125: if (output_composition is not None) and (output_type == 'video'): if bgr_source is not None and os.path.isfile(bgr_source): if os.path.isfile(bgr_source): if os.path.splitext(bgr_source)[-1].lower() in [".png", ".jpg"]: bgr_raw = ImageReader(bgr_source, transform=transform) else: bgr_raw = VideoReader(bgr_source, transform) else: bgr_raw = ImageSequenceReader(bgr_source, transform) else: bgr_raw = ConstantImage(120, 255, 155, device=device, dtype=dtype)

the bgr' size should resize, make it equal to the source' size

  1. line in 148: bgr = bgr_raw[index].to(device, dtype, non_blocking=True).unsqueeze(0) # [B, T, C, H, W]

if seq_chunk>1, bgr shuld be batch, the batchsize equal to seq_chunk; and the last batch' batchsize is the remainder

  1. len(bgr_raw) should be greater than len(source),otherwise, it could throw exception the file inference_utils.py line 25: frame = self.video[idx]

chenying99 avatar Oct 31 '21 06:10 chenying99

thank you for your share

  1. the file inference.py line in 123 125: if (output_composition is not None) and (output_type == 'video'): if bgr_source is not None and os.path.isfile(bgr_source): if os.path.isfile(bgr_source): if os.path.splitext(bgr_source)[-1].lower() in [".png", ".jpg"]: bgr_raw = ImageReader(bgr_source, transform=transform) else: bgr_raw = VideoReader(bgr_source, transform) else: bgr_raw = ImageSequenceReader(bgr_source, transform) else: bgr_raw = ConstantImage(120, 255, 155, device=device, dtype=dtype)

the bgr' size should resize, make it equal to the source' size

  1. line in 148: bgr = bgr_raw[index].to(device, dtype, non_blocking=True).unsqueeze(0) # [B, T, C, H, W]

if seq_chunk>1, bgr shuld be batch, the batchsize equal to seq_chunk; and the last batch' batchsize is the remainder

  1. len(bgr_raw) should be greater than len(source),otherwise, it could throw exception the file inference_utils.py line 25: frame = self.video[idx]

thank you for your share! ! I have same question in it.When I input a background image, it always doesn't match. Do you have a solution?It would be a big breakthrough if you could help me......

xiami1234567890 avatar Aug 19 '22 05:08 xiami1234567890

RuntimeError: The size of tensor a (3) must match the size of tensor b (4) at non-singleton dimension 2

justforyourdream avatar Sep 29 '22 05:09 justforyourdream

@Ahuge @justforyourdream @chenying99 have you solved the issue? still not able to get results, its not matching with input size,fps & duration of video ,how to fix it

akashAD98 avatar Dec 14 '22 06:12 akashAD98