question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

tfjs-models: make pose-detection deno compatible

See original GitHub issue

I am attempting to get tensorflowjs running within deno. A basic script like the following will work:

import * as tf from 'https://cdn.skypack.dev/@tensorflow/tfjs'
import 'https://cdn.skypack.dev/@tensorflow/tfjs-backend-webgpu'

// initialize tensorflow
await tf.setBackend('webgpu')
await tf.ready()
const tensor = tf.tensor1d([0])
tensor.print()
deno run --allow-write --allow-read --unstable mod.ts

I can also load up a model, specifically over http, using the file:// protocol actually still triggers a fetch, which deno fails on.

import * as tf from 'https://cdn.skypack.dev/@tensorflow/tfjs'
import 'https://cdn.skypack.dev/@tensorflow/tfjs-backend-webgpu'

// initialize tensorflow
await tf.setBackend('webgpu')
await tf.ready()

const model = await tf.loadGraphModel(`https://storage.googleapis.com/tfhub-tfjs-modules/google/tfjs-model/movenet/singlepose/lightning/4/model.json`, {
  fetchFunc: fetch
})

However, I would like to be able to reuse some of the code in tfjs-models, since there is a decent amount of code that makes the output from the models useful. This is the following code snippet I want to get working:

import * as tf from 'https://cdn.skypack.dev/@tensorflow/tfjs'
import 'https://cdn.skypack.dev/@tensorflow/tfjs-backend-webgpu'
import * as poseDetection from 'https://cdn.skypack.dev/@tensorflow-models/pose-detection';

// initialize tensorflow
await tf.setBackend('webgpu')
await tf.ready()

const detectorConfig = {
  modelType: poseDetection.movenet.modelType.SINGLEPOSE_LIGHTNING,
}
const detector = await poseDetection.createDetector(poseDetection.SupportedModels.MoveNet, detectorConfig)

System information MacOS M1

  • TensorFlow.js version (you are using): v3.14.0
  • Are you willing to contribute it (Yes/No): Yes

Describe the feature and the current behavior/state. tfjs throws an error

error: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'fetch')
      this.fetch = env().platform.fetch;

Will this change the current api? How? yes, adding a third option to the createDetector method. Example:

const detector = await poseDetection.createDetector(
  poseDetection.SupportedModels.MoveNet,
  detectorConfig,
  { fetchFunc: fetch }
)

Who will benefit with this feature? anyone porting tensoflowjs to deno trying to use the pose detection

Any Other info. deno --version

deno 1.24.1 (release, aarch64-apple-darwin)
v8 10.4.132.20
typescript 4.7.4

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:25 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
vicarycommented, Sep 15, 2022

@andykais Thanks for the hint. It turns out to be me prematurely disposing a tensor before the promise is resolved, we could definitely use a better error message but that’s for another issue.

I can gladly say that my Deno fork basically works for all the use cases I have.

0reactions
haoyunfeixcommented, Dec 22, 2022

@andykais shader problems fixed with #7193, please look forward to the next version(should be https://cdn.skypack.dev/@tensorflow/tfjs-backend-webgpu@0.0.1-alpha.17, not published yet) can be runnable on your demo.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Next-Generation Pose Detection with MoveNet and ...
js. MoveNet is an ultra fast and accurate model that detects 17 keypoints of a body. The model is offered on TF Hub...
Read more >
@tensorflow-models/pose-detection - npm
Pretrained pose detection model. Latest version: 2.0.0, last published: 10 months ago. Start using @tensorflow-models/pose-detection in your ...
Read more >
The Deno Company - Hacker News
We're not yet 100% compatible with browsers in the stdlib, but being compatible ... Deno poses itself partially as node with web standards, ......
Read more >
Notes From JS Nation Live 2020 | Leben++
Visual testing for components ... General thoughts on testing components: ... https://github.com/tensorflow/tfjs-models/tree/master/posenet - Pose Detection ...
Read more >
(PDF) Egypt- Study 31. | Tristan A A Forshaw - Academia.edu
It has in front an architrave excavated from the rock, and supported by two ... a military man, at Eilethya 1 , is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found