mirror of
https://github.com/yakhyo/uniface.git
synced 2025-12-30 09:02:25 +00:00
make emotion module optional to avoid pytorch dependency
This commit is contained in:
@@ -21,7 +21,11 @@ from uniface.log import Logger, enable_logging
|
|||||||
from uniface.model_store import verify_model_weights
|
from uniface.model_store import verify_model_weights
|
||||||
from uniface.visualization import draw_detections
|
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 .detection import SCRFD, RetinaFace, create_detector, detect_faces, list_available_detectors
|
||||||
from .landmark import Landmark106, create_landmarker
|
from .landmark import Landmark106, create_landmarker
|
||||||
from .recognition import ArcFace, MobileFace, SphereFace, create_recognizer
|
from .recognition import ArcFace, MobileFace, SphereFace, create_recognizer
|
||||||
|
|||||||
@@ -6,10 +6,17 @@ from typing import Dict, Any, List, Union
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from uniface.attribute.age_gender import AgeGender
|
from uniface.attribute.age_gender import AgeGender
|
||||||
from uniface.attribute.emotion import Emotion
|
|
||||||
from uniface.attribute.base import Attribute
|
from uniface.attribute.base import Attribute
|
||||||
from uniface.constants import AgeGenderWeights, DDAMFNWeights
|
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
|
# Public API for the attribute module
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"AgeGender",
|
"AgeGender",
|
||||||
@@ -21,9 +28,12 @@ __all__ = [
|
|||||||
# A mapping from model enums to their corresponding attribute classes
|
# A mapping from model enums to their corresponding attribute classes
|
||||||
_ATTRIBUTE_MODELS = {
|
_ATTRIBUTE_MODELS = {
|
||||||
**{model: AgeGender for model in AgeGenderWeights},
|
**{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(
|
def create_attribute_predictor(
|
||||||
model_name: Union[AgeGenderWeights, DDAMFNWeights],
|
model_name: Union[AgeGenderWeights, DDAMFNWeights],
|
||||||
|
|||||||
Reference in New Issue
Block a user