Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

failing to compute hair_mask with CDGnet #13

Closed
op10ds opened this issue Aug 28, 2023 · 3 comments
Closed

failing to compute hair_mask with CDGnet #13

op10ds opened this issue Aug 28, 2023 · 3 comments

Comments

@op10ds
Copy link

op10ds commented Aug 28, 2023

I am trying to pre-process custom data, by following your indications. For simplicity, i am using the monocular data provided by you in /monocular/person_0_image. I get an error when executing the command:

python preprocess_custom_data/calc_masks.py --scene_path ./implicit-hair-data/data/SCENE_TYPE/CASE/ --MODNET_ckpt path_to_modnet --CDGNET_ckpt path_to_cdgnet

calc_masks.py", line 159, in main
for key, nkey in zip(state_dict_old.keys(), state_dict.keys()):
RuntimeError: OrderedDict mutated during iteration

I tried to find a workaround by rewriting the lines from 156 to 164 like this (following the discussion here: https://github.com/pytorch/pytorch/issues/40859

current_model_dict = model.state_dict()
loaded_state_dict = torch.load(args.CDGNET_ckpt, map_location='cpu')
new_state_dict={k:v if v.size()==current_model_dict[k].size()  else  current_model_dict[k] for k,v in zip(current_model_dict.keys(), loaded_state_dict.values())}
model.load_state_dict(new_state_dict, strict=False)

and then the images are generated, but they are all black. So what am i missing?
By contrast, mask images via MODnet are generated succesfully.

@kenshi84
Copy link

I encountered the same issue, and was able to fix it by modifying the code as

     state_dict = model.state_dict().copy()
     state_dict_old = torch.load(args.CDGNET_ckpt, map_location='cpu')
 
-    for key, nkey in zip(state_dict_old.keys(), state_dict.keys()):
+    state_dict_keys = list(state_dict.keys())
+    for key, nkey in zip(state_dict_old.keys(), state_dict_keys):
         if key != nkey:
             # remove the 'module.' in the 'key'
             state_dict[key[7:]] = deepcopy(state_dict_old[key])

and then downloading a different version of LIP_epoch_149.pth from this Google Drive link, posted in tjpulkl/CDGNet#5.

Hope this helps!

@op10ds
Copy link
Author

op10ds commented Sep 12, 2023

Hi Kenshi,
yeah the checkpoint file you linked works well. The size is bigger than the one indicated by the authors, so that may be corrupted.
Thanks a lot.

@op10ds op10ds closed this as completed Sep 12, 2023
@peeloffskin
Copy link

I encountered the same issue, and was able to fix it by modifying the code as

     state_dict = model.state_dict().copy()
     state_dict_old = torch.load(args.CDGNET_ckpt, map_location='cpu')
 
-    for key, nkey in zip(state_dict_old.keys(), state_dict.keys()):
+    state_dict_keys = list(state_dict.keys())
+    for key, nkey in zip(state_dict_old.keys(), state_dict_keys):
         if key != nkey:
             # remove the 'module.' in the 'key'
             state_dict[key[7:]] = deepcopy(state_dict_old[key])

and then downloading a different version of LIP_epoch_149.pth from this Google Drive link, posted in tjpulkl/CDGNet#5.

Hope this helps!

我遇到了同样的问题,并能够通过修改代码来修复它,

     状态_dict =模型.状态_dict().复制()状态_dict_old =火炬.加载(args.CDGNET_ckpt,map_location ='cpu')-    对于key,nkey in zip(state_dict_old.keys(),state_dict.keys()):+    state_dict_keys = list(state_dict.keys())+    for key,nkey in zip(state_dict_old.keys(),state_dict_keys):if key!= nkey:#删除'模块。“在”key“state_dict[key[7:]] = deepcopy(state_dict_old[key])

,然后从这个Google Drive链接下载不同版本的LIP_epoch_149.pth,发布在tjpulkl/CDGNet#5

希望
这对你有帮助!

Can you provide me with a download link for LIP_epoch_149.pth?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants