1.#git clone https://github.com/yangxy/GPEN.git
2.下载RetinaFace模型并放入weights目录:
weights压缩包下载地址:
链接: https://pan.baidu.com/s/11jTPTR9zA8ABE4pQGe5bIg 提取码: 3nvq
[email protected] weights % ls -ll
total 3809008
-rw-r–r–@ 1 hazz staff 96024689 3 21 11:48 GPEN-BFR-256-D.pth
-rw-r–r–@ 1 hazz staff 75573183 3 21 11:48 GPEN-BFR-256.pth
-rw-r–r–@ 1 hazz staff 115954608 3 21 11:49 GPEN-BFR-512-D.pth
-rw-r–r–@ 1 hazz staff 284085738 3 21 11:49 GPEN-BFR-512.pth
-rw-r–r–@ 1 hazz staff 284914645 3 21 11:50 GPEN-Colorization-1024.pth
-rw-r–r–@ 1 hazz staff 284914645 3 21 11:50 GPEN-Inpainting-1024.pth
-rw-r–r–@ 1 hazz staff 284085738 3 21 11:50 GPEN-Seg2face-512.pth
-rw-r–r–@ 1 hazz staff 85331193 3 21 11:48 ParseNet-latest.pth
-rw-r–r–@ 1 hazz staff 2625 3 15 02:15 README.md
-rw-r–r–@ 1 hazz staff 109497761 3 21 11:48 RetinaFace-R50.pth
-rw-r–r–@ 1 hazz staff 175367323 3 21 11:49 model_ir_se50.pth
-rw-r–r–@ 1 hazz staff 77228423 3 21 11:48 realesrnet_x2.pth
-rw-r–r–@ 1 hazz staff 77207687 3 21 11:48 realesrnet_x4.pth
3.四个用法
恢复面部图像:
#python3 demo.py --task FaceEnhancement --model GPEN-BFR-512 --in_size 512 --channel_multiplier 2 --narrow 1 --use_sr --sr_scale 4 --use_cuda --save_face --indir 1.JPG --outdir /Users/hazz/Downloads/GPEN-main/outs
为面孔着色:
#python demo.py --task FaceColorization --model GPEN-Colorization-1024 --in_size 1024 --use_cuda --indir examples/grays --outdir examples/outs-colorization
完整的面孔:
#python3 demo.py --task FaceInpainting --model GPEN-Inpainting-1024 --in_size 1024 --use_cuda --indir examples/ffhq-10 --outdir examples/outs-inpainting
#合成面孔:
python3 demo.py --task Segmentation2Face --model GPEN-Seg2face-512 --in_size 512 --use_cuda --indir examples/segs --outdir examples/outs-seg2face
4.使用帮助可以用run.sh 查看
常见错误:
报错1:
Traceback (most recent call last):
File “demo.py”, line 6, in
import cv2
import cv2时报错No module named ‘cv2‘如何解决
原因:缺少opencv-python中的cv2
opencv是一个开源BSD许可的库,包括数百种计算机视觉算法.
解决办法:
#pip3 install opencv-python
#import cv2
参考文章:https://docs.opencv.org/3.4/d6/d00/tutorial_py_root.html
报错2:
Traceback (most recent call last):
File “demo.py”, line 12, in
from PIL import Image, ImageDraw
ModuleNotFoundError: No module named ‘PIL’
原因缺少图像库文件: Image, ImageDraw
PIL是Fredrik Lundh和贡献者的Python成像库。
解决办法:
#python3 -m pip install --upgrade pip
#python3 -m pip install --upgrade Pillow
参考文章: https://pillow.readthedocs.io/en/latest/installation.html
报错3:
line 6, in
import torch
ModuleNotFoundError: No module named ‘torch’
原因:缺少PyTorch库,PyTorch是一个优化的张量库,用于使用GPU和CPU进行深度学习。
解决方法:
#pip3 install torch torchvision
参考文章: https://pytorch.org
报错4:
from skimage import transform as trans
ModuleNotFoundError: No module named ‘skimage’
缺少:scikit-image
scikit image是一组用于图像处理的算法.
解决方法:
#pip3 install scikit-image
参考文章:https://scikit-image.org
报错5:
raise AssertionError(“Torch not compiled with CUDA enabled”)
AssertionError: Torch not compiled with CUDA enabled
原因: 设置运行设备为GPU 但是本地的电脑没有GPU,可以修改成cpu
解决:
把启动参数里: –use_cuda 修改成 –use_cpu
device = torch.device(“cuda” if torch.cuda.is_available() else “cpu”)
参考文章:
https://pytorch.org
https://scikit-image.org
https://github.com/yangxy/GPEN.git
https://docs.opencv.org/3.4/d6/d00/tutorial_py_root.html
https://pillow.readthedocs.io/en/latest/installation.html