shield-vision
v1.0.1
Published
Client-side privacy masking for faces and license plates with TensorFlow.js.
Maintainers
Readme
Shield Vision
Shield Vision is a client-side privacy masking library for browsers. It detects faces with BlazeFace, masks license plate risk areas from vehicle detections, and applies blur or pixelation before an image is uploaded to a server.
The goal is simple: keep the original image on the user's device so backend systems never handle unredacted personal data.
What it does
- Auto-selects the fastest available TensorFlow.js backend, preferring
webgpu, thenwebgl, thenwasm, thencpu - Detects faces locally with BlazeFace
- Detects vehicles locally with COCO-SSD and masks conservative plate-risk regions by default
- Supports custom license plate detectors for teams with a dedicated trained model
- Masks sensitive regions with blur or pixelation on a canvas
- Exposes capability reporting so apps can show whether acceleration is active
- Includes a polished Vite demo for trying the pipeline with local images
Quick start
npm install
npm run devOpen the Vite app in a browser, upload an image, and the demo will render:
- the original image
- the masked output
- the detection overlay
- backend and timing metrics
Library usage
import { createShieldVision } from 'shield-vision';
const shieldVision = createShieldVision({
preferredBackend: 'auto',
maskMode: 'blur',
blurStrength: 18,
enableFaceMasking: true,
enableLicensePlateMasking: true,
// Production-safe default: mask the full detected vehicle as the plate risk area.
licensePlateFallback: 'vehicle',
// Recommended for production: serve model files from infrastructure you control.
// faceModelUrl: '/models/blazeface/model.json',
// objectModelUrl: '/models/coco-ssd/model.json',
// Required only when you want WASM fallback and host the TFJS WASM binaries yourself.
// wasmPaths: '/vendor/tfjs-backend-wasm/'
});
await shieldVision.warmup();
const result = await shieldVision.mask(file);
console.log(result.backend, result.metrics.totalMs, result.regions);
const blob = await result.toBlob('image/jpeg', 0.92);License Plate Modes
By default, licensePlateFallback: 'vehicle' masks the full detected vehicle region. This favors privacy over preserving vehicle detail, which is the safer production behavior when a dedicated plate detector is not configured.
Use licensePlateFallback: 'plate-zone' only when you accept a tighter, vehicle-assisted heuristic. Use licensePlateFallback: 'none' with licensePlateDetector when your app provides its own dedicated detector.
const shieldVision = createShieldVision({
licensePlateDetector: async (canvas) => {
// Return boxes from your own trained plate detector.
return [{ x: 120, y: 220, width: 92, height: 28, confidence: 0.96 }];
},
licensePlateFallback: 'vehicle'
});Scripts
npm run devstarts the demonpm run buildbuilds the distributable SDK intodist/npm run build:demobuilds the demo site intodemo-dist/npm run checkruns TypeScript without emitting filesnpm testbuilds the SDK and runs package/browser smoke testsnpm run verifyruns typecheck, tests, demo build, and a production dependency auditnpm run previewpreviews the built demo or library environment through Vite
Project structure
src/contains the reusable Shield Vision SDKdemo/contains the browser demo UIdist/contains the packaged library outputdemo-dist/contains the built demo output
Notes
- Face detection is model-based and fairly direct.
- License plate masking defaults to conservative vehicle-region masking unless a custom detector returns plate boxes.
- For high-risk privacy workflows, keep
licensePlateFallback: 'vehicle'unless you have validated a dedicated detector against your exact camera angles, regions, and vehicle types.
Production checklist
- Run
npm run verifybefore publishing or deploying. - Self-host
faceModelUrlandobjectModelUrlif your product cannot depend on TensorFlow's public model URLs at runtime. - If you rely on the WASM backend, serve
tfjs-backend-wasm.wasm,tfjs-backend-wasm-simd.wasm, andtfjs-backend-wasm-threaded-simd.wasm, then setwasmPathsbefore callingwarmup(). - Keep WebGL or WebGPU enabled for best performance; the CPU fallback is functional but slower on large images.
- Leave
licensePlateFallback: 'vehicle'enabled for fail-closed plate privacy when a dedicated detector misses or is not configured.
