Skip to content

armgit / facex

Public Imported from GitHub
0

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.

Exercise Go identification on the model fixture gallery

Baurzhan Atynov72b561d4f44e
diff --git a/.github/workflows/go-gallery.yml b/.github/workflows/go-gallery.yml
index 7db3412..00620bf 100644
--- a/.github/workflows/go-gallery.yml
+++ b/.github/workflows/go-gallery.yml
@@ -28,3 +28,34 @@ jobs:
env:
FACEX_GALLERY_SCALE: '1'
run: go test -v -run '^TestIdentityGalleryScale$' -count=1 ./...
+ - uses: actions/setup-python@v5
+ with:
+ python-version: '3.12'
+ - name: Prepare model fixture and verify Go decisions
+ working-directory: .
+ env:
+ OPENBLAS_NUM_THREADS: '1'
+ FACEX_GALLERY_SCALE: '1'
+ FACEX_GALLERY_FIXTURE: ${{ runner.temp }}/gallery
+ run: |
+ make cli
+ weights="$RUNNER_TEMP/edgeface_xs_fp32.bin"
+ curl --fail --silent --show-error --location --retry 2 https://github.com/facex-engine/facex/releases/download/v1.0.0/edgeface_xs_fp32.bin -o "$weights"
+ echo "d23f7b3cf8bcda5e451b48cf012e7dc6c4963d5703fafb8893f956d0203691d8 $weights" | sha256sum --check
+ python -m pip install numpy==2.3.5 Pillow==12.0.0
+ PYTHONPATH=tests:python python - "$weights" <<'PY'
+ import os
+ import sys
+ from pathlib import Path
+ import numpy as np
+ from bench_gallery_groups import fixture_views, prepare
+
+ output = Path(os.environ["FACEX_GALLERY_FIXTURE"])
+ output.mkdir()
+ prepare(output, fixture_views(Path(sys.argv[1])), scaled=True)
+ near_and_boundary = np.load(output / "queries.npy")
+ random = np.random.default_rng(77).standard_normal((15, 512))
+ np.vstack((near_and_boundary, random)).astype("<f4").tofile(output / "queries")
+ PY
+ cd go/facex
+ go test -v -run '^TestIdentityGalleryScale$' -count=1 ./...
diff --git a/go/facex/identity_batch_test.go b/go/facex/identity_batch_test.go
index acdec05..b022bff 100644
--- a/go/facex/identity_batch_test.go
+++ b/go/facex/identity_batch_test.go
@@ -1,11 +1,14 @@
package facex
import (
+ "bufio"
"context"
+ "encoding/binary"
"errors"
"math"
"math/rand"
"os"
+ "path/filepath"
"sort"
"testing"
"time"
@@ -95,6 +98,27 @@ func TestIdentityGalleryScale(t *testing.T) {
queries[i+people][(i+1)%people] = 1
queries[i+2*people] = basis(200+i)
}
+ if dir := os.Getenv("FACEX_GALLERY_FIXTURE"); dir != "" {
+ readRows := func(name string, vectors [][]float32) {
+ f, err := os.Open(filepath.Join(dir, name))
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer f.Close()
+ stat, err := f.Stat()
+ if err != nil || stat.Size() != int64(len(vectors)*OutputSize*4) {
+ t.Fatalf("incorrect fixture size for %s: %v", name, err)
+ }
+ reader := bufio.NewReaderSize(f, 1<<20)
+ for _, row := range vectors {
+ if err := binary.Read(reader, binary.LittleEndian, row); err != nil {
+ t.Fatal(err)
+ }
+ }
+ }
+ readRows("rows", rows)
+ readRows("queries", queries)
+ }
g, err := NewIdentityGallery(rows, ids)
if err != nil {
t.Fatal(err)