PeterL1n / RobustVideoMatting

Robust Video Matting in PyTorch, TensorFlow, TensorFlow.js, ONNX, CoreML!
https://peterl1n.github.io/RobustVideoMatting/
GNU General Public License v3.0
8.64k stars 1.14k forks source link

convert_video() png_sequence set backgroud #179

Open SowisLiuYiming opened 2 years ago

SowisLiuYiming commented 2 years ago

调用 convert_video( ),输入为图片路径,输出的图片是透明背景,是否有办法更换背景为黑色背景

Super-six-java commented 1 year ago

convert_vedio()怎么使用图片序列啊,我这边一直报错

  0%|                                                                   | 0/208 [00:00<?, ?it/s]Traceback (most recent call last):
  File "/home/code/unet_deeplab/RobustVideoMatting/inference.py", line 193, in <module>
    converter.convert(
  File "/home/code/unet_deeplab/RobustVideoMatting/inference.py", line 169, in convert
    convert_video(self.model, device=self.device, dtype=torch.float32, *args, **kwargs)
  File "/home/code/unet_deeplab/RobustVideoMatting/inference.py", line 127, in convert_video
    fgr, pha, *rec = model(src, *rec, downsample_ratio)
  File "/home/anaconda3/envs/bytedance/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1051, in _call_impl
    return forward_call(*input, **kwargs)
RuntimeError: The following operation failed in the TorchScript interpreter.
Traceback of TorchScript (most recent call last):
  File "/home/code/unet_deeplab/RobustVideoMatting/model/model.py", line 54, in forward
            src_sm = src

        f1, f2, f3, f4 = self.backbone(src_sm)
                         ~~~~~~~~~~~~~ <--- HERE
        f4 = self.aspp(f4)
        hid, *rec = self.decoder(src_sm, f1, f2, f3, f4, r1, r2, r3, r4)
  File "/home/code/unet_deeplab/RobustVideoMatting/model/resnet.py", line 43, in forward
    def forward(self, x):
        if x.ndim == 5:
            return self.forward_time_series(x)
                   ~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
        else:
            return self.forward_single_frame(x)
  File "/home/code/unet_deeplab/RobustVideoMatting/model/resnet.py", line 37, in forward_time_series
    def forward_time_series(self, x):
        B, T = x.shape[:2]
        features = self.forward_single_frame(x.flatten(0, 1))
                   ~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
        features = [f.unflatten(0, (B, T)) for f in features]
        return features
  File "/home/code/unet_deeplab/RobustVideoMatting/model/resnet.py", line 21, in forward_single_frame
    def forward_single_frame(self, x):
        x = self.conv1(x)
            ~~~~~~~~~~ <--- HERE
        x = self.bn1(x)
        x = self.relu(x)
  File "/home/anaconda3/envs/bytedance/lib/python3.9/site-packages/torch/nn/modules/conv.py", line 443, in forward
    def forward(self, input: Tensor) -> Tensor:
        return self._conv_forward(input, self.weight, self.bias)
               ~~~~~~~~~~~~~~~~~~ <--- HERE
  File "/home/anaconda3/envs/bytedance/lib/python3.9/site-packages/torch/nn/modules/conv.py", line 439, in _conv_forward
                            weight, bias, self.stride,
                            _pair(0), self.dilation, self.groups)
        return F.conv2d(input, weight, bias, self.stride,
               ~~~~~~~~ <--- HERE
                        self.padding, self.dilation, self.groups)
RuntimeError: Given groups=1, weight of size [64, 3, 7, 7], expected input[1, 1, 409, 512] to have 3 channels, but got 1 channels instead

Exception ignored in: <function tqdm.__del__ at 0x7f6bcf1e55e0>
Traceback (most recent call last):
  File "/home/anaconda3/envs/bytedance/lib/python3.9/site-packages/tqdm/std.py", line 1145, in __del__
  File "/home/anaconda3/envs/bytedance/lib/python3.9/site-packages/tqdm/std.py", line 1299, in close
  File "/home/anaconda3/envs/bytedance/lib/python3.9/site-packages/tqdm/std.py", line 1492, in display
  File "/home/anaconda3/envs/bytedance/lib/python3.9/site-packages/tqdm/std.py", line 1148, in __str__
  File "/home/anaconda3/envs/bytedance/lib/python3.9/site-packages/tqdm/std.py", line 1450, in format_dict
TypeError: cannot unpack non-iterable NoneType object

我是用的启动命令

python3 inference.py \
    --variant resnet50 \
    --checkpoint "./checkpoint/rvm_resnet50.pth" \
    --device cuda \
    --input-source "./input/png_sequence/1次处理/" \
    --output-type png_sequence \
    --output-composition "./output/png_sequence/test1/composition/" \
    --output-alpha "./output/png_sequence/test1/alpha/" \
    --output-foreground "./output/png_sequence/test1/foreground/" \
    --output-video-mbps 4 \
    --seq-chunk 1