Merge pull request #1145 from common-io/master

FastMtCnn Use of Gpu for Face Detection
This commit is contained in:
Sefik Ilkin Serengil 2024-04-05 16:35:56 +01:00 committed by GitHub
commit 1b60cf210d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -62,13 +62,16 @@ class FastMtCnnClient(Detector):
# this is not a must dependency. do not import it in the global level. # this is not a must dependency. do not import it in the global level.
try: try:
from facenet_pytorch import MTCNN as fast_mtcnn from facenet_pytorch import MTCNN as fast_mtcnn
import torch
except ModuleNotFoundError as e: except ModuleNotFoundError as e:
raise ImportError( raise ImportError(
"FastMtcnn is an optional detector, ensure the library is installed." "FastMtcnn is an optional detector, ensure the library is installed."
"Please install using 'pip install facenet-pytorch' " "Please install using 'pip install facenet-pytorch' "
) from e ) 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 return face_detector