Skip to content

Commit

Permalink
raise legible error message for optional import
Browse files Browse the repository at this point in the history
  • Loading branch information
serengil committed Dec 8, 2023
1 parent fceeccb commit adfb29d
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions deepface/detectors/DlibWrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@

logger = Logger(module="detectors.DlibWrapper")


def build_model():

home = functions.get_deepface_home()

import dlib # this requirement is not a must that's why imported here
# this is not a must dependency. do not import it in the global level.
try:
import dlib
except ModuleNotFoundError as e:
raise ImportError(
"Dlib is an optional detector, ensure the library is installed."
"Please install using 'pip install dlib' "
) from e

# check required file exists in the home/.deepface/weights folder
if os.path.isfile(home + "/.deepface/weights/shape_predictor_5_face_landmarks.dat") != True:
Expand Down Expand Up @@ -40,7 +48,14 @@ def build_model():

def detect_face(detector, img, align=True):

import dlib # this requirement is not a must that's why imported here
# this is not a must dependency. do not import it in the global level.
try:
import dlib
except ModuleNotFoundError as e:
raise ImportError(
"Dlib is an optional detector, ensure the library is installed."
"Please install using 'pip install dlib' "
) from e

resp = []

Expand Down

0 comments on commit adfb29d

Please sign in to comment.