Closed danies8 closed 2 years ago
if you're using old face-api
, post issues in that forum - i'm not going to troubleshoot something that works in my port of face-api
and doesnt in the old one.
It will be very great if you help how to create tensor in old api js
its been there for a while :) https://github.com/vladmandic/face-api/blob/master/demo/node-image.js
I used your code:
const tf = require('@tensorflow/tfjs-node');
const canvas = await image.imageFromBuffer(Buffer.from(imageStrEncodedBase64.split(',')[1], 'base64')); // decode to canvas
const imageData = image.getImageData(canvas);
const tensor = tf.tidy(() => { // create tensor from image data
*const data = tf.tensor(Array.from(imageData.data || []), [canvas.height, canvas.width, 4], 'int32'); // create rgba image tensor from flat array and flip to height x width
const channels = tf.split(data, 4, 2); // split rgba to channels
const rgb = tf.stack([channels[0], channels[1], channels[2]], 2); // stack channels back to rgb
const reshape = tf.reshape(rgb, [1, canvas.height, canvas.width, 3]); // move extra dim from the end of tensor and use it as batch number instead
return reshape;
});
Get error in *: TypeError: tfc.ENV.findBackend is not a function What do I miss ?
very weird, but it again points to bad tfjs-node
installation as it use even basic API.
I think I succeded to create tensor: Create tensor done successfully(tensor shape:1,512,383,3, tensor size:588288 but when I reached to this code (*) I got: UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'backend' of undefined at Engine.moveData \node_modules\tfjs-image-recognition-base\node_modules\@tensorflow\tfjs-core\dist\engine.js:349:31) at DataStorage.get node_modules\tfjs-image-recognition-base\node_modules\@tensorflow\tfjs-core\dist\backends\backend.js:31:28)
const ssdOptions = { minConfidence: parseFloat(config.ssdOptionsMinConfidence), maxResults: parseInt(config.ssdOptionsMaxResults) };
const optionsSSDMobileNet = new faceapi.SsdMobilenetv1Options(ssdOptions);
* const faces = await faceapi
.detectAllFaces(tensor, optionsSSDMobileNet)
.withFaceLandmarks()
.withFaceDescriptors();
What do I miss ?
it means that faceapi is using wrong instance of tf. it has browser version of tfjs
embedded (even when used in node),
but that doesnt work in node
i dont remember anymore if const tf = require('@tensorflow/tfjs-node')
should be done before or after face-api
import so it basically overwrites its internal registrations - try both.
i don't know why are you spending so much time trying old face-api
? is there a problem with the new one?
I used in both places and got same error,
something is really wrong with installation of tfjs-node
on your system and i have no idea why...
Hi,
Error:tf.node.decodeImage is not a function Thanks,