{"id":21810223,"url":"https://github.com/shhossain/facedb","last_synced_at":"2025-05-07T02:40:59.077Z","repository":{"id":192365955,"uuid":"686320635","full_name":"shhossain/FaceDB","owner":"shhossain","description":"A package designed for efficient face recognition across extensive photo collections, optimized for large-scale processing.","archived":false,"fork":false,"pushed_at":"2024-09-14T15:27:35.000Z","size":364,"stargazers_count":63,"open_issues_count":3,"forks_count":14,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-16T01:12:24.795Z","etag":null,"topics":["face-detection","face-recognition","large-scale"],"latest_commit_sha":null,"homepage":"","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/shhossain.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2023-09-02T11:58:23.000Z","updated_at":"2025-04-15T06:31:40.000Z","dependencies_parsed_at":null,"dependency_job_id":"0b0db24a-e5bf-425b-8cbe-62da8e046cb5","html_url":"https://github.com/shhossain/FaceDB","commit_stats":null,"previous_names":["shhossain/facedb"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shhossain%2FFaceDB","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shhossain%2FFaceDB/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shhossain%2FFaceDB/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shhossain%2FFaceDB/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shhossain","download_url":"https://codeload.github.com/shhossain/FaceDB/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252802422,"owners_count":21806496,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["face-detection","face-recognition","large-scale"],"created_at":"2024-11-27T13:33:40.794Z","updated_at":"2025-05-07T02:40:59.039Z","avatar_url":"https://github.com/shhossain.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FaceDB - A Face Recognition Database\n\nFaceDB is a Python library that provides an easy-to-use interface for face recognition and face database management. It allows you to perform face recognition tasks, such as face matching and face searching, and manage a database of faces efficiently. FaceDB supports two popular face recognition frameworks: DeepFace and face_recognition.\n\n## Links\n[Pypi](https://pypi.org/project/facedb/)\n[Github](https://github.com/shhossain/facedb)\n\n## Installation\n\nFaceDB can be installed using pip:\n\n```bash\npip install facedb\n```\n\nYou can use face_recognition or DeepFace for face recognition. If you want to use DeepFace, you need to install the following dependencies:\nfor face_recognition:\n\n```bash\npip install face_recognition\n```\n\nfor DeepFace:\n\n```bash\npip install deepface\n```\n\n## Simple Usage\n\nThis will create a chromadb database in the current directory.\n\n```python\n# Import the FaceDB library\nfrom facedb import FaceDB\n\n# Create a FaceDB instance\ndb = FaceDB(\n    path=\"facedata\",\n)\n\n# Add a new face to the database\nface_id = db.add(\"John Doe\", img=\"john_doe.jpg\")\n\n# Recognize a face\nresult = db.recognize(img=\"new_face.jpg\")\n\n# Check if the recognized face is similar to the one in the database\nif result and result[\"id\"] == face_id:\n    print(\"Recognized as John Doe\")\nelse:\n    print(\"Unknown face\")\n```\n\n## Advanced Usage\n\nYou need to install pinecone first to use pinecone as the database backend.\n\n```bash\npip install pinecone\n```\n\n```python\nimport os\n\nos.environ[\"PINECONE_API_KEY\"] = \"YOUR_API_KEY\"\n\ndb = FaceDB(\n    path=\"facedata\",\n    metric='euclidean',\n    database_backend='pinecone',\n    index_name='faces',\n    embedding_dim=128,\n    module='face_recognition',\n)\n\n# This will create a pinecone index with name 'faces' in your environment if it doesn't exist\n\n# add multiple faces\nfrom glob import glob\nfrom pathlib import Path\n\nfiles = glob(\"faces/*.jpg\") # Suppose you have a folder with imgs with names as filenames\nimgs = []\nnames = []\nfor file in files:\n    imgs.append(file)\n    names.append(Path(file).name)\n\nids, failed_indexes = db.add_many(\n    imgs=imgs,\n    names=names,\n)\n\nunknown_face = \"unknown_face.jpg\"\nresult = db.recognize(img=unknown_face, include=['name'])\nif result:\n    print(f\"Recognized as {result['name']}\")\nelse:\n    print(\"Unknown face\")\n\n\n# Include img in the result\nresult = db.recognize(img=unknown_face, include=['img'])\nif result:\n    result.show_img()\n\n# # Use can also use show_img() for multiple results\nresults = db.all(include='name')\nresults.show_img() # make sure you have matplotlib installed\n\n# or\nimg = result['img'] # cv2 image (numpy array)\n\n# Include embedding in the result\nresult = db.recognize(img=unknown_face, include=['embedding'])\nif result:\n    print(result['embedding'])\n\n\n# Search for similar faces\nresults = db.search(img=unknown_face, top_k=5, include=['name'])[0]\n\nfor result in results:\n    print(f\"Found {result['name']} with distance {result['distance']}\")\n\n# or search for multiple faces\nmulti_results = db.search(img=[img1, img2], top_k=5, include=['name'])\n\nfor results in multi_results:\n    for result in results:\n        print(f\"Found {result['name']} with distance {result['distance']}\")\n\n# get all faces\nfaces = db.get_all(include=['name', 'img']) \n\n# Update a face\ndb.update(face_id, name=\"John Doe\", img=\"john_doe.jpg\", metadata1=\"metadata1\", metadata2=\"metadata2\")\n\n# Delete a face\ndb.delete(face_id)\n\n# Count the number of faces in the database\ncount = db.count()\n\n# Get pandas dataframe of all faces\ndf = db.all().df\n```\n\n## Simple Querying\n\n```python\n\n# First add some faces to the database\ndb.add(\"Nelson Mandela\", img=\"mandela.jpg\", profession=\"Politician\", country=\"South Africa\")\ndb.add(\"Barack Obama\", img=\"obama.jpg\", profession=\"Politician\", country=\"USA\")\ndb.add(\"Einstein\", img=\"einstein.jpg\", profession=\"Scientist\", country=\"Germany\")\n\n# Query the database by name\nresults = db.query(name=\"Nelson Mandela\")\n\n# Query the database by profession\nresults = db.query(profession=\"Politician\")\n```\n## If you don't have an API key\n\nYou can follow the official pinecone tutorial : https://docs.pinecone.io/docs/new-api\nIt's easy to use and to understand, don't worry.\n\n## Advanced Querying\n\nYou can use following operators in queries:\n\n- $eq - Equal to (number, string, boolean)\n- $ne - Not equal to (number, string, boolean)\n- $gt - Greater than (number)\n- $lt - Less than (number)\n- $in - In array (string or number)\n- $regex - Regex match (string)\n\n```python\nresults = db.query(\n    profession={\"$eq\": \"Politician\"},\n    country={\"$in\": [\"USA\", \"South Africa\"]},\n)\n# or write in a single json\nresults = db.query(\n    where={\n        \"profession\": {\"$eq\": \"Politician\"},\n        \"country\": {\"$in\": [\"USA\", \"South Africa\"]},\n    }\n)\n\n# you can use show_img(), df, query to further filter the results\nresults.show_img()\nresults.df\nresults.query(name=\"Nelson Mandela\")\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshhossain%2Ffacedb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshhossain%2Ffacedb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshhossain%2Ffacedb/lists"}