diff --git a/deepface/detectors/FastMtCnn.py b/deepface/detectors/FastMtCnn.py index acc71f18..ee8e69c1 100644 --- a/deepface/detectors/FastMtCnn.py +++ b/deepface/detectors/FastMtCnn.py @@ -62,13 +62,16 @@ def build_model(self) -> Any: # this is not a must dependency. do not import it in the global level. try: from facenet_pytorch import MTCNN as fast_mtcnn + import torch except ModuleNotFoundError as e: raise ImportError( "FastMtcnn is an optional detector, ensure the library is installed." "Please install using 'pip install facenet-pytorch' " ) from e - face_detector = fast_mtcnn(device="cpu") + device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu') + face_detector = fast_mtcnn(device=device) + return face_detector