PeterL1n / RobustVideoMatting

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

Weird results when use Segmentation Pass for inference #123

Closed luuil closed 2 years ago

luuil commented 2 years ago

https://github.com/PeterL1n/RobustVideoMatting/blob/f8a26e27198a93a94bfd06e96b8d5a34d0660f81/inference.py#L127

I changed this line to use Segmentation Pass. (use the pretrained weights rvm_mobilenetv3.pth)

pha, *rec = model(src, *rec, segmentation_pass=True)
fgr = src * pha

But I got weird mask results, something like this, why?

seg_pass_alpha

PeterL1n commented 2 years ago

Try pha.sigmoid(), aka fgr = src * pha.sigmoid(). Because the segmentation pass outputs logits. You need a sigmoid to convert it to 0-1 range.

luuil commented 2 years ago

Thank you for your prompt reply. You are right, now the result is correct.

FengMu1995 commented 2 years ago

is it necessary to change "pha.sigmoid()" for the train module """ pred_seg = self.model_ddp(true_img, segmentation_pass=True)[0] loss = segmentation_loss(pred_seg, true_seg) """

vacing commented 1 year ago

is it necessary to change "pha.sigmoid()" for the train module

it seems not necessary

https://zhang-yang.medium.com/how-is-pytorchs-binary-cross-entropy-with-logits-function-related-to-sigmoid-and-d3bd8fb080e7