ZHKKKe / MODNet

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

error occured when run on windows cpu #14

Closed zhangyunming closed 3 years ago

zhangyunming commented 3 years ago

hi, because there is no GPU on my windows pc, so i change the GPU to cpu by :

企业微信截图_16076615348073 and chang the code in imagematting/inference.py line 98: , _, matte = modnet(im.cpu(), inference=False)

but error occured as: 企业微信截图_16076616854716

my torch-cpu=1.6.0 thanks.

ZHKKKe commented 3 years ago

Hi. Thanks for your attention.

Our pre-trained models are wrapped by nn.DataParallel. For your problem, you may need to load the ckpt file by using:

model.load_state_dict(torch.load(args.ckpt_path, map_location=torch.device('cpu'))['module'])

Thank you for pointing it out. We will soon improve the code to make it compatible with cpu.

zhangyunming commented 3 years ago
###for cpu
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()

just ok above.  i delete  modnet = nn.DataParallel(modnet).
thanks
ZHKKKe commented 3 years ago

Yes. This is another solution. Good job :)