backend.cast is not a function
Please make sure that this is a bug. As per our GitHub Policy, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:bug_template
System information
- Have I written custom code (as opposed to using a stock example script provided in TensorFlow.js): Yes
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Linux Ubuntu SMP 20.04.1
- Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device:
- TensorFlow.js installed from (npm or script link): https://www.npmjs.com/package/@tensorflow/tfjs-node
- TensorFlow.js version (use command below): 4.2.0
- Browser version:
- Tensorflow.js Converter Version:
Describe the current behavior

Describe the expected behavior It should save a the image file with a box drawn around the face
Standalone code to reproduce the issue
const faceapi = require('face-api.js');
const canvas = require('canvas');
const fs = require('fs');
const { Canvas, Image, ImageData } = canvas
faceapi.env.monkeyPatch({ Canvas, Image, ImageData })
const tf = require('@tensorflow/tfjs-node');
// Load face detection models
Promise.all([
faceapi.nets.ssdMobilenetv1.loadFromDisk('./models'),
faceapi.nets.faceLandmark68Net.loadFromDisk('./models'),
faceapi.nets.faceRecognitionNet.loadFromDisk('./models')
]).then(startDetection);
// Start face detection
async function startDetection() {
// Load input image
const img = await canvas.loadImage('input.jpg');
// Detect faces in the input image
const detections = await faceapi.detectAllFaces(img)
.withFaceLandmarks()
.withFaceDescriptors();
// Draw rectangles around the detected faces
const out = faceapi.createCanvasFromMedia(img);
const draw = faceapi.draw.drawDetections(out, detections);
fs.writeFileSync('output.jpg', out.toBuffer('image/jpeg'));
}
same here at 4.2.0
looks like you are running with an older version of TFJS, there might be some mismatching dependencies among your libraries, can you share your package.json files?
{
...
"dependencies": {
"@tensorflow/tfjs-node" : "^4.2.0",
"face-api.js" : "^0.22.2"
...
}
}
I managed to get things to work by removing require('@tensorflow/tfjs-node'); Face API will work well, but now I'm getting a msg:
============================
Hi there 👋. Looks like you are running TensorFlow.js in Node.js. To speed things up dramatically, install our node backend, ##### which binds to TensorFlow C++, by running npm i @tensorflow/tfjs-node, or npm i @tensorflow/tfjs-node-gpu if you have CUDA. Then call require('@tensorflow/tfjs-node'); (-gpu suffix for CUDA) at the start of your program. Visit https://github.com/tensorflow/tfjs-node for more details.
============================
my dependencies are the same as @ServerDeveloper9447
I managed to get things to work by removing require('@tensorflow/tfjs-node'); Face API will work well, but now I'm getting a msg:
============================
Hi there 👋. Looks like you are running TensorFlow.js in Node.js. To speed things up dramatically, install our node backend, ##### which binds to TensorFlow C++, by running npm i @tensorflow/tfjs-node, or npm i @tensorflow/tfjs-node-gpu if you have CUDA. Then call require('@tensorflow/tfjs-node'); (-gpu suffix for CUDA) at the start of your program. Visit https://github.com/tensorflow/tfjs-node for more details.
============================
my dependencies are the same as @ServerDeveloper9447
I tried that too, but when I do that, it just takes more time but ultimately outputs the same error
Hi, @ServerDeveloper9447
Apologize for the delayed response and as per this documentation if you'e looking to use original github repo for face-api .js then it seems like incompatible with latest TFJS versions and Original face-api.js is based on TFJS 1.7.4 so either you'll have to downgrade your TFJS version to TFJS 1.7.4 or if you're looking to use latest TFJS version then I think you can go with new FaceAPI
If possible could you please try to downgrade version of TFJS to 1.7.4 for original FaceAPI and let us know whether is it resolving your issue or not ?
If have I missed something here, please let me know ? Thank you!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you.
Closing as stale. Please @mention us if this needs more attention.
Hi, @ServerDeveloper9447
Apologize for the delayed response and as per this documentation if you'e looking to use original github repo for
face-api .jsthen it seems like incompatible with latestTFJSversions andOriginal face-api.js is based on TFJS 1.7.4so either you'll have to downgrade yourTFJSversion toTFJS 1.7.4or if you're looking to use latestTFJSversion then I think you can go with new FaceAPIIf possible could you please try to downgrade version of TFJS to 1.7.4 for original FaceAPI and let us know whether is it resolving your issue or not ?
If have I missed something here, please let me know ? Thank you!
Thanks very much downgrading the version just saved my day of headaches