ygtxr1997 / CelebBasis

Official Implementation of 'Inserting Anybody in Diffusion Models via Celeb Basis'
https://celeb-basis.github.io/
MIT License
252 stars 7 forks source link

00_align_face.sh errors out due to hardcoded paths and missing weights/.pth(s) #2

Closed mjdi closed 1 year ago

mjdi commented 1 year ago

I get the following error running bash 00_align_face.sh <...>/ori <...>/ffhq

(sd) wsl@MJDFW:~/repos/CelebBasis$ bash 00_align_face.sh /home/wsl/repos/CelebBasis/my_imgs/ori/ /home/wsl/repos/CelebBasis/my_imgs/ffhq/
running build_ext
skipping 'nms/cpu_nms.c' Cython extension (up-to-date)
Traceback (most recent call last):
  File "./evaluation/face_align/PIPNet/start_align.py", line 85, in <module>
    main(opt)
  File "./evaluation/face_align/PIPNet/start_align.py", line 35, in main
    folder_dataset = FolderAlignCrop(
  File "/home/wsl/repos/CelebBasis/evaluation/face_align/PIPNet/alignment/dataloader.py", line 40, in __init__
    self.net, self.detector = get_lmk_model()
  File "/home/wsl/repos/CelebBasis/evaluation/face_align/PIPNet/lib/tools.py", line 62, in get_lmk_model
    state_dict = torch.load(weight_file, map_location=device)
  File "/home/wsl/anaconda3/envs/sd/lib/python3.8/site-packages/torch/serialization.py", line 594, in load
    with _open_file_like(f, 'rb') as opened_file:
  File "/home/wsl/anaconda3/envs/sd/lib/python3.8/site-packages/torch/serialization.py", line 230, in _open_file_like
    return _open_file(name_or_buffer, mode)
  File "/home/wsl/anaconda3/envs/sd/lib/python3.8/site-packages/torch/serialization.py", line 211, in __init__
    super(_open_file, self).__init__(open(name, mode))
FileNotFoundError: [Errno 2] No such file or directory: '/gavin/code/FaceSwapping/inference/PIPNet/weights/epoch59.pth'

due to the hardcoded paths in the get_lmk_model() function in evaluation/face_align/PIPNet/lib/tools.py as seen here

wsl@MJDFW_~reposCelebBasis_10_56_01

As we can see here, there should be PIPNet weights (and epoch59.pth ?) which need to be downloaded (and instructions for doing so in the README.md)

wsl@MJDFW_~reposCelebBasisevaluationface_alignPIPN_11_04_53

Please advise, thanks!

justindujardin commented 1 year ago

You need to add the weights files from your screenshot somewhere and fix the paths:

ygtxr1997 commented 1 year ago

We use PIPNet to align and crop the face, but missed their weight files. You may visit PIPNet repo to download the missing weight files or using the files provided by @justindujardin . These files can also be downloaded from our Baidu Yun Drive with extracting code ygss. We'll fix the hardcoded file paths ASAP!

aiXander commented 1 year ago

Just updating the paths to relative paths (after putting the weight files there) works:

evaluation/face_align/PIPNet/lib/tools.py line 60:

    weight_file = 'evaluation/face_align/PIPNet/weights/epoch59.pth'
    state_dict = torch.load(weight_file, map_location=device)
    net.load_state_dict(state_dict)

    detector = FaceBoxesDetector(
        "FaceBoxes",
        "evaluation/face_align/PIPNet/weights/FaceBoxesV2.pth",
        use_gpu=True,
        device="cuda:0",
    )
aiXander commented 1 year ago

This entire section of code is also full of hardcoded paths: https://github.com/ygtxr1997/CelebBasis/blob/main/scripts/stable_txt2img.py#L272

ygtxr1997 commented 1 year ago

Just updating the paths to relative paths (after putting the weight files there) works:

evaluation/face_align/PIPNet/lib/tools.py line 60:

    weight_file = 'evaluation/face_align/PIPNet/weights/epoch59.pth'
    state_dict = torch.load(weight_file, map_location=device)
    net.load_state_dict(state_dict)

    detector = FaceBoxesDetector(
        "FaceBoxes",
        "evaluation/face_align/PIPNet/weights/FaceBoxesV2.pth",
        use_gpu=True,
        device="cuda:0",
    )
  1. Code updated, https://github.com/ygtxr1997/CelebBasis/commit/82fdc0eb1b5b93bff5704ba14fda04420eaa19e0.

This entire section of code is also full of hardcoded paths: https://github.com/ygtxr1997/CelebBasis/blob/main/scripts/stable_txt2img.py#L272

  1. For stable_txt2img.py#L272, these hardcoded paths are not used under the default setting. We consider removing these codes or adding the relevant testing options.