A WebGL accelerated JavaScript library for training and deploying ML models.

Overview

TensorFlow.js

TensorFlow.js is an open-source hardware-accelerated JavaScript library for training and deploying machine learning models.

⚠️ We recently released TensorFlow.js 2.0. If you have been using TensorFlow.js via a script tag without specifying a version and see an error saying no backends are found, then you should read our release notes for instructions on how to upgrade.

Develop ML in the Browser
Use flexible and intuitive APIs to build models from scratch using the low-level JavaScript linear algebra library or the high-level layers API.

Develop ML in Node.js
Execute native TensorFlow with the same TensorFlow.js API under the Node.js runtime.

Run Existing models
Use TensorFlow.js model converters to run pre-existing TensorFlow models right in the browser.

Retrain Existing models
Retrain pre-existing ML models using sensor data connected to the browser or other client-side data.

About this repo

This repository contains the logic and scripts that combine several packages.

APIs:

Backends/Platforms:

If you care about bundle size, you can import those packages individually.

If you are looking for Node.js support, check out the TensorFlow.js Node directory.

Examples

Check out our examples repository and our tutorials.

Gallery

Be sure to check out the gallery of all projects related to TensorFlow.js.

Pre-trained models

Be sure to also check out our models repository where we host pre-trained models on NPM.

Benchmarks

  • Local benchmark tool. Use this webpage tool to collect the performance related metrics (speed, memory, etc) of TensorFlow.js models and kernels on your local device with CPU, WebGL or WASM backends. You can benchmark custom models by following this guide.
  • Multi-device benchmark tool. Use this tool to collect the same performance related metrics on a collection of remote devices.

Getting started

There are two main ways to get TensorFlow.js in your JavaScript project: via script tags or by installing it from NPM and using a build tool like Parcel, WebPack, or Rollup.

via Script Tag

Add the following code to an HTML file:

<html>
  <head>
    <!-- Load TensorFlow.js -->
    <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs/dist/tf.min.js"> </script>


    <!-- Place your code in the script tag below. You can also use an external .js file -->
    <script>
      // Notice there is no 'import' statement. 'tf' is available on the index-page
      // because of the script tag above.

      // Define a model for linear regression.
      const model = tf.sequential();
      model.add(tf.layers.dense({units: 1, inputShape: [1]}));

      // Prepare the model for training: Specify the loss and the optimizer.
      model.compile({loss: 'meanSquaredError', optimizer: 'sgd'});

      // Generate some synthetic data for training.
      const xs = tf.tensor2d([1, 2, 3, 4], [4, 1]);
      const ys = tf.tensor2d([1, 3, 5, 7], [4, 1]);

      // Train the model using the data.
      model.fit(xs, ys).then(() => {
        // Use the model to do inference on a data point the model hasn't seen before:
        // Open the browser devtools to see the output
        model.predict(tf.tensor2d([5], [1, 1])).print();
      });
    </script>
  </head>

  <body>
  </body>
</html>

Open up that HTML file in your browser, and the code should run!

via NPM

Add TensorFlow.js to your project using yarn or npm. Note: Because we use ES2017 syntax (such as import), this workflow assumes you are using a modern browser or a bundler/transpiler to convert your code to something older browsers understand. See our examples to see how we use Parcel to build our code. However, you are free to use any build tool that you prefer.

import * as tf from '@tensorflow/tfjs';

// Define a model for linear regression.
const model = tf.sequential();
model.add(tf.layers.dense({units: 1, inputShape: [1]}));

// Prepare the model for training: Specify the loss and the optimizer.
model.compile({loss: 'meanSquaredError', optimizer: 'sgd'});

// Generate some synthetic data for training.
const xs = tf.tensor2d([1, 2, 3, 4], [4, 1]);
const ys = tf.tensor2d([1, 3, 5, 7], [4, 1]);

// Train the model using the data.
model.fit(xs, ys).then(() => {
  // Use the model to do inference on a data point the model hasn't seen before:
  model.predict(tf.tensor2d([5], [1, 1])).print();
});

See our tutorials, examples and documentation for more details.

Importing pre-trained models

We support porting pre-trained models from:

Find out more

TensorFlow.js is a part of the TensorFlow ecosystem. For more info:

Thanks, BrowserStack, for providing testing support.

