• ‘face_alignment‘ has no attribute ‘FaceAlignment‘


    最近需要提取人脸landmark,使用的是face-alignment:https://github.com/1adrianb/face-alignment

    发现按照作者给出的Binaries 

    安装方式总会报错

    'face_alignment' has no attribute 'FaceAlignment'

    因此切换为从source安装。

    如果使用的是服务器,且没有root权限,那么最好为创建一个face-alignment的环境再安装。

    1. # 环境搭建
    2. git clone https://github.com/1adrianb/face-alignment
    3. cd face_alignment
    4. conda create -n FaceAlign python=3.7 # 这里版本任意3.5+即可
    5. conda activate FaceAlign
    6. pip install torch==1.12.1+cu116 torchvision==0.13.1+cu116 torchaudio==0.12.1 --extra-index-url https://download.pytorch.org/whl/cu116
    7. # 以下包按需安装
    8. conda install matplotlib
    9. conda install -c conda-forge ffmpeg
    10. conda install -c conda-forge opencv
    11. # 安装face_alignment
    12. pip install -r requirements.txt
    13. conda install -c 1adrianb face_alignment
    14. python setup.py install

    codes of get landmarks

    1. import face_alignment
    2. from skimage import io
    3. fa = face_alignment.FaceAlignment(face_alignment.LandmarksType.TWO_D, flip_input=False)
    4. input = io.imread('/home/wyw/tes_imgs/src_0.jpg')
    5. preds = fa.get_landmarks(input)
    6. print(preds)

    运行后会先下载模型,然后输出landmarks,为68组坐标。

    1. $ CUDA_VISIBLE_DEVICES=9 python3 face_alignment.py
    2. Downloading: "https://www.adrianbulat.com/downloads/python-fan/s3fd-619a316812.pth" to /home/wyw/.cache/torch/hub/checkpoints/s3fd-619a316812.pth
    3. 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 85.7M/85.7M [1:24:15<00:00, 17.8kB/s]
    4. Downloading: "https://www.adrianbulat.com/downloads/python-fan/2DFAN4-cd938726ad.zip" to /home/wyw/.cache/torch/hub/checkpoints/2DFAN4-cd938726ad.zip
    5. 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 91.9M/91.9M [1:19:52<00:00, 20.1kB/s]
    6. [array([[ 59., 119.],
    7. [ 59., 135.],
    8. [ 64., 153.],
    9. [ 66., 169.],
    10. [ 75., 182.],
    11. [ 84., 194.],
    12. [ 98., 198.],
    13. [111., 203.],
    14. [131., 207.],
    15. [154., 203.],
    16. [167., 200.],
    17. [179., 194.],
    18. [188., 182.],
    19. [194., 167.],
    20. [197., 151.],
    21. [199., 133.],
    22. [201., 117.],
    23. [ 77., 88.],
    24. [ 84., 79.],
    25. [ 95., 74.],
    26. [104., 74.],
    27. [113., 77.],
    28. [147., 77.],
    29. [156., 74.],
    30. [165., 74.],
    31. [176., 79.],
    32. [185., 88.],
    33. [131., 97.],
    34. [131., 108.],
    35. [134., 117.],
    36. [134., 126.],
    37. [120., 137.],
    38. [127., 137.],
    39. [134., 140.],
    40. [138., 137.],
    41. [143., 137.],
    42. [ 91., 101.],
    43. [ 98., 97.],
    44. [104., 97.],
    45. [113., 101.],
    46. [107., 104.],
    47. [ 98., 104.],
    48. [147., 101.],
    49. [156., 97.],
    50. [163., 99.],
    51. [170., 101.],
    52. [165., 104.],
    53. [154., 104.],
    54. [111., 164.],
    55. [118., 158.],
    56. [129., 151.],
    57. [134., 153.],
    58. [138., 151.],
    59. [147., 158.],
    60. [156., 164.],
    61. [149., 171.],
    62. [140., 173.],
    63. [134., 173.],
    64. [125., 173.],
    65. [120., 169.],
    66. [111., 164.],
    67. [127., 160.],
    68. [134., 160.],
    69. [140., 160.],
    70. [154., 164.],
    71. [140., 164.],
    72. [134., 164.],
    73. [127., 164.]], dtype=float32)]

  • 相关阅读:
    Android Fragment动画实现
    Vue封装的过度与动画,脚手架配置代理, slot插槽
    Java循环结构-for语句、while语句详解
    TI/德州仪器 CSD86350Q5D 同步降压 集成电路
    使用hutool工具发送带附件的邮件(特简单)
    大话设计模式学习笔记
    微信小程序_19,自定义组件-behaviors
    SpringBoot结合SpringCache操作Redis实现数据缓存
    编译一日一练(DIY系列之汇编优化)
    手把手教你通过PaddleHub快速实现输入中/英文本生成图像(Stable Diffusion)
  • 原文地址:https://blog.csdn.net/qq_27901917/article/details/134266390