testing PoseNet on local files - 'pixels must be HTMLCanvasElement' error
See original GitHub issueTo get help from the community, check out our Google group.
TensorFlow.js version
v0.12.0
Browser version
Node version 10.8.0
Describe the problem or feature request
I’m pretty new to node, so I apologize if this is a simple fix … interested to see how PoseNet could be converted to python. Anyway, I’m trying to run estimateSinglePose
on a local file, but I keep getting the following error:
Error: When running in node, pixels must be an HTMLCanvasElement like the one returned by the `canvas` npm package
at NodeJSKernelBackend.fromPixels (/Users/home/Documents/pose_estimation/poseNet/node_modules/@tensorflow/tfjs-node/dist/nodejs_kernel_backend.js:886:19)
at Engine.fromPixels (/Users/home/Documents/pose_estimation/poseNet/node_modules/@tensorflow/tfjs-core/dist/engine.js:343:29)
at fromPixels_ (/Users/home/Documents/pose_estimation/poseNet/node_modules/@tensorflow/tfjs-core/dist/ops/array_ops.js:174:37)
at Object.fromPixels (/Users/home/Documents/pose_estimation/poseNet/node_modules/@tensorflow/tfjs-core/dist/ops/operation.js:23:29)
at Object.<anonymous> (/Users/home/Documents/pose_estimation/poseNet/test_git_issue.js:24:21)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
I’ve tried creating a new canvas Image object with the local file path, but that still produced the error. I also tried passing that image object to a tensor and then sending the tensor to estimateSinglePose
, as recommended in this thread, but I keep getting the same error.
Thanks!!
Code to reproduce the bug / link to feature request
const tf = require('@tensorflow/tfjs');
require('@tensorflow/tfjs-node');
const posenet = require('@tensorflow-models/posenet');
const { Image } = require('canvas');
async function singlePoseOutput(imageElement) {
const imageScaleFactor = 0.50;
const flipHorizontal = false;
const outputStride = 16;
const net = await posenet.load();
const pose = await net.estimateSinglePose(imageElement, imageScaleFactor, flipHorizontal, outputStride);
return pose;
};
//create canvas image with local file
const img = new Image();
img.src = './img_file.png';
// convert canvas image to tensor
var img_tensor = tf.fromPixels(img);
const pose = singlePoseOutput(img_tensor);
console.log(pose);
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (2 by maintainers)
Top Results From Across the Web
BodyPix (Tensorflow.js) error: Unknown input type
Posenet (Bodypix uses this) is used in a nodejs server script. You can check how the image is loaded here and is used...
Read more >Added posenet model using the new tfjs-core. · e574eca966
Once the checkpoint is dumped again as a single file, then this can be switched ... This registers the local `posenet` as a...
Read more >@tensorflow-models/posenet - npm package | Snyk
Pretrained PoseNet model in TensorFlow.js For more information about how to use this package see README · Ensure you're using the healthiest npm...
Read more >Hour of Code with p5.js and PoseNet - YouTube
A one hour activity (intermediate level) to create a sketch with p5.js and ml5.js (using TensorFlow.js PoseNet model)#HourOfCode ...
Read more >Advanced TypeScript Programming - Peter O'Hanlon | PDF | Web ...
If you need to check your parameters or manipulate them in some. way, you should use this ... Here, we are using the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Since you are using the ‘canvas’ npm package, you have to pass the
canvas
object tofromPixels
since that’s the one that polyfills browser’s canvas. The workflow is as follows:Hope this helps!
@laurencamblackburn I’m not sure this will solve your problem (it may be node specific), but have you tried making sure the image is loaded first before calling tf.fromPixels?
Check out how the coco demo does it here:
https://github.com/tensorflow/tfjs-models/blob/master/posenet/demos/coco.js#L90