From 0aea17d14de567452f4a1e557391ffffa2278aff Mon Sep 17 00:00:00 2001 From: yakhyo Date: Sat, 8 Nov 2025 01:33:42 +0900 Subject: [PATCH] make emotion module optional to avoid pytorch dependency --- uniface/__init__.py | 6 +++++- uniface/attribute/__init__.py | 14 ++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/uniface/__init__.py b/uniface/__init__.py index 351da5d..b632757 100644 --- a/uniface/__init__.py +++ b/uniface/__init__.py @@ -21,7 +21,11 @@ from uniface.log import Logger, enable_logging from uniface.model_store import verify_model_weights from 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 installed from .detection import SCRFD, RetinaFace, create_detector, detect_faces, list_available_detectors from .landmark import Landmark106, create_landmarker from .recognition import ArcFace, MobileFace, SphereFace, create_recognizer diff --git a/uniface/attribute/__init__.py b/uniface/attribute/__init__.py index eda6dbd..62bb82d 100644 --- a/uniface/attribute/__init__.py +++ b/uniface/attribute/__init__.py @@ -6,10 +6,17 @@ from typing import Dict, Any, List, Union import numpy as np from uniface.attribute.age_gender import AgeGender -from uniface.attribute.emotion import Emotion from uniface.attribute.base import Attribute from 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],