AI Faces (InsightFace)
The AI Faces plugin for ResourceSpace integrates advanced facial similarity search using InsightFace, a high-performance open-source framework for face detection, recognition, and analysis. This plugin enables ResourceSpace to detect faces in images automatically and generate facial embeddings — compact vector representations of individual faces. These vectors are indexed and searched using Facebook's FAISS engine, allowing users to find visually similar faces across the system with high accuracy. The functionality is entirely CPU-based and requires no training, making it lightweight and easy to deploy. It supports similarity search by face ID, automatic background indexing, and works across multiple databases, providing powerful facial recognition capabilities.
Using the Plugin
Enable the plugin in the Plugin Manager. You will need to install the Python FastAPI service (below).
Once up and running, from the plugins/faces/scripts folder execute "php faces_detect.php" to detect all faces. These will appear on the resource view page and you can click on each to search for matching faces.
Automatic Tagging
In the plugin settings configure a field used to store the names of people in your photos, for example "Named people", of type Dynamic Dropdown. Now set this value for some of the photos. Back on the resource view page, assign the people you have added to each detected face.
Execute "php faces_tag.php" to automatically tag matching faces that have a name selected for them. The threshold for a match can be adjusted in the plugin settings.
Installing the Face Matching Python FastAPI Service
This guide covers setting up the FastAPI-based face recognition service used for facial similarity search within ResourceSpace.
1. Prerequisites
- Python 3.9 or later (3.12 tested)
- Virtual environment support (recommended)
- Git and curl installed
- MySQL user with access to the ResourceSpace database
2. Create a Virtual Environment
python3 -m venv ~/faceenv
source ~/faceenv/bin/activate
3. Install Required Python Packages
pip install --upgrade pip
pip install fastapi uvicorn insightface onnxruntime faiss-cpu opencv-python-headless python-multipart mysql-connector-python
4. Download the Model
The InsightFace model will download automatically the first time the service runs. It will be stored under ~/.insightface/models
5. Start the Service
python faces_service.py --db-host=localhost --db-user=resourcespace --db-pass=yourpassword
The service will run on port 8001
and listen on all interfaces by default.
6. Verify It’s Working
curl -X POST http://localhost:8001/find_similar_faces \
-H "Content-Type: application/json" \
-d '{"ref": 1234, "db": "resourcespace", "k": 10}'
This should return a JSON list of the most similar faces to ref 1234
based on cosine similarity.
7. Run the Service Automatically (Optional)
Use systemd
, supervisord
or a similar tool to run the service as a background process on boot.
Notes
- The service supports multiple ResourceSpace databases, caching vector data separately for each.
- Vectors are refreshed automatically if new faces are detected or after an hour of inactivity.
- All similarity scores use cosine similarity (0.0–1.0, where 1.0 is a perfect match).