diff --git a/ppgan/faceutils/dlibutils/dlib_utils.py b/ppgan/faceutils/dlibutils/dlib_utils.py index eca5ba68e8806eec9bf190a58a0a96c12e514127..665276da0a5d0acfa18c8de852c20b138b3d0eec 100644 --- a/ppgan/faceutils/dlibutils/dlib_utils.py +++ b/ppgan/faceutils/dlibutils/dlib_utils.py @@ -17,7 +17,7 @@ import os.path as osp import numpy as np from PIL import Image -import dlib +from paddle.utils import try_import import cv2 from ..image import resize_by_max from paddle.utils.download import get_weights_path_from_url @@ -26,6 +26,7 @@ LANDMARKS_WEIGHT_URL = 'https://paddlegan.bj.bcebos.com/models/lms.dat' def detect(image: Image): + dlib = try_import('dlib') image = np.asarray(image) h, w = image.shape[:2] image = resize_by_max(image, 361) @@ -43,6 +44,7 @@ def detect(image: Image): def crop(image: Image, face, up_ratio, down_ratio, width_ratio): + dlib = try_import('dlib') width, height = image.size face_height = face.height() face_width = face.width() @@ -96,6 +98,7 @@ def crop(image: Image, face, up_ratio, down_ratio, width_ratio): def crop_by_image_size(image: Image, face): + dlib = try_import('dlib') center = face.center() width, height = image.size if width > height: @@ -123,6 +126,7 @@ def crop_by_image_size(image: Image, face): def landmarks(image: Image, face): + dlib = try_import('dlib') weight_path = get_weights_path_from_url(LANDMARKS_WEIGHT_URL) predictor = dlib.shape_predictor(weight_path) shape = predictor(np.asarray(image), face).parts() @@ -130,6 +134,7 @@ def landmarks(image: Image, face): def crop_from_array(image: np.array, face): + dlib = try_import('dlib') ratio = 0.20 / 0.85 # delta_size / face_size height, width = image.shape[:2] face_height = face.height() diff --git a/requirements.txt b/requirements.txt index 6f6de9a77f009d0911ea1699d15ad6a4bf9852f5..2816f6be1834c8b8dc10b9cd0a5de48ba1f9614c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,3 @@ scikit-image>=0.14.0 scipy>=1.1.0 opencv-python imageio-ffmpeg -dlib diff --git a/setup.py b/setup.py index 54c197caa33d24ebc003bff793fc56e0253186f8..a5e63930651d9a6ac79d1b2cf5e1f9cb74099fca 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ from setuptools import setup from io import open -with open('requirments.txt', encoding="utf-8-sig") as f: +with open('requirements.txt', encoding="utf-8-sig") as f: requirements = f.readlines()