| Crates.io | baklava |
| lib.rs | baklava |
| version | 0.1.4 |
| created_at | 2025-08-16 18:57:27.7269+00 |
| updated_at | 2025-08-27 18:01:31.262842+00 |
| description | A rust wrapper around the InsightFace library to perform face comparison |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1798772 |
| size | 151,087 |
A small project that wrap the InsightFace SDK in order to perform face comparison. It uses a fork of InsightFace in order to implement some convenient method to be exposed for Rust that can be found here. The implementation is based on the sample provided by the insightface team. c example link
[!IMPORTANT] This guide required you to download the
insightfacelibrary and to follow the instructions in orders.
To use the library you'll need to specify the model that will be used. These models are the same that are used by the InsightFace library. The models can be found here
Clone the insightface's fork repository using this link and build the insightface library with the command
cd insightface/cpp-package/inspireface && git clone --recurse-submodules https://github.com/tunmx/inspireface-3rdparty.git 3rdparty
cd insightface/cpp-package/inspireface && bash command/build.sh
insightface library in your Cargo.toml by adding this into your .cargo/config.toml:[env]
INSIGHTFACE_PATH = "<path to>/insightface/cpp-package/inspireface/build/inspireface-<arch>/InspireFace"
Thereafter the library can be add as follows in your Cargo.toml:
[dependencies]
baklava = "0.1.0"
Below is a simple example of how to use the library:
// Should you have a list of images greater than 10. You can pass a chunk_size parameter in order to perform the image preparation concurrently.
let (cosine, percentage) = InsightFace::new("<model>", None)?
.prepare_images(&[
"./input1.png",
"./input2.png",
])?
.prepare_target_image("./target_image.png")?
.compare_images(Methodology::Mean)?;
The example can be run by executing the following command:
cargo run --example compare
[!IMPORTANT] This guide requires you to replace the
build.rsby thebuild_local.rs. Thisbuild_local.rswill build the project locally and copy the resultingdylibinto the target directory.
git clone --recurse-submodules https://github.com/shigedangao/baklava.git
# or
git submodule update --init --recursive
cd insightface/cpp-package/inspireface && git clone --recurse-submodules https://github.com/tunmx/inspireface-3rdparty.git 3rdparty
Replace the build.rs by the build_local.rs. This build_local.rs will build the project locally and copy the resulting dylib into the target directory.
Build the project
cargo build
cargo test
If you wish to recompile the InsightFace - rm -rf ./insightface/cpp-package/inspireface/build
These includes error such as inspireface.h not found etc...
The linking between the InsightFace and Baklava is done through the build.rs script. It automatically build with the targeted architecture and copies the resulting dylib into the target directory. Should you encounter any issues try to pass the DYLIB_INCLUDE_PATH variable like below.
DYLD_LIBRARY_PATH=./insightface/cpp-package/inspireface/build/inspire-{arch}/InspireFace/lib cargo build
[!TIP]
If the
inspireface.hcould still not be found. Then you may try to build the InsightFace library by yourself. You can run the following command within the InsightFace directory.cd insightface/cpp-package/inspireface bash command/build/shThis will build a dynamic library your current architecture within the
build/inspire-{arch}/InspireFace/libdirectory.