UniFace: A Unified Face Analysis Library for Python | Detection, alignment, landmarks, face-mesh, recognition, parsing, gaze, attributes and anti-spoofing under one API.
Python computer-visiondeep-learningface-alignmentface-analysisface-anonymizationface-anti-spoofingface-attributesface-detectionface-meshface-parsingface-quality-assessmentface-recognitionface-segmentationface-trackingfacial-landmarksgaze-estimationhead-pose-estimationonnxruntimeportrait-mattingpython
make emotion module optional to avoid pytorch dependency
yakhyo0aea17d14de5
diff --git a/uniface/__init__.py b/uniface/__init__.pyindex 351da5d..b632757 100644--- a/uniface/__init__.py+++ b/uniface/__init__.py@@ -21,7 +21,11 @@ from uniface.log import Logger, enable_loggingfrom uniface.model_store import verify_model_weightsfrom uniface.visualization import draw_detections-from .attribute import AgeGender, Emotion+from .attribute import AgeGender+try:+ from .attribute import Emotion+except ImportError:+ Emotion = None # PyTorch not installedfrom .detection import SCRFD, RetinaFace, create_detector, detect_faces, list_available_detectorsfrom .landmark import Landmark106, create_landmarkerfrom .recognition import ArcFace, MobileFace, SphereFace, create_recognizerdiff --git a/uniface/attribute/__init__.py b/uniface/attribute/__init__.pyindex eda6dbd..62bb82d 100644--- a/uniface/attribute/__init__.py+++ b/uniface/attribute/__init__.py@@ -6,10 +6,17 @@ from typing import Dict, Any, List, Unionimport numpy as npfrom uniface.attribute.age_gender import AgeGender-from uniface.attribute.emotion import Emotionfrom uniface.attribute.base import Attributefrom uniface.constants import AgeGenderWeights, DDAMFNWeights+# Emotion requires PyTorch - make it optional+try:+ from uniface.attribute.emotion import Emotion+ _EMOTION_AVAILABLE = True+except ImportError:+ Emotion = None+ _EMOTION_AVAILABLE = False+# Public API for the attribute module__all__ = ["AgeGender",@@ -21,9 +28,12 @@ __all__ = [# A mapping from model enums to their corresponding attribute classes_ATTRIBUTE_MODELS = {**{model: AgeGender for model in AgeGenderWeights},- **{model: Emotion for model in DDAMFNWeights}}+# Add Emotion models only if PyTorch is available+if _EMOTION_AVAILABLE:+ _ATTRIBUTE_MODELS.update({model: Emotion for model in DDAMFNWeights})+def create_attribute_predictor(model_name: Union[AgeGenderWeights, DDAMFNWeights],