__init__.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # Copyright 2025 Yakhyokhuja Valikhujaev
  2. # Author: Yakhyokhuja Valikhujaev
  3. # GitHub: https://github.com/yakhyo
  4. from .base import BaseRecognizer
  5. from .models import ArcFace, MobileFace, SphereFace
  6. def create_recognizer(method: str = 'arcface', **kwargs) -> BaseRecognizer:
  7. """
  8. Factory function to create face recognizers.
  9. This function initializes and returns a face recognizer instance based on the
  10. specified method. It acts as a high-level interface to the underlying
  11. model classes like ArcFace, MobileFace, etc.
  12. Args:
  13. method (str): The recognition method to use.
  14. Options: 'arcface' (default), 'mobileface', 'sphereface'.
  15. **kwargs: Model-specific parameters passed to the recognizer's constructor.
  16. For example, `model_name` can be used to select a specific
  17. pre-trained weight from the available enums (e.g., `ArcFaceWeights.MNET`).
  18. Returns:
  19. BaseRecognizer: An initialized recognizer instance ready for use.
  20. Raises:
  21. ValueError: If the specified `method` is not supported.
  22. Examples:
  23. >>> # Create the default ArcFace recognizer
  24. >>> recognizer = create_recognizer()
  25. >>> # Create a specific MobileFace recognizer
  26. >>> from uniface.constants import MobileFaceWeights
  27. >>> recognizer = create_recognizer(
  28. ... 'mobileface',
  29. ... model_name=MobileFaceWeights.MNET_V2
  30. ... )
  31. >>> # Create a SphereFace recognizer
  32. >>> recognizer = create_recognizer('sphereface')
  33. """
  34. method = method.lower()
  35. if method == 'arcface':
  36. return ArcFace(**kwargs)
  37. elif method == 'mobileface':
  38. return MobileFace(**kwargs)
  39. elif method == 'sphereface':
  40. return SphereFace(**kwargs)
  41. else:
  42. available = ['arcface', 'mobileface', 'sphereface']
  43. raise ValueError(f"Unsupported method: '{method}'. Available: {available}")
  44. __all__ = [
  45. 'create_recognizer',
  46. 'ArcFace',
  47. 'MobileFace',
  48. 'SphereFace',
  49. 'BaseRecognizer',
  50. ]