Comments (8)
sorry, i have no idea how nodejs GCP works, clearly its not the same are real nodejs environment.
from face-api.
GCP works with old faceapi, I've found this repository so I think your faceapi should work too.
But those erros I've mentioned, do you know how to solve them?
from face-api.
I'm following this and this examples and having canvas type errors also:
async function getImage(
input: Buffer
) {
const img = await canvas.loadImage(input)
const canva = canvas.createCanvas(img.width, img.height)
const ctx = canva.getContext('2d')
ctx.drawImage(img, 0, 0, img.width, img.height)
return canva
}
const path = './models'
const { Canvas, Image, ImageData } = canvas
faceapi.env.monkeyPatch({Canvas, Image, ImageData})
await faceapi.nets.ssdMobilenetv1.loadFromDisk( path )
await faceapi.nets.faceLandmark68Net.loadFromDisk( path )
await faceapi.nets.faceRecognitionNet.loadFromDisk( path )
const faceDetectorOptions = new faceapi.SsdMobilenetv1Options( {
maxResults: 2
} )
const selfie = await getImage( uploads[ 0 ].buffer )
const results = await faceapi.detectAllFaces(
selfie,
faceDetectorOptions
).withFaceLandmarks()
.withFaceDescriptors()
console.log( 'faces found', results.length )
from face-api.
all those messages are about type mismatach that come from GCP, i have no idea why its mismatching perfectly fine types. i never used gcp nodejs workers nor i plan to.
from face-api.
I don't think these type errors are related to GCP because they happens locally. I think this is something related to TS. Anyway, I've managed to get rid of these errors casting types as unknown.
I just have one more doubt: Is it possible to store face detection data to use them after in FaceMatcher
?
E.g:
// stringfy detection data
const detections = await detectAllFaces(
selfie as unknown as TNetInput,
faceDetectorOptions
).withFaceLandmarks()
.withFaceDescriptors()
await saveToDb(
JSON.stringfy(detections)
)
// then parse it back
const stringDetections = await getFromDb()
const detections = JSON.parse(stringDetections)
const faceMatcher = new FaceMatcher( detections )
I'm trying but this leads to error. Do you have a better sollution?
from face-api.
its definitely possible and quite common use-case, search previous issues.
from face-api.
@vladmandic Thanks for your help. I've managed to get this working.
If anyone needs something like this here's a little example:
async function getDetections(
input: Buffer,
faceDetectorOptions: SsdMobilenetv1Options
): Promise<FaceDetectionResult> {
// needs to require, importing will set tf to undefined
const tf = require( '@tensorflow/tfjs-node' )
const tensor = tf.node.decodeImage( input, 3 )
const detections = await detectAllFaces(
tensor as unknown as TNetInput,
faceDetectorOptions
).withFaceLandmarks()
.withFaceDescriptors()
tf.dispose( tensor )
return detections
}
// we will save descriptors in firestore so they need to be as string
const descriptors: string[] = []
// initialize and load detections models
....
// loop through images uploaded
for await ( const { buffer } of uploads ) {
const detections = await getDetections(
buffer,
faceDetectorOptions
)
if ( isEmpty( detections ) ) // handle 0 faces detected
if ( detections.length > 1 ) // handle multiple faces detected
descriptors.push( detections[ 0 ].descriptor.toString() )
}
await firestore.doc<FaceMatcherDoc>( `faces/${ label }` )
.set( { descriptors } )
/**
* now when you need to validate a face just restore stored face descriptors
*/
const faceMatcherDoc = await firestore
.doc( `faces/${ label }` )
.get()
const { descriptors } = faceMatcherDoc.data()!
const labeledDescriptors = new LabeledFaceDescriptors(
label,
// converts string back to Float32Array[]
descriptors.map( descriptor => Float32Array.from(
descriptor.split( "," ),
parseFloat
) )
)
const faceMatcher = new FaceMatcher( labeledDescriptors )
const match = faceMatcher.findBestMatch(
detections[ 0 ].descriptor
)
const confidence = 1 - match.distance
if ( confidence < parseFloat( FACE_MIN_CONFIDENCE ) ) // handle face do not match
const stringDescriptor = detections[ 0 ].descriptor.toString()
// add new descriptos to current saved so detection will be more precise
if ( !arrayContains(
descriptors,
stringDescriptor
) ) {
await firestore.doc( `faces/${ label }` )
.set( {
descriptors: [
...descriptors,
stringDescriptor
]
} )
}
from face-api.
@nonam4 do you happen to have a repo available showing this? Having trouble getting this to work
from face-api.
Related Issues (20)
- Demo Launch Issue HOT 1
- Different face detection and match results between browser and server HOT 5
- Pitch is not good when Yaw is <-150º or >150º HOT 1
- Face-api.js In React native HOT 1
- Is it possible to translate it? HOT 1
- Face api gives an error when there are too many photos HOT 3
- Error: Based on the provided shape, [1,1,16,32], the tensor should have 512 values but has 48 HOT 2
- Unhandled Promise Rejection: TypeError: null is not an object (evaluating 'e.isContextLost') HOT 1
- Trying to load tfjs-node externally to be able to deploy on vercel. HOT 2
- A bit confusing, old version cpu, gpu issues & new wasm flow HOT 1
- System requirements HOT 1
- node multiprocess on GPU HOT 4
- Object Detection HOT 1
- Can this lib use with RTSP Streaming Video From IP Camera? HOT 2
- Error while using faceapi in angular HOT 1
- Cant we use models from node modules and decrease models file size? HOT 3
- Initialization of backend wasm failed HOT 1
- Detached EventHandlers when running on a Canvas HOT 3
- Support for TSC verbatimModuleSyntax HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from face-api.