Coder Social home page Coder Social logo

rustface's Introduction


SeetaFace detection library for the Rust programming language

Bt Example Example of demo program output

Linux build License

About

SeetaFace Detection is an implementation of Funnel-Structured cascade, which is designed for real-time multi-view face detection. FuSt aims at a good trade-off between accuracy and speed by using a coarse-to-fine structure. It consists of multiple view-specific fast LAB cascade classifiers at early stages, followed by coarse Multilayer Perceptron (MLP) cascades at later stages. The final stage is one unified fine MLP cascade, processing all proposed windows in a centralized style.

Read more...

Performance

Crude manual benchmarking shows that the Rust version is slightly faster than the original C++ version. Here are some numbers for a medium-sized image with 29 persons, which you may see above in this readme:

Image size: 1666x1136
Number of faces: 29

CPU: 2,3 GHz Intel Core i7
Single-thread (OpenMP disabled, Rayon threads set to 1)
SIMD enabled

* Original *
samples (ms): 893,893,891,883,884,883,890,908,893,879
mean (ms): 889.7
stddev (ms): 7.785

* Rustface *
samples (ms): 867,861,851,850,856,847,855,851,850,861
mean (ms): 854.9
stddev (ms): 6.024

In this particular test the Rust version has been 4% faster on average than its C++ counterpart.

Usage example

extern crate rustface;

use rustface::{Detector, FaceInfo, ImageData};

fn main() {
    let mut detector = rustface::create_detector("/path/to/model").unwrap();
    detector.set_min_face_size(20);
    detector.set_score_thresh(2.0);
    detector.set_pyramid_scale_factor(0.8);
    detector.set_slide_window_step(4, 4);
    
    let mut image = ImageData::new(bytes, width, height);
    for face in detector.detect(&mut image).into_iter() {
        // print confidence score and coordinates
        println!("found face: {:?}", face);
    }
}

How to build

The project is a library crate, but also contains an optional runnable module for demonstration purposes. In order to build it, you'll need an OpenCV 2.4 installation for generation of Rust bindings.

Also, due to usage of experimental stdsimd crate for SIMD support, the project relies on the nightly Rust toolchain, so you'll need to install it and set it as the default:

rustup default nightly

Then just use the standard Cargo build command:

cargo build --release

To build the runnable demo, specify the opencv-demo feature in the Cargo command line:

cargo build --release --features opencv-demo

Run demo

Code for the demo is located in src/bin/opencv-demo/main.rs file. It performs face detection for the given image and opens it in a separate window.

Please note that this library makes use of Rayon framework to parallelize some computations. By default, Rayon spawns the same number of threads as the number of CPUs (logicals cores) available. Instead of making things faster, the penalty of switching between so many threads may severely hurt the performance, so it's strongly advised to keep the number of threads small by manually setting RAYON_NUM_THREADS environment variable.

# empirically found to be the sweet spot for the number of threads
export RAYON_NUM_THREADS=2
cargo run --release --features opencv-demo model/seeta_fd_frontal_v1.0.bin <path-to-image>

TODO

  • Parallelize remaining CPU intensive loops
  • Tests (it would make sense to start with an integration test for Detector::detect, based on the results retrieved from the original library)

License

Original SeetaFace Detection is released under the BSD 2-Clause license. This project is a derivative work and uses the same license as the original.

rustface's People

Contributors

atomashpolskiy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.