Full face stack that runs entirely in the browser. Detection, 576-point 3D mesh, recognition, anti-spoof, smile — all WebAssembly, zero server. Apache 2.0.
C avx-512avx2biometricsc99computer-visioncpu-inferencedeep-learningedge-aiembedded-aiface-embeddingface-recognitionface-verificationlow-latencyonnx-runtimeproduction-readysimdzero-dependencies
#include "nn2_internal.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef _WIN32
#include <windows.h>
static double now(void){LARGE_INTEGER f,c;QueryPerformanceFrequency(&f);QueryPerformanceCounter(&c);return(double)c.QuadPart/f.QuadPart*1000.0;}
#endif
int main(void){
nn2_tp_init(6);
printf("=== NanoDet-Plus-m Operator Benchmarks (6 threads) ===\n\n");
int R=100; double t0,ms;
/* DW conv benchmarks (the most common op in NanoDet) */
printf("Depthwise Conv (per-channel, no GEMM):\n");
struct{const char*n;int c,h,k,s;} dw_tests[]={
{"DW 58ch k=3 s=1 @80", 58, 80, 3, 1},
{"DW 116ch k=3 s=1 @40", 116, 40, 3, 1},
{"DW 232ch k=3 s=1 @20", 232, 20, 3, 1},
{"DW 96ch k=5 s=1 @40", 96, 40, 5, 1},
{"DW 96ch k=5 s=1 @20", 96, 20, 5, 1},
{"DW 192ch k=5 s=1 @40", 192, 40, 5, 1},
{"DW 96ch k=5 s=2 @40", 96, 40, 5, 2},
};
for(int t=0;t<7;t++){
int c=dw_tests[t].c, h=dw_tests[t].h, k=dw_tests[t].k, s=dw_tests[t].s;
int ho=(h+2*(k/2)-k)/s+1;
float*in=(float*)calloc(c*h*h,4);
float*w=(float*)calloc(c*k*k,4);
float*b=(float*)calloc(c,4);
float*out=(float*)malloc(c*ho*ho*4);
t0=now();
for(int r=0;r<R;r++)nn2_dwconv2d(in,w,b,c,h,h,k,s,k/2,3,out);
ms=(now()-t0)/R;
printf(" %-28s %.3f ms\n",dw_tests[t].n,ms);
free(in);free(w);free(b);free(out);
}
/* PW (1x1) conv benchmarks */
printf("\nPointwise Conv (pure GEMM):\n");
struct{const char*n;int co,ci,h;} pw_tests[]={
{"PW 58->58 @80", 58, 58, 80},
{"PW 116->116 @40",116,116, 40},
{"PW 232->232 @20",232,232, 20},
{"PW 96->96 @40", 96, 96, 40},
{"PW 96->112 @40", 112, 96, 40},
{"PW 116->96 @40", 96,116, 40},
{"PW 232->96 @20", 96,232, 20},
};
for(int t=0;t<7;t++){
int co=pw_tests[t].co, ci=pw_tests[t].ci, h=pw_tests[t].h;
int sp=h*h;
float*w=(float*)calloc(co*ci,4);
float*in=(float*)calloc(ci*sp,4);
float*out=(float*)malloc(co*sp*4);
t0=now();
for(int r=0;r<R;r++)nn2_sgemm(co,ci,sp,w,ci,in,sp,out,sp);
ms=(now()-t0)/R;
printf(" %-28s %.3f ms\n",pw_tests[t].n,ms);
free(w);free(in);free(out);
}
/* Sum up estimated total */
printf("\n--- Estimated NanoDet total ---\n");
printf(" ~43 DW convs: ~43 * 0.03ms avg = ~1.3ms\n");
printf(" ~66 PW convs: ~66 * 0.02ms avg = ~1.3ms\n");
printf(" 1 regular conv + overhead: ~0.4ms\n");
printf(" Estimated total: ~3.0ms\n");
printf(" vs ONNX RT NanoDet: 10.7ms\n");
printf(" vs ONNX RT YOLOv8n: 13.6ms\n");
nn2_tp_destroy();return 0;
}