ZHKKKe / MODNet

A Trimap-Free Portrait Matting Solution in Real Time [AAAI 2022]
Apache License 2.0
3.84k stars 636 forks source link

Matte L1 Loss Maybe have some wrong ? #73

Closed FinnChou closed 3 years ago

FinnChou commented 3 years ago

https://github.com/ZHKKKe/MODNet/blob/44667be551eff6427e774b60e3b251f90b9dac61/src/trainer.py#L162

calculate matte boundary (or detail) Loss value, we should using pred_boundary_matte and gt_detail (Not gt_matte) , right?

https://github.com/ZHKKKe/MODNet/blob/44667be551eff6427e774b60e3b251f90b9dac61/src/trainer.py#L156 https://github.com/ZHKKKe/MODNet/blob/44667be551eff6427e774b60e3b251f90b9dac61/src/trainer.py#L161

FinnChou commented 3 years ago

matte_compositional_loss seem to has same problem

https://github.com/ZHKKKe/MODNet/blob/44667be551eff6427e774b60e3b251f90b9dac61/src/trainer.py#L163-L164

I think it should be

 matte_compositional_loss = F.l1_loss(image * pred_matte, image * gt_matte) \ 
          + 4.0 * F.l1_loss(image * pred_boundary_matte, image * gt_detail) 

right?

ZHKKKe commented 3 years ago

Hi, thanks for your attentions.

Nope. In our code, gt_detail is the same as gt_matte. The foreground and the background regions in pred_boundary_matte are the same as trimap, i.e., the same as gt_matte. Therefore, the loss term F.l1_loss(image * pred_boundary_matte, image * gt_detail) is only be calculated on the boundary regions.

FinnChou commented 3 years ago

Thanks for your reply!