Tensorflow.js can’t be used

Hi, I am trying to use TfJs & HandPose for a couple days and JUST CAN’T. TfJs, TfJs Core, webGpu and TfJs-HandPose just can’t work together. There’s dependency hell going on, even after resolving everything somehow, I was getting errors when installing ngx-webcam for example.

Couldn’t do anything but give up.

I wouldn’t try resolving it for days, if it wasn’t a great tool, obviously, TfJs is amazing, but if the devs could work more on making TfJs and its models easier to install & use, it would be great.

If someone‘s doing the same thing with ease or is experienced and doesn’t have problems with it, please tell me how to resolve my issue. Because at this point I don’t even know if I’m wrong or TfJs actually has problems with dependencies.

Thank you.

Can you provide specific details - there is not much to go on here for us to try and replicate? What is your example code / what environment etc / what errors or issues specifically come up for you?

I assume you are using the MediaPipe handpose?

Maybe @ThatJenPerson can comment on this one for MP models.

Can you please provide the following information

  • The operating system you’re using, along with the version
  • The specific list of packages you are trying to install, along with their versions
  • The specific error(s) you see logged when installing
  • What you are seeking to use the HandPose model for

From a MediaPipe perspective, I might recommend you use the new MediaPipe Gesture Recognizer task or Hand Landmark Detector task, depending on your use case. But we can talk more about it once we know more about the issue.

Hi, thank you for helping

  • I am using Windows 10.

  • I’ m installing @tensorflow/tfjs and @tensorflow-models/handpose and importing them in a component, then I’m running ng serve, which gives me these kinds of errors (installing the @latest versions of tfjs and handpose doesn’t work):

Error: node_modules/@tensorflow/tfjs-core/dist/hash_util.d.ts:3:69 - error TS2304: Cannot find name 'Long'.

3 export declare function fingerPrint64(s: Uint8Array, len?: number): Long;
                                                                      ~~~~


Error: node_modules/@tensorflow/tfjs-core/dist/tensor.d.ts:18:23 - error TS4090: Conflicting definitions for '@webgpu/types/dist' found

Error: node_modules/@tensorflow/tfjs/node_modules/@tensorflow/tfjs-core/dist/hash_util.d.ts:2:49 - error TS2304: Cannot find name 'Long'.

2 export declare function hexToLong(hex: string): Long;
                                                  ~~~~


Error: node_modules/@tensorflow/tfjs/node_modules/@tensorflow/tfjs-core/dist/hash_util.d.ts:3:69 - error TS2304: Cannot find name 'Long'.

3 export declare function fingerPrint64(s: Uint8Array, len?: number): Long;
                                                                      ~~~~


Error: node_modules/@tensorflow/tfjs/node_modules/@tensorflow/tfjs-layers/dist/engine/training.d.ts:144:22 - error TS2420: Class 'LayersModel' incorrectly implements interface 'InferenceModel'.
  Types of property 'inputs' are incompatible.
    Type 'SymbolicTensor[]' is not assignable to type 'ModelTensorInfo[]'.
      Type 'SymbolicTensor' is not assignable to type 'ModelTensorInfo'.
        Types of property 'shape' are incompatible.
          Type 'Shape' is not assignable to type 'number[]'.
            Type 'number | null' is not assignable to type 'number'.
              Type 'null' is not assignable to type 'number'.

144 export declare class LayersModel extends Container implements tfc.InferenceModel {
                         ~~~~~~~~~~~


Error: node_modules/@tensorflow/tfjs/node_modules/@tensorflow/tfjs-layers/dist/keras_format/topology_config.d.ts:17:5 - error TS2411: Property 'input_shape' of type 'Shape | undefined' is not assignable to 'string' index type 'PyJsonValue'.

17     input_shape?: Shape;
       ~~~~~~~~~~~


Error: node_modules/@tensorflow/tfjs/node_modules/@tensorflow/tfjs-layers/dist/keras_format/topology_config.d.ts:18:5 - error TS2411: Property 'batch_input_shape' of type 'Shape | undefined' is not assignable to 'string' index type 'PyJsonValue'.

18     batch_input_shape?: Shape;
       ~~~~~~~~~~~~~~~~~


Error: node_modules/@tensorflow/tfjs/node_modules/@tensorflow/tfjs-layers/dist/keras_format/topology_config.d.ts:19:5 - error TS2411: Property 'batch_size' of type 'number | undefined' is not assignable to 'string' index type 'PyJsonValue'.

19     batch_size?: number;
       ~~~~~~~~~~


Error: node_modules/@tensorflow/tfjs/node_modules/@tensorflow/tfjs-layers/dist/keras_format/topology_config.d.ts:20:5 - error TS2411: Property 'dtype' of type 'keyof DataTypeMap | undefined' is not assignable to 'string' index type 'PyJsonValue'.

20     dtype?: DataType;
       ~~~~~


Error: node_modules/@tensorflow/tfjs/node_modules/@tensorflow/tfjs-layers/dist/keras_format/topology_config.d.ts:21:5 - error TS2411: Property 'name' of type 'string | undefined' is not assignable to 'string' index type 'PyJsonValue'.

21     name?: string;
       ~~~~


Error: node_modules/@tensorflow/tfjs/node_modules/@tensorflow/tfjs-layers/dist/keras_format/topology_config.d.ts:22:5 - error TS2411: Property 'trainable' of type 'boolean | undefined' is not assignable to 'string' index type 'PyJsonValue'.

22     trainable?: boolean;
       ~~~~~~~~~

  • I am using HandPose, to create a website where I’m setting up a comprehensive and multi-functional drawing environment, people can draw without even touching a mouse, and if I don’t use a frontend tool for video tracking for example HandPose and use python for example, my website will slow down and server will have a heavy traffic.

Here’s the typescript and tfjs & handpose versions:

TS - 4.9.4, tfjs - 4.2.0, handPose: 0.0.7

Tried:

  1. Updating typescript from 4.9.4 to 4.9.5 ;
  2. setting "strict": false in tsconfig.json ;
  3. adding import '@tensorflow/tfjs-backend-webgl' to imports in the component
  4. Installing the @latest versions of tfjs and handpose

webgpu/types in package.lock.json file has a version of 0.1.16 in some parts, and 0.1.21 in some of them.

Hi can you answer please? I really need help for this one

Hi, I answered the question on what exactly was the problem, can someone answer it please?

Can you try using the MediaPipe Hand Landmark solution:

It doesn’t depend on the tfjs module so you might be able to avoid the dependency issue.