tfjs icon indicating copy to clipboard operation
tfjs copied to clipboard

backend.cast is not a function

Open ServerDeveloper9447 opened this issue 3 years ago • 10 comments

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 image

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'));
}

ServerDeveloper9447 avatar Feb 25 '23 16:02 ServerDeveloper9447

same here at 4.2.0

FanaticFalcon avatar Mar 03 '23 02:03 FanaticFalcon

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?

pyu10055 avatar Mar 06 '23 19:03 pyu10055

{
   ...
   "dependencies": {
         "@tensorflow/tfjs-node" : "^4.2.0",
         "face-api.js" : "^0.22.2"
         ...
   }
}

ServerDeveloper9447 avatar Mar 07 '23 02:03 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

FanaticFalcon avatar Mar 11 '23 06:03 FanaticFalcon

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

ServerDeveloper9447 avatar Mar 11 '23 07:03 ServerDeveloper9447

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!

gaikwadrahul8 avatar Mar 18 '23 15:03 gaikwadrahul8

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.

google-ml-butler[bot] avatar Mar 25 '23 15:03 google-ml-butler[bot]

Closing as stale. Please @mention us if this needs more attention.

google-ml-butler[bot] avatar Apr 01 '23 15:04 google-ml-butler[bot]

Are you satisfied with the resolution of your issue? Yes No

google-ml-butler[bot] avatar Apr 01 '23 15:04 google-ml-butler[bot]

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!

Thanks very much downgrading the version just saved my day of headaches

obipascal avatar Jul 14 '24 23:07 obipascal