{"id":43059380,"url":"https://github.com/hfahrudin/facex","last_synced_at":"2026-01-31T11:35:37.105Z","repository":{"id":262645629,"uuid":"159106334","full_name":"hfahrudin/facex","owner":"hfahrudin","description":"Python library for detecting faces and classifying emotions in images lightweight, efficient threading and object pooling for concurrent processing.","archived":false,"fork":false,"pushed_at":"2025-08-07T00:34:58.000Z","size":6029,"stargazers_count":17,"open_issues_count":1,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-09-27T22:25:08.899Z","etag":null,"topics":["computer-vision","deep-learning","machine-learning","opencv","python","raspberry-pi","tensorflow"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/facex/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hfahrudin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-11-26T03:43:39.000Z","updated_at":"2025-04-17T01:02:32.000Z","dependencies_parsed_at":"2024-11-13T15:00:39.325Z","dependency_job_id":null,"html_url":"https://github.com/hfahrudin/facex","commit_stats":null,"previous_names":["hfahrudin/fastemotrecognition"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/hfahrudin/facex","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hfahrudin%2Ffacex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hfahrudin%2Ffacex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hfahrudin%2Ffacex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hfahrudin%2Ffacex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hfahrudin","download_url":"https://codeload.github.com/hfahrudin/facex/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hfahrudin%2Ffacex/sbom","scorecard":{"id":463403,"data":{"date":"2025-08-11","repo":{"name":"github.com/hfahrudin/facex","commit":"471002400e4212f1a48620b45cbcdbb181241520"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Code-Review","score":0,"reason":"Found 0/16 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'","Warn: branch protection not enabled for branch 'release-v.1.0.0'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 15 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-19T11:47:18.933Z","repository_id":262645629,"created_at":"2025-08-19T11:47:18.933Z","updated_at":"2025-08-19T11:47:18.933Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28940641,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-31T10:18:23.202Z","status":"ssl_error","status_checked_at":"2026-01-31T10:18:22.693Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["computer-vision","deep-learning","machine-learning","opencv","python","raspberry-pi","tensorflow"],"created_at":"2026-01-31T11:35:36.973Z","updated_at":"2026-01-31T11:35:37.097Z","avatar_url":"https://github.com/hfahrudin.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Facex: Lightweight, High-Performance Facial Expression Classifier\n\n**facex** is a Python library for detecting faces and classifying emotions in images lightweight, efficient threading and object pooling for concurrent processing making it suitable for high-performance applications. \n\n**NOTE:**  The model was trained some time ago. While it performs well, newer advancements in the field may offer improved results\n\n## Features\n- **Face Detection**: Uses Haar cascades to detect faces in images.\n- **Emotion Classification**: Predicts emotions like anger, happiness, sadness, and more.\n- **Thread-Safe Pooling**: Manages multiple classifiers through a thread-safe object pool.\n- **Dedicated Worker Allocation**: Assign dedicated classifiers for specific tasks or users.\n\n**NOTE:**  The model was trained some time ago. While it performs well, newer advancements in the field may offer improved results.\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"https://user-images.githubusercontent.com/25025173/51177457-37460a00-18f2-11e9-8858-9c51f6c987a1.gif\" alt=\"Alt Text\" width=\"500\"/\u003e\n    \u003cp\u003e\u003ci\u003eTesting on RaspberryPi\u003c/i\u003e\u003c/p\u003e\n\u003c/div\u003e\n\n## Installation\n\nInstall the library via pip:\n```bash\npip install facex\n```\n\n### Prerequisites\nMake sure you have the following:\n- Python 3.7 or higher\n- Required dependencies (installed automatically with pip):\n  - `numpy`\n  - `opencv-python`\n  - `tensorflow`\n  \nAdditionally, ensure the `assets` directory contains the following files:\n- `haarcascade_frontalface_default.xml`\n- `model_optimized.tflite`\n\n## Usage\n\n### Example Code\n```python\nimport cv2\nimport facex\n\n# Initialize the PoolManager\npool_manager = facex.PoolManager(pool_size=3)\n\n# Load a test image\nimage = cv2.imread(\"test_image.jpg\")\n\n# Predict emotions\npredictions = pool_manager.predict(image)\n\n# Display results\nfor prediction in predictions:\n    print(f\"Face: {prediction['bbox']}, Emotion: {prediction['emot']}\")\n\n# Shutdown the pool manager when done\npool_manager.shutdown()\n```\n\n### Key Classes and Methods\n\n#### `facex.EmotionClassifier`\nA class responsible for detecting faces and classifying emotions in images.\n\n- **`__init__(model_path, category=None)`**: \n  Initializes the emotion classifier with the provided TensorFlow Lite model and optional emotion categories.\n  - **Arguments**:\n    - `model_path` (str): Path to the pre-trained TensorFlow Lite model (`model_optimized.tflite`).\n    - `category` (list, optional): List of emotion categories (default: `['anger', 'disgust', 'fear', 'happy', 'neutral', 'sadness', 'surprised']`).\n\n- **`detect_faces(input)`**: \n  Detects faces in the input image using OpenCV's Haar Cascade Classifier.\n  - **Arguments**:\n    - `input` (np.ndarray): The input image (e.g., a frame from a video feed).\n  - **Returns**:\n    - `faces` (list of tuples): Coordinates of detected faces in the form `(x, y, w, h)`.\n    - `procs_input` (np.ndarray): Preprocessed grayscale version of the input image.\n\n- **`detect_emotion(input)`**: \n  Detects the emotion of a given face using the TensorFlow Lite model.\n  - **Arguments**:\n    - `input` (np.ndarray): The face image (grayscale or resized) to classify.\n  - **Returns**:\n    - `dict`: A dictionary containing the predicted emotion with associated confidence scores.\n\n- **`predict(input)`**: \n  Detects faces and predicts the emotions for each detected face in the image.\n  - **Arguments**:\n    - `input` (np.ndarray): The input image (e.g., a frame from a video feed).\n  - **Returns**:\n    - `list`: A list of dictionaries, each containing:\n      - `'bbox'`: Bounding box of the detected face `(x, y, w, h)`.\n      - `'emot'`: Emotion prediction for the face (e.g., `{'happy': 0.95, 'sadness': 0.05}`).\n\n#### `facex.PoolManager`\nA class for managing a pool of EmotionClassifier instances, enabling thread-safe predictions.\n\n- **`__init__(pool_size=5)`**: \n  Initializes the pool with a given number of `EmotionClassifier` instances.\n  - **Arguments**:\n    - `pool_size` (int): Number of `EmotionClassifier` instances in the pool (default: `5`).\n\n- **`predict(input_data)`**: \n  Retrieves an `EmotionClassifier` from the pool and uses it to make a prediction on the input data.\n  - **Arguments**:\n    - `input_data` (np.ndarray): The input image data (e.g., a frame from a video feed).\n  - **Returns**:\n    - `list`: A list of dictionaries, each containing:\n      - `'bbox'`: Bounding box of the detected face `(x, y, w, h)`.\n      - `'emot'`: Emotion prediction for the face.\n\n- **`get_worker(user_id)`**: \n  Allocates a dedicated `EmotionClassifier` instance for a specific user.\n  - **Arguments**:\n    - `user_id` (str): The ID of the user requesting the worker.\n  - **Returns**:\n    - `EmotionClassifier`: The dedicated `EmotionClassifier` instance for the user.\n  - **Raises**:\n    - `RuntimeError`: If the user already has a dedicated worker or if no classifiers are available.\n\n- **`release_worker(user_id)`**: \n  Releases the dedicated worker assigned to a user and returns it to the pool.\n  - **Arguments**:\n    - `user_id` (str): The ID of the user releasing the worker.\n  - **Raises**:\n    - `KeyError`: If the user does not have a dedicated worker.\n\n- **`shutdown()`**: \n  Shuts down the pool manager and frees all resources, including threads.\n\n## License\n**facex** is licensed under the MIT License. See the `LICENSE` file for details.\n\n## References\n\n1. **Deep learning based facial expressions recognition system for assisting visually impaired persons**  \n   Hendra Kusuma, Muhammad Attamimi, Hasby Fahrudin (2020). *Deep learning based facial expressions recognition system for assisting visually impaired persons*. Retrieved from [link](https://www.researchgate.net/publication/341796937_Deep_learning_based_facial_expressions_recognition_system_for_assisting_visually_impaired_persons)\n\n## Support\nIf you encounter any issues, feel free to [open an issue](https://github.com/hfahrudin/facex/issues) or reach out via email.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhfahrudin%2Ffacex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhfahrudin%2Ffacex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhfahrudin%2Ffacex/lists"}