ZHKKKe / MODNet

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

Can we export pretrained model to TorchScript format? #38

Closed xpeng closed 3 years ago

xpeng commented 3 years ago

this is a great work, and have some advantages comparing to other models.

does there have TorchScript format model as BackgroundMatting project do? this will do much more check and performance benchmark work on other devices such as mobile, i think this project must has a wide perspective and huge potential.

@ZHKKKe thanks your work, waiting for future progress.

i try to use jit.save but it is not working:

modnet = MODNet(backbone_pretrained=False)
modnet = nn.DataParallel(modnet)
modnet.load_state_dict(torch.load(args.ckpt_path, map_location=torch.device('cpu')))
modnet.eval()
scriptmod = torch.jit.script(modnet)
torch.jit.save(scriptmod, "modnet.pt")
ZHKKKe commented 3 years ago

Hi, thanks for your attention.

We have not previously considered providing models in TorchScript format. Since there is a lot of demand for this right now, we will consider putting it on our schedule. If we have any updates on this, I will @ you under this issue.

LogWell commented 3 years ago

So at the moment, I can’t convert it to the C++ version and call it, right?

ZHKKKe commented 3 years ago

@LogWell We have not tried to do it. So I am not sure if now we can convert to the C++ version directly.

ZHKKKe commented 3 years ago

Hi, all,

I am sorry that now we do not plan to provide an official pretrained model with TorchScript format. Please let me know if you achieve this goal and want to share with the community. Thanks in advance.