Comments
  • Google Meet background segmentation model

    Google Meet background segmentation model

    System information

    • TensorFlow.js version (you are using): 2
    • Are you willing to contribute it (Yes/No): No, it's not mine

    Describe the feature and the current behavior/state. This Google AI blog post describes the background segmentation model used in Google Meet. This model would be an excellent complement to the models in the tfjs-models collection. (The existing BodyPix model can be (ab)used for background segmentation, but has quality and performance issues for this use-case. I expect the Google Meet model improves on this.)

    Will this change the current api? How? No, it would be an addition to tfjs-models.

    Who will benefit with this feature? Apps consuming and/or displaying a user-facing camera feed. WebRTC video chat apps are the most obvious, where background blur/replacement is becoming expected. I also expect it could be a useful preprocessing step before applying e.g. PoseNet. It can also be used creatively on images as a pre-processing step -- for example, this recent app to enhance profile pictures integrates a background segmentation solution.

    type:feature stat:awaiting response stalled 
    opened by jameshfisher 107
  • Unsupported system error when installing on M1 / Apple Silicon

    Unsupported system error when installing on M1 / Apple Silicon

    System information

    • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): macOS 11.0.1 (20B29)
    • TensorFlow.js installed from (npm or script link): npm
    • TensorFlow.js version: 2.8.3

    Describe the problem

    Installation fails due to a missing precompiled libtensorflow for darwin / arm64.

    Apple has their own fork of TensorFlow supporting their chips-- is there a way to tell the installation script to use their libtensorflow.dylib?

    Provide the exact sequence of commands / steps that you executed before running into the problem

    npm install @tensorflow/tfjs-node --save

    Any other info / logs

    npm ERR! code 1
    npm ERR! path /Users/nicklee/Documents/Development/<redacted>/src/<redacted>/node_modules/@tensorflow/tfjs-node
    npm ERR! command failed
    npm ERR! command sh -c node scripts/install.js
    npm ERR! CPU-darwin-2.8.3.tar.gz
    npm ERR! * Downloading libtensorflow
    npm ERR! /Users/nicklee/Documents/Development/<redacted>/src/<redacted>/node_modules/@tensorflow/tfjs-node/scripts/install.js:100
    npm ERR!     throw new Error(`Unsupported system: ${libType}-${platform}-${os.arch()}`);
    npm ERR!           ^
    npm ERR! 
    npm ERR! Error: Unsupported system: cpu-darwin-arm64
    npm ERR!     at getPlatformLibtensorflowUri (/Users/nicklee/Documents/Development/<redacted>/src/<redacted>/node_modules/@tensorflow/tfjs-node/scripts/install.js:100:11)
    npm ERR!     at downloadLibtensorflow (/Users/nicklee/Documents/Development/<redacted>/src/<redacted>/node_modules/@tensorflow/tfjs-node/scripts/install.js:134:7)
    npm ERR!     at async run (/Users/nicklee/Documents/Development/<redacted>/src/<redacted>/node_modules/@tensorflow/tfjs-node/scripts/install.js:197:5)
    
    npm ERR! A complete log of this run can be found in:
    npm ERR!     /Users/nicklee/.npm/_logs/2021-01-09T02_53_09_673Z-debug.log
    
    type:build/install 
    opened by nickplee 94
  • Error: TensorList shape mismatch: Shapes -1 and 3 must match - CONTINUE

    Error: TensorList shape mismatch: Shapes -1 and 3 must match - CONTINUE

    I've been working for a week. This error appears to be from open source applications that were not in previous versions. I even tried from old models. They are working. But the one I just created doesn't work.

    This error continues. How do we fix this?

    tfjs-core: ^3.0.0
    tfjs-converter: ^3.0.0
    TF 2.4.1
    Python 3.6.9
    

    Originally posted by @umitkacar in https://github.com/tensorflow/tfjs/issues/4641#issuecomment-779332368

    type:support stat:awaiting response stalled 
    opened by umitkacar 56
  • Cannot import @tensorflow/tfjs-node-gpu on Windows

    Cannot import @tensorflow/tfjs-node-gpu on Windows

    To get help from the community, we encourage using Stack Overflow and the tensorflow.js tag.

    TensorFlow.js version

    1.2.9

    Browser version

    Using NodeJS: v12.10.0

    Describe the problem or feature request

    Cannot import @tensorflow/tfjs-node-gpu at all, only @tensorflow/tfjs-node but I'd like to use my GPU.

    Code to reproduce the bug / link to feature request

    require('@tensorflow/tfjs-node-gpu');

    Here is the error:

    `internal/modules/cjs/loader.js:977 return process.dlopen(module, path.toNamespacedPath(filename)); ^

    Error: The specified module could not be found. \?\D:\Programming\NodeJS Work\dumb-doorbell\server\node_modules@tensorflow\tfjs-node-gpu\lib\napi-v4\tfjs_binding.node at Object.Module._extensions..node (internal/modules/cjs/loader.js:977:18) at Module.load (internal/modules/cjs/loader.js:790:32) at Function.Module._load (internal/modules/cjs/loader.js:703:12) at Module.require (internal/modules/cjs/loader.js:830:19) at require (internal/modules/cjs/helpers.js:68:18) at Object. (D:\Programming\NodeJS Work\dumb-doorbell\server\node_modules@tensorflow\tfjs-node-gpu\dist\index.js:44:16) at Module._compile (internal/modules/cjs/loader.js:936:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10) at Module.load (internal/modules/cjs/loader.js:790:32) at Function.Module._load (internal/modules/cjs/loader.js:703:12) `

    I've tried reinstalling all my modules, tried using Recommended Node version, tried rebuilding the package, idk what else to try so I'm hoping to get some way to fix this from here

    comp:node.js P0 
    opened by gobboo 55
  • React production build will not compile TensorFlow.js  2.0

    React production build will not compile TensorFlow.js 2.0

    To get help from the community, we encourage using Stack Overflow and the tensorflow.js tag.

    2.0 TensorFlow.js version

    Chrome Version 83.0.4103.61 (Official Build) (64-bit)

    Hello, when building the react app in Development mode the tensorFlowJS 2.0 model worked just fine, but when using the built version from reactjs, I get an error related to tensorflow,

    Uncaught (in promise) TypeError: Cannot call a class as a function at r (classCallCheck.js:3) at new e (tensor.ts:395) at e.value (engine.ts:714) at l (tensor_ops.ts:113) at c (tensor_ops.ts:59) at Module.d (io_utils.ts:180) at e.<anonymous> (graph_model.ts:128) at s (runtime.js:45) at Generator._invoke (runtime.js:274) at Generator.forEach.e.<computed> [as next] (runtime.js:97)

    [solution] rolled back tensorFlowJS version 1.0.1 and it compiled for production. We were never able to pinpoint the problem but I thought I should flag this.

    GitHub issues for this repository are tracked in the tfjs union repository.

    Please file your issue there, following the guidance in that issue template.

    comp:core type:others stat:awaiting response 
    opened by JoeJoeMango 43
  • Tensorflow Object Detection API Model - Unsupported Ops in ssd_mobilenet_v2 model

    Tensorflow Object Detection API Model - Unsupported Ops in ssd_mobilenet_v2 model

    To get help from the community, check out our Google group.

    TensorFlow.js version

    @tensorflow/tfjs-converter: 0.1.1 (this was installed through pip)

    Browser version

    N/A (issue is related to tensorflowjs_converter)

    Describe the problem or feature request

    Unsupported Ops

    I tried running the tensorflowjs_converter as follows: tensorflowjs_converter \ --input_format=tf_saved_model \ --output_node_names='detection_boxes,detection_classes,detection_scores,num_detections' \ --saved_model_tags=serve \ ~/workspace/model/saved_model \ ~/workspace/model/web_model

    Once it is complete, I get the following output of unsupported ops: All, Assert, Enter, Exit, LoopCond, Merge, NextIteration, NonMaxSuppressionV2, Rank, ResizeBilinear, Size, Split, StridedSlice, Switch, TensorArrayGatherV3, TensorArrayReadV3, TensorArrayScatterV3, TensorArraySizeV3, TensorArrayV3, TensorArrayWriteV3, TopKV2, Unpack, Where This is a ssd_mobilenet_v2_coco model trained through tensorflow object detection api. It is performing well on tensorflow, but it contains ops not supported by tensorflowjs. I have tried several other models from the tensorflow model zoo, and they all have similiar unsupported ops.

    Code to reproduce the bug / link to feature request

    I found this GIST describing the exact issue: Convert Tensorflow SavedModel to WebModel for TF-JS From this GIST I got the following:

    # Download the model files. 
    wget http://download.tensorflow.org/models/object_detection/ssd_mobilenet_v2_coco_2018_03_29.tar.gz 
    
    # Untar the model .
    tar -xzvf ssd_mobilenet_v2_coco_2018_03_29.tar.gz
    
    pip install tensorflow-gpu # Or just tensorflow for CPU
    pip install tensorflowjs
    
    saved_model_cli show --dir ssd_mobilenet_v2_coco_2018_03_29/saved_model --tag_set serve --signature_def serving_default
    
    tensorflowjs_converter \
        --input_format=tf_saved_model \
        --output_node_names='detection_boxes,detection_scores,num_detections,detection_classes' \
        --saved_model_tags=serve \
        ./ssd_mobilenet_v2_coco_2018_03_29/saved_model \
        ./ssd_mobilenet_v2_coco_2018_03_29/web_model
    
    

    Thanks!

    comp:core comp:converter 
    opened by threedayoldcoffee 43
  • Bi-Directional LSTM model with Embedding layer for Language Translation

    Bi-Directional LSTM model with Embedding layer for Language Translation

    Hi,

    I have created a Bi-Directional LSTM model with Embedding layer in Keras (Python) for Language Translation and converted to tfjs Graph model. In the Keras (python) model, I give the input to model for prediction as an array of padded sequences (using Tokenizer, dataset is first fit_on_texts(), texts_to_sequences() and then pad_sequences()). So, for training and prediction I use the array of padded sequences (sentences). This way the model works perfectly.

    Input layer of the model: model.add(Embedding(src_vocab, n_units, input_length=src_timesteps, mask_zero=True)) src_vocab - 30973 n_units - 256 src_timesteps - 109

    But in tfjs, when I give a tokenized, padded sentence converted to tensor2d and give as input for model.executeAsync() function, it doesn't accept and I get the below error.

    Uncaught (in promise) Error: Error in where: Shapes 1,1 and 1,256 must match

    I am quite new to tfjs and would appreciate any inputs on the above.

    Thanks in advance.

    type:others stat:awaiting response 
    opened by jaygit123 42
  • Error when installing @tensorflow/tfjs-node

    Error when installing @tensorflow/tfjs-node

    To get help from the community, check out our Google group.

    TensorFlow.js version

    Browser version

    Describe the problem or feature request

    Error when installing `@tensorflow/tfjs-node``

    I get this Error:

    Error: node-gyp rebuild failed with: Error: Command failed: node-gyp rebuild Traceback (most recent call last): File "/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py", line 16, in <module> sys.exit(gyp.script_main()) File "/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 545, in script_main return main(sys.argv[1:]) File "/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 538, in main return gyp_main(args) File "/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 523, in gyp_main generator.GenerateOutput(flat_list, targets, data, params) File "/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 2213, in GenerateOutput part_of_all=qualified_target in needed_targets) File "/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 793, in Write extra_mac_bundle_resources, part_of_all) File "/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 967, in WriteActions "Spaces in action input filenames not supported (%s)" % input) AssertionError: Spaces in action input filenames not supported (/Users/jonas/Web Dev/NodeJS/RestAPITest/node_modules/@tensorflow/tfjs-node/scripts/deps-stage.js) gyp ERR! configure error gyp ERR! stack Error:gyp` failed with exit code: 1 gyp ERR! stack at ChildProcess.onCpExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:345:16) gyp ERR! stack at emitTwo (events.js:126:13) gyp ERR! stack at ChildProcess.emit (events.js:214:7) gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12) gyp ERR! System Darwin 17.5.0 gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild" gyp ERR! cwd /Users/jonas/Web Dev/NodeJS/RestAPITest/node_modules/@tensorflow/tfjs-node gyp ERR! node -v v8.11.2 gyp ERR! node-gyp -v v3.8.0 gyp ERR! not ok

    at cp.exec (/Users/jonas/Web Dev/NodeJS/RestAPITest/node_modules/@tensorflow/tfjs-node/scripts/install.js:154:13)
    at ChildProcess.exithandler (child_process.js:282:5)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at maybeClose (internal/child_process.js:925:16)
    at Socket.stream.socket.on (internal/child_process.js:346:11)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at Pipe._handle.close [as _onclose] (net.js:557:12)
    

    npm WARN [email protected] No description npm WARN [email protected] No repository field.

    npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! @tensorflow/[email protected] install: node scripts/install.js npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the @tensorflow/[email protected] install script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

    npm ERR! A complete log of this run can be found in: npm ERR! /Users/jonas/.npm/_logs/2018-09-19T16_23_53_635Z-debug.log Jonass-MBP:RestAPITest jonas$`

    Code to reproduce the bug / link to feature request

    Running npm install @tensorflow/tfjs-node on a Mac with Node version 6.4.1. XCode is installed.

    type:build/install 
    opened by JonasJW 42
  • major difference in performance between sync and async methods to download tensor data

    major difference in performance between sync and async methods to download tensor data

    when using webgl backend, tensor.dataSync() is about 35% faster than await tensor.data() when returning larger amounts of data
    (in my case, model takes 720x720x3 image as input and produces 720x720x3 image as output)

    actual timings are ~100ms for tensor.dataSync() and ~140ms for await tensor.data()
    note that there is nothing else executing, this is a single active loop

    i wouldn't mind using dataSync(), but then again any sync calls are not compatible with webgpu backend and maintaining two separate codepaths for webgl and webgpu is a no-op

    btw, model in question can be found at https://github.com/vladmandic/anime

    environment: tfjs 3.19..0 on chrome 103

    type:bug 
    opened by vladmandic 37
  • [webgl] enabling WEBGL_USE_SHAPES_UNIFORMS results in model execution returning null values

    [webgl] enabling WEBGL_USE_SHAPES_UNIFORMS results in model execution returning null values

    user reported issue with my library and after a while it was traced down to WEBGL_USE_SHAPES_UNIFORMS
    which i have enabled by default for over half a year now due to massive performance advantages

    issue itself is that model execution shows no issues and it returns tensors in expected shape,
    but tensor data is an array with all null values instead of expected float32 values

    what is strange that on majority of systems there are no issues (plus i cannot reproduce locally)
    and there is only single (quite small) affected model out of 10+ used

    affected model

    very simple code reproduction (again, i cannot reproduce myself)
    (it runs a model using predefined image input and checks output validity)

    test has tfjs debug enabled and you can see all ops in the browser console

    environment:

    • tfjs: 3.20.0 (older versions are also affected)
    • browser: chrome 104 and 105
    • os: windows 10 pro

    it's reported on two different systems using different graphics adapters (AMD Radeon and nVidia RTX)
    both affected systems report no issues looking at chrome://gpu and webgl v2 is working fine

    only other thing worth noting is that user is using non-latin os locale

    link to original issue: https://github.com/vladmandic/human/issues/291

    type:bug 
    opened by vladmandic 34
  • Npm installation fails.

    Npm installation fails.

    Update: The original content of this thread is not important any more. Please keep 2 things in mind in order to install tenforflow.js successfully. 1, npm could be slow, as you might already know. To solve this, you can update npm to its very latest version or you can try yarn. If you are in China, yarn is generally faster. Also, when you use yarn in windows, you probably get a link from your powershell, open that page, search for Set-ExecutionPolicy. Or you simply type Set-ExecutionPolicy in your powershell and then Bypass and then to all. If you care, set it back to Default after using yarn. 2, Any extra firewall, safety and security software may mess any installation. My A***t messed all my vs2022 updating and npm(and pip when I tried pip install tensorflow). After turning it off, I reinstalled vs2022, and started up with a new react project, yarn installed tfjs, and they all worked again. Notice, I only mean the EXTRA safery softwares, I didn't turn off the default firewall came along with windows to fix my dev env. 3, A trivial detail. I don't know how to setup tfjs with pure node.js. But it's easy to setup with any react template if you use visual studio. I didn't try but I guess it's the same way to setup with vue or angular. The key is that, tfjs needs dom. If this update helps or not, please let me know. Feel free to comment in here.

    Original content: System information

    • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 10
    • 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): npm install @tensorflow/tfjs-node-gpu
    • TensorFlow.js version: 3.12.0
    • CUDA/cuDNN version: [email protected], [email protected] #define CUDNN_MAJOR 8 #define CUDNN_MINOR 3 #define CUDNN_PATCHLEVEL 1

    Describe the problem I opened up a default react ts project in vs 2022 stable version. View -> terminal. In terminal, npm install @tensorflow/tfjs or tfjs-node or tfjs-node-gpu. None of them works. I also tried npm install in the terminal directly opened from Windows 10 and failed. I don't know if this issue is caused by the internet since I'm in China. The familiar 404, you know.

    Provide the exact sequence of commands / steps that you executed before running into the problem As above.

    Any other info / logs npm install @tensorflow/tfjs-node-gpu

    @tensorflow/[email protected] install E:\ts practice\tfjs with ts test\tfjsWithTsTest\tfjsWithTsTest\node_modules@tensorflow\tfjs-node-gpu node scripts/install.js gpu download

    GPU-windows-3.12.0.zip

    • Downloading libtensorflow https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-windows-x86_64-2.7.0.zip [==============================] 11266495/bps 100% 0.0s
    • Building TensorFlow Node.js bindings node-pre-gyp install failed with error: Error: Command failed: node-pre-gyp install --fallback-to-build node-pre-gyp ERR! install response status 404 Not Found on https://storage.googleapis.com/tf-builds/pre-built-binary/napi-v8/3.12.0/GPU-windows-3.12.0.zip node-pre-gyp WARN Pre-built binaries not installable for @tensorflow/[email protected] and [email protected] (node-v83 ABI, unknown) (falling back to source compile with node-gyp) node-pre-gyp WARN Hit error response status 404 Not Found on https://storage.googleapis.com/tf-builds/pre-built-binary/napi-v8/3.12.0/GPU-windows-3.12.0.zip gyp ERR! find VS gyp ERR! find VS msvs_version not set from command line or npm config gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt gyp ERR! find VS unknown version "undefined" found at "C:\Program Files\Microsoft Visual Studio\2022\Community" gyp ERR! find VS checking VS2019 (16.11.31911.196) found at: gyp ERR! find VS "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community" gyp ERR! find VS - found "Visual Studio C++ core features" gyp ERR! find VS - found VC++ toolset: v142 gyp ERR! find VS - missing any Windows SDK gyp ERR! find VS could not find a version of Visual Studio 2017 or newer to use gyp ERR! find VS looking for Visual Studio 2015 gyp ERR! find VS - not found gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8 gyp ERR! find VS gyp ERR! find VS ************************************************************** gyp ERR! find VS You need to install the latest version of Visual Studio gyp ERR! find VS including the "Desktop development with C++" workload. gyp ERR! find VS For more information consult the documentation at: gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows gyp ERR! find VS ************************************************************** gyp ERR! find VS gyp ERR! configure error gyp ERR! stack Error: Could not find any Visual Studio installation to use gyp ERR! stack at VisualStudioFinder.fail (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:121:47) gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:74:16 gyp ERR! stack at VisualStudioFinder.findVisualStudio2013 (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:351:14) gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:70:14 gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:372:16 gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\util.js:54:7 gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\util.js:33:16 gyp ERR! stack at ChildProcess.exithandler (child_process.js:326:5) gyp ERR! stack at ChildProcess.emit (events.js:375:28) gyp ERR! stack at maybeClose (internal/child_process.js:1055:16) gyp ERR! System Windows_NT 10.0.19043 gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "configure" "--fallback-to-build" "--module=E:\ts practice\tfjs with ts test\tfjsWithTsTest\tfjsWithTsTest\node_modules\@tensorflow\tfjs-node-gpu\lib\napi-v8\tfjs_binding.node" "--module_name=tfjs_binding" "--module_path=E:\ts practice\tfjs with ts test\tfjsWithTsTest\tfjsWithTsTest\node_modules\@tensorflow\tfjs-node-gpu\lib\napi-v8" "--napi_version=8" "--node_abi_napi=napi" "--napi_build_version=8" "--node_napi_label=napi-v8" gyp ERR! cwd E:\ts practice\tfjs with ts test\tfjsWithTsTest\tfjsWithTsTest\node_modules@tensorflow\tfjs-node-gpu gyp ERR! node -v v14.17.3 gyp ERR! node-gyp -v v5.1.0 gyp ERR! not ok node-pre-gyp ERR! build error node-pre-gyp ERR! stack Error: Failed to execute 'C:\Program Files\nodejs\node.exe C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js configure --fallback-to-build --module=E:\ts practice\tfjs with ts test\tfjsWithTsTest\tfjsWithTsTest\node_modules@tensorflow\tfjs-node-gpu\lib\napi-v8\tfjs_binding.node --module_name=tfjs_binding --module_path=E:\ts practice\tfjs with ts test\tfjsWithTsTest\tfjsWithTsTest\node_modules@tensorflow\tfjs-node-gpu\lib\napi-v8 --napi_version=8 --node_abi_napi=napi --napi_build_version=8 --node_napi_label=napi-v8' (1) node-pre-gyp ERR! stack at ChildProcess. (E:\ts practice\tfjs with ts test\tfjsWithTsTest\tfjsWithTsTest\node_modules@mapbox\node-pre-gyp\lib\util\compile.js:89:23) node-pre-gyp ERR! stack at ChildProcess.emit (events.js:375:28) node-pre-gyp ERR! stack at maybeClose (internal/child_process.js:1055:16) node-pre-gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5) node-pre-gyp ERR! System Windows_NT 10.0.19043 node-pre-gyp ERR! command "C:\Program Files\nodejs\node.exe" "E:\ts practice\tfjs with ts test\tfjsWithTsTest\tfjsWithTsTest\node_modules\@mapbox\node-pre-gyp\bin\node-pre-gyp" "install" "--fallback-to-build" node-pre-gyp ERR! cwd E:\ts practice\tfjs with ts test\tfjsWithTsTest\tfjsWithTsTest\node_modules@tensorflow\tfjs-node-gpu node-pre-gyp ERR! node -v v14.17.3 node-pre-gyp ERR! node-pre-gyp -v v1.0.4 node-pre-gyp ERR! not ok

    npm WARN @babel/[email protected] requires a peer of @babel/core@^7.13.0 but none is installed. You must install peer dependencies yourself. npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"}) npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\webpack-dev-server\node_modules\fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"}) npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\watchpack-chokidar2\node_modules\fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

    npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! @tensorflow/[email protected] install: node scripts/install.js gpu download npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the @tensorflow/[email protected] install script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

    npm ERR! A complete log of this run can be found in: One last line is note copied. It's only a path.

    Tomorrow I'll try installing the python version with pip to check if both ways fail. Btw, would you please add some guide for typescript with tf. The type system is too helpful. Thanks.

    type:build/install stat:awaiting tensorflower stat:awaiting response stalled 
    opened by YagaoDirac 34
  • hand-pose-detection: 'tfjs-webgl' backend returns NaN values

    hand-pose-detection: 'tfjs-webgl' backend returns NaN values

    System information

    • OS Platform and Distribution: iOS 15.7.2
    • Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device: iPhone 7 Plus
    • TensorFlow.js installed from (npm or script link): @tensorflow-models/hand-pose-detection
    • TensorFlow.js version (use command below): 4.1.0
    • Browser version: Safari 15.7.2
    • Tensorflow.js Converter Version: 4.1.0

    Describe the current behavior I'm setting the hand-pose-detection model following the https://storage.googleapis.com/tfjs-models/demos/hand-pose-detection/index.html?model=mediapipe_hands example

    In my code, setting the mediapipe runtime works fine, although setting the 'tfjs-webgl' runtime returns NaN values of x,y coordinates.

    Detector initialization:

    detectorConfig = {
            runtime: 'tfjs',
            modelType: 'full',
            maxHands: 1
          }
          handDetector = await handPoseDetection.createDetector(model, detectorConfig)
    

    Estimate hand data:

    try {
          handData = await handDetector.estimateHands(sourceElement, 
            {flipHorizontal: isFlipHorizontal}         // flipHorizontal: false, if we want the result to flip horizontaly. Defaults is set to false.
          )       
        } catch (error) {
          handDetector.dispose()
          handDetector = null
          alert(error)
        }
    

    Logged detector output:

    nan-tfjs

    Tensorflow environment flags:

    tfjs-env-flags

    I would appreciate any suggestion on how to fix this issue. Maybe I'm missing some other detector configuration or setting? Thanks!

    type:bug 
    opened by mikkamikka 1
  • Hand-pose-detection demos are failing to build/run

    Hand-pose-detection demos are failing to build/run

    System information

    • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 10
    • TensorFlow.js installed from (npm or script link): https://github.com/tensorflow/tfjs-models/tree/master/hand-pose-detection/demos
    • TensorFlow.js version: 3.9.0

    Describe the problem

    Any attempt running hand-pose detection demos locally failed. I followed the instructions listed here https://github.com/tensorflow/tfjs-models/tree/master/hand-pose-detection/demos#how-to-run-a-demo

    Step 2 ("Remove cache etc. rm -rf .cache dist node_modules") throws an error:

    Remove-Item : A parameter cannot be found that matches parameter name 'rf'.
    

    Step 3 ("Build dependency. yarn build-dep") throws a bunch of 27 errors, typical one of:

    src/mediapipe/mediapipe_test.ts:25:65 - error TS2307: Cannot find module '../shared/test_util' or its corresponding type declarations.
    

    etc.

    Any suggestion for the correct demos build and run sequence?

    Thanks!

    type:build/install 
    opened by mikkamikka 1
  • TFJS : Error: All values in axis param must be in range [-4, 4) but got axis -272777233,-1074807361

    TFJS : Error: All values in axis param must be in range [-4, 4) but got axis -272777233,-1074807361

    TensorFlow.js version: "@tensorflow/tfjs": "^4.1.0"

    Capture d’écran 2022-12-28 à 23 04 47

    I get this error message during prediction but the problem comes from the way the model was loaded. Indeed, when I load my model with tf.loadGraphModel and my model (.json + .bin) is on local or public server I have no problem. when the model is loaded (without error message) from an external filesystem I get this problem. I'm sure that the .json has been loaded correctly and that it refers to the .bin weights. Where I have a doubt is on the encoding or format of the .bin that are returned through the filesystem.

    However when I consult the responses to the requests, it seems that the .bin is complete:

    (locally with predictions that work) Capture d’écran 2022-12-28 à 23 14 02 (locally with predictions KO) Capture d’écran 2022-12-28 à 23 13 22

    Please, Is there anything I missed?

    (the filesystem extracts the data "application/octet-stream" and I return the buffer (data.Body) as it seems to be done when the model is served locally)

    thank you in advance for your help

    type:others 
    opened by ygf8 3
  • [Error: Operands could not be broadcast together with shapes 285 and 285,39.]

    [Error: Operands could not be broadcast together with shapes 285 and 285,39.]

    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): Windows 11 version 22H2 build 22621.963
    • Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device: Using Iphone 8 and Oppo A9 2020 as simulator
    • TensorFlow.js installed from (npm or script link): FROM NPM
    • TensorFlow.js version (use command below): 3.3.0 (I have also used the lastest before, but from recent researches about my bug someone made it worked with 3.3.0 but I haven't when I tried)
    • Browser version: Firefox 108.0.1 (64-bit)
    • Tensorflow.js Converter Version: 3.3.0? same as TensorflowJS?

    Describe the current behavior I am a beginner in Machine Learning, I am currently doing this for my thesis application. I am trying to integrate MobilenetV3 with React-Native Expo. I trained my mobilenetv3 following this tutorial: https://tensorflow-object-detection-api-tutorial.readthedocs.io/en/tensorflow-1.14/training.html inserting mobilenetv3 into the pipeline.config and adjusting steps and batches.

    After succesfully training and exporting (from the tutorial), I then converted the exported files using tensorflowjs and tensorflowjs_converter. I followed the tutorial from: https://www.tensorflow.org/js/tutorials/conversion/import_saved_model I have even tried both tf_frozen_model and tf_saved_model as input, and specified output_node_names. I have successfully converted on both types. I also successfully loaded (as far as I can understand) it when running in the mobile application. The problem is after putting an image in the loaded model it displays this error [Error: Operands could not be broadcast together with shapes 285 and 285,39.] I will be providing here the code of my Camera.js and Model.js CODES.zip

    Describe the expected behavior The output should be properly predicted without error if im not mistaken in following tutorials and documentations.

    Standalone code to reproduce the issue See uploaded files

    Other info / logs Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached.

    type:bug 
    opened by maxnuggets 1
  • Boolean OR, AND, XOR, BitCount: Reduction operators over integers

    Boolean OR, AND, XOR, BitCount: Reduction operators over integers

    Please make sure that this is a feature request. As per our GitHub Policy, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:feature_template

    System information

    • TensorFlow.js version (you are using): 4.1.0
    • Are you willing to contribute it (Yes/No): Would be glad to but do not have the expertise

    Describe the feature and the current behavior/state. Kindly add boolean AND, OR, XOR , bitCount as reduction operators over integer typed tensors.

    For example, for a 2-dimensional matrix, column-wise boolean AND/OR/XOR reduction should result in a 1-dimensional tensor etc. Similarly row-wise etc.

    Will this change the current api? How? New reduction operators may need to be added in addition to the existing sum, prod etc. operators.

    These below new reduction operators may have to be added for the integer dType:

    • boolean reduction operators: AND, OR, XOR
    • bitCount reduction operator that returns the total number of bits that are 1 in the given axis

    Who will benefit with this feature?

    • Boolean operators enable bit-packing, which will vastly reduce the memory requirement in boolean matrix manipulation senarios. For example, boolean matrix multiplication currently forces us to use "int32" dType, (the bool type is mostly restricted to just logical operators currently it seems). Enabling boolean reduction operators allows extending the boolean operations further into arithmetic, than just logical.

    Any Other info.

    type:feature 
    opened by KrishnaPG 5
  • [webgpu] Let vectorized binary op return an overridable value on NaN

    [webgpu] Let vectorized binary op return an overridable value on NaN

    This is like

    2c95a67 [webgpu] Further tweak vectorized NaN handling in binary ops

    but for valueForNaN.

    To see the logs from the Cloud Build CI, please join either our discussion or announcement mailing list.


    This change is Reviewable

    opened by hujiajie 0
Releases(tfjs-v4.1.0)
WebGL-accelerated ML // linear algebra // automatic differentiation for JavaScript.

This repository has been archived in favor of tensorflow/tfjs. This repo will remain around for some time to keep history but all future PRs should be

null 8.5k Dec 31, 2022
Run Keras models in the browser, with GPU support using WebGL

**This project is no longer active. Please check out TensorFlow.js.** The Keras.js demos still work but is no longer updated. Run Keras models in the

Leon Chen 4.9k Dec 29, 2022
This is a JS/TS library for accelerated tensor computation intended to be run in the browser.

TensorJS TensorJS How to use Tensors Tensor operations Reading values Data types Converting between backends Onnx model support Optimizations Running

Frithjof Winkelmann 32 Jun 26, 2022
Train and test machine learning models for your Arduino Nano 33 BLE Sense in the browser.

Tiny Motion Trainer Train and test IMU based TFLite models on the Web Overview Since 2009, coders have created thousands of experiments using Chrome,

Google Creative Lab 59 Nov 21, 2022
Visualizer for neural network, deep learning, and machine learning models

Netron is a viewer for neural network, deep learning and machine learning models. Netron supports ONNX, TensorFlow Lite, Caffe, Keras, Darknet, Paddle

Lutz Roeder 21k Jan 5, 2023
A JavaScript deep learning and reinforcement learning library.

neurojs is a JavaScript framework for deep learning in the browser. It mainly focuses on reinforcement learning, but can be used for any neural networ

Jan 4.4k Jan 4, 2023
A neural network library built in JavaScript

A flexible neural network library for Node.js and the browser. Check out a live demo of a movie recommendation engine built with Mind. Features Vector

Steven Miller 1.5k Dec 31, 2022
Linear Regression library in pure Javascript

Lyric Linear Regression library in pure Javascript Lyric can help you analyze any set of x,y series data by building a model that can be used to: Crea

Flurry, Inc. 43 Dec 22, 2020
architecture-free neural network library for node.js and the browser

Synaptic Important: Synaptic 2.x is in stage of discussion now! Feel free to participate Synaptic is a javascript neural network library for node.js a

Juan Cazala 6.9k Dec 27, 2022
An NLP library for building bots, with entity extraction, sentiment analysis, automatic language identify, and so more

NLP.js If you're looking for the version 3 docs, you can find them here Version 3 "NLP.js" is a general natural language utility for nodejs. Currently

AXA 5.3k Dec 29, 2022
A lightweight library for neural networks that runs anywhere

Synapses A lightweight library for neural networks that runs anywhere! Getting Started Why Sypapses? It's easy Add one dependency to your project. Wri

Dimos Michailidis 65 Nov 9, 2022
A library for prototyping realtime hand detection (bounding box), directly in the browser.

Handtrack.js View a live demo in your browser here. Handtrack.js is a library for prototyping realtime hand detection (bounding box), directly in the

Victor Dibia 2.7k Jan 3, 2023
A speech recognition library running in the browser thanks to a WebAssembly build of Vosk

A speech recognition library running in the browser thanks to a WebAssembly build of Vosk

Ciaran O'Reilly 207 Jan 3, 2023
Machine Learning library for node.js

shaman Machine Learning library for node.js Linear Regression shaman supports both simple linear regression and multiple linear regression. It support

Luc Castera 108 Feb 26, 2021
Support Vector Machine (SVM) library for nodejs

node-svm Support Vector Machine (SVM) library for nodejs. Support Vector Machines Wikipedia : Support vector machines are supervised learning models t

Nicolas Panel 296 Nov 6, 2022
machinelearn.js is a Machine Learning library written in Typescript

machinelearn.js is a Machine Learning library written in Typescript. It solves Machine Learning problems and teaches users how Machine Learning algorithms work.

machinelearn.js 522 Jan 2, 2023
FANN (Fast Artificial Neural Network Library) bindings for Node.js

node-fann node-fann is a FANN bindings for Node.js. FANN (Fast Artificial Neural Network Library) is a free open source neural network library, which

Alex Kocharin 186 Oct 31, 2022
JavaScript API for face detection and face recognition in the browser and nodejs with tensorflow.js

face-api.js JavaScript face recognition API for the browser and nodejs implemented on top of tensorflow.js core (tensorflow/tfjs-core) Click me for Li

Vincent Mühler 14.6k Jan 2, 2023
Simple Javascript implementation of the k-means algorithm, for node.js and the browser

#kMeans.js Simple Javascript implementation of the k-means algorithm, for node.js and the browser ##Installation npm install kmeans-js ##Example (JS)

Emil Bay 44 Aug 19, 2022