WebGL-accelerated ML // linear algebra // automatic differentiation for JavaScript.

Overview

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 sent to tensorflow/tfjs inside the tfjs-core folder.

All history and contributions have been preserved in the monorepo.

Comments
  • Add support for using webgl in a worker via offscreen canvas

    Add support for using webgl in a worker via offscreen canvas

    Description

    tensorflow/tfjs#102

    Offscreen Canvas is currently only shipping in Chrome so this could break for users who try to use WebGL backend in a worker in unsupported browsers.
    The same issue applies to tests hence the support check in the test

    Add feature to check if in worker Add types for offscreen canvas Add test for canvas when running in worker


    For repository owners only:

    Please remember to apply all applicable tags to your pull request. Tags: FEATURE, BREAKING, BUG, PERF, DEV, DOC, SECURITY

    For more info see: https://github.com/tensorflow/tfjs/blob/master/DEVELOPMENT.md


    This change is Reviewable

    opened by bkazi 27
  • Sgd+ momentum optimizer added

    Sgd+ momentum optimizer added

    Created a simple SGD+Momentum optimizer and have tested in session_test.ts for initial commit to get familiar. If this goes well, will start working on other optimizers.


    This change is Reviewable

    opened by mnottheone 17
  • Add the pow operator

    Add the pow operator

    Added pow operator for both cpu and gpu discovered some discrepancies between WebGL implementation of pow function. the current implementation is when the base is negative or base is 0 and power is negative then return NaN. That is the current OpenGL spec.


    This change is Reviewable

    opened by pyu10055 16
  • Add packed arithmetic binary operation kernel. (#951)

    Add packed arithmetic binary operation kernel. (#951)

    FEATURE

    Description

    • Doesn't support 5-D and 6-D.
    • Supports add(addN), sub, multiply, realDivide, floorDiv and pow.
    • Broadcasting is supported only when one of the operands is scalar or 1-D.
    • Added behind environmental flag 'WEBGL_PACK_BINARY_OPERATIONS'.
    • Existing arithmetic tests are configured to run both with non-packed and packed binary operations.

    For repository owners only:

    Please remember to apply all applicable tags to your pull request. Tags: FEATURE, BREAKING, BUG, PERF, DEV, DOC, SECURITY

    For more info see: https://github.com/tensorflow/tfjs/blob/master/DEVELOPMENT.md


    This change is Reviewable

    PERF 
    opened by astojilj 15
  • Support tensors rank 5

    Support tensors rank 5

    Added tensors rank 5. This is still a work in progress. The shader_compiler.ts file needs to be further revised ... Many gpu operations needs to be changed like reverse, transpose, slice ...


    This change is Reviewable

    opened by zaidalyafeai 15
  • Demo: Learning XOR

    Demo: Learning XOR

    This pull request adds demo for the famous learning xor problem.

    @nsthorat I'm using meanSquaredCost here which ideally should not be the case. We should be using softmaxCrossEntropyCost. I'm facing some issue with it. I feel it has not been documented properly or maybe I'm not using it correctly. Could you please look into it?

    Also, I'm building an interface around this. Hence, work is in progress.


    This change is Reviewable

    opened by manrajgrover 15
  • Add fft ops

    Add fft ops

    Description

    FEATURE

    Add fft ops. Since TypeScript/JavaScript does not support complex number natively, it regards two length array as a complex number so that it can support [n, 2] shape tensor as input.

    const real = tf.tensor1d([1, 2, 3]);
    const imag = tf.tensor1d([1, 2, 3]);
    const input = tf.complex(real, imag);
    tf.fft(input); // => [[6, 6], [-2.3660252, -0.63397473], [-0.6339747, -2.3660254]]
    

    see: https://github.com/tensorflow/tfjs/issues/214


    For repository owners only:

    Please remember to apply all applicable tags to your pull request. Tags: FEATURE, BREAKING, BUG, PERF, DEV, DOC, SECURITY

    For more info see: https://github.com/tensorflow/tfjs/blob/master/DEVELOPMENT.md


    This change is Reviewable

    opened by Lewuathe 14
  • Introduce src/contrib/data.

    Introduce src/contrib/data.

    This subpackage provides Dataset, DataStream, and related subclasses and utilities.

    It provides for streaming data loading and preprocessing, with the intent of feeding machine learning models with data for both training and evaluation.

    This cannot yet replace src/data, nor does it yet support the needs of the current deeplearn.js demos. It's just an initial commit, moving the current version of the code unmodified from its private repo. Deeper integration with deeplearn.js will follow.


    This change is Reviewable

    opened by davidsoergel 14
  • Add stft op

    Add stft op

    Add tf.signal.stft op.

    One TODO is passing fft length parameter because rfft does not support fft length parameter. We can pass fft length parameter after rfft supports it.

    See: https://github.com/tensorflow/tfjs/issues/1362


    This change is Reviewable

    cla: yes 
    opened by Lewuathe 13
  • Add Conv3d

    Add Conv3d

    Description

    This is an implementation of conv3d, as discussed in: https://github.com/tensorflow/tfjs/issues/470

    This implementation has a functional CPU kernel that needs some additional unit tests and checking of a few more edge cases.

    The webGL kernel is incomplete. I will use this PR to communicate with people more knowledgeable around webGL and the 5d tensor implementation for guidance.

    I also need to check my conv3d implementation against the recent changes to the conv2d implementation. For some reason the original conv2d routine was rewritten in the time since I started working on conv3d - I need to look at the prior PRs and see why. Since my conv3d implementation was based off of the old conv2d implementation, this may effect my conv3d implementation.


    For repository owners only:

    Please remember to apply all applicable tags to your pull request. Tags: FEATURE, BREAKING, BUG, PERF, DEV, DOC, SECURITY

    For more info see: https://github.com/tensorflow/tfjs/blob/master/DEVELOPMENT.md


    This change is Reviewable

    opened by zboldyga 13
  • Fixed division by zero in QR decomposition. Issue #1058

    Fixed division by zero in QR decomposition. Issue #1058

    Description

    https://github.com/tensorflow/tfjs/issues/1058 The sign() function returns 0 on 0, which causes a division by zero in the QR decomposition function qr() if there is a zero on the diagonal.


    For repository owners only:

    Please remember to apply all applicable tags to your pull request. Tags: FEATURE, BREAKING, BUG, PERF, DEV, DOC, SECURITY

    For more info see: https://github.com/tensorflow/tfjs/blob/master/DEVELOPMENT.md


    This change is Reviewable

    cla: yes 
    opened by jarno-r 12
  • Add rn integration test app

    Add rn integration test app

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

    This adds an app that can serve as an integration testbed for tfjs-react-native. The PR looks somewhat big because there is a fair amount of generated iOS and Android boilerplate. The files that needs review all end in .ts .js and .tsx (and the regular js and ts configuration files we are used to). A few assets that the app uses are also included. The android and ios subfolders are pretty much all autogenerated.


    This change is Reviewable

    cla: yes 
    opened by tafsiri 5
  • EncodeBase64 and DecodeBase64 ops

    EncodeBase64 and DecodeBase64 ops

    the TF implementation of the pix2pix model which fails conversion because of

    `Unsupported Ops: DecodeJpeg, EncodePng, DecodeBase64`
    

    the Open NSFW model also fails conversion with some of the same ops (https://github.com/tensorflow/tfjs/issues/433).

    i wanted to try to implement some of these ops in TensorFlow.js. starting with this pull request for DecodeBase64 and EncodeBase64.

    along with this tfjs-core PR, there is a corresponding PR in tfjs-converter (https://github.com/tensorflow/tfjs-converter/pull/376)


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


    This change is Reviewable

    opened by vabarbosa 9
  • tf.image.transform no-shader implementation

    tf.image.transform no-shader implementation

    This PR aims to fix tensorflow/tfjs#1426 and replaces #1637

    After trying to implement specific webgl/cpu shaders in #1637 i realized ImageProjectiveTransform is not available in the ops list of C API.

    Considering this, I've implemented it in a no-shader way, using tf.gatherND as the cornerstone of the implementation.

    This new version won't need to maintain multiple shaders but may be a little bit slower (i haven't fully tested the performance yet)

    Since the implementation takes 300 lines, i have put it into a separated file required in image_ops.ts.

    Please share your feedbacks and suggestions :-)


    This change is Reviewable

    opened by piercus 0
  • tf.linalg.bandPart

    tf.linalg.bandPart

    This is an attempt to further break down/simplify PR#1366.

    (Matrix) band part is required for the backpropagation of many linear operations. Implementation should behave the same way as in Python/C/C++ Tensorflow.


    This change is Reviewable

    opened by DirkToewe 1
  • initial commit diagPart operator

    initial commit diagPart operator

    FEATURE add operator diagPart

    https://github.com/tensorflow/tfjs/issues/655

    Description


    For repository owners only:

    Please remember to apply all applicable tags to your pull request. Tags: FEATURE, BREAKING, BUG, PERF, DEV, DOC, SECURITY

    For more info see: https://github.com/tensorflow/tfjs/blob/master/DEVELOPMENT.md


    This change is Reviewable

    opened by kedevked 0
Releases(v0.6.0)
  • v0.6.0(Mar 30, 2018)

    This release brings some exciting news: deeplearn.js is joining the TensorFlow family and is being renamed to TensorFlow.js Core.

    It is just one part of a larger ecosystem of tools surrounding TensorFlow in JavaScript, called TensorFlow.js. TensorFlow.js Core contains the low-level linear algebra ops as well as an eager layer for automatic differentiation. We now also provide a high-level layers API on top of Core called TensorFlow.js Layers.

    For convenience, we've packaged TensorFlow Layers and TensorFlow Core under a single union package, which you can find here: https://github.com/tensorflow/tfjs

    Since TensorFlow.js is a continuation of deeplearn.js, the first version of the union package and the Core API will be 0.6.0.

    What does this mean for existing users of deeplearn.js?

    • To use TensorFlow.js, you will have to update your imports. We recommend using the union package if you don't care about bundle size.
    // Import of union package, also contains layers API
    import * as tf from '@tensorflow/tfjs';
    const a = tf.tensor2d([1, 2]);
    
    // Also contains layers API:
    const model = tf.sequential();
    model.add(tf.layers.dense({inputShape: [1], units: [1]});
    

    If you want to just use the core API without any of the layers API, you can import the core library directly:

    // Import of tfjs-core only
    import * as tfc from '@tensorflow/tfjs-core';
    const a = tfc.tensor2d([1, 2]);
    

    These are both replacements for the old way to import deeplearn.js:

    // Old import
    import * as dl from 'deeplearn';
    const a = dl.tensor2d([1, 2]);
    

    What's new?

    • tf.tidy() no longer supports receiving asynchronous functions because they result in a serious bug with memory management as GPU memory allocations and deallocations may become interleaved.
    • Tensor.toString has been added. It returns a numpy-like rendering of the Tensor values as a string. You can also use Tensor.print() which is a convenience function for console.log(tensor.toString()).
    • Gradients added for: tf.slice, tf.pad, tf.reverse(), tf.tile().
    • Adds tf.dispose(...) which disposes multiple tensors.
    • Added nesterov flag to the momentum optimizer.
    • Allow floating point exponents in tf.pow().

    What's changed?

    • tf.conv2d signature has changed. This should only affect you if you are using dimRoundingMode.
    // Before
    tf.conv2d(x, filter, strides, pad, dimRoundingMode?)
    // After
    tf.conv2d(x, filter, strides, pad, dataFormat?, dilations?, dimRoundingMode?)
    
    • Scalar / Tensor1D / Tensor2D / Tensor3D / Tensor4D are now just types in TypeScript. They do not exist in JavaScript.

    What's removed?

    We've deleted all of the code we deprecated in the 0.5.0 release

    • CheckpointLoader and dumper has been deleted. We now have automatic tools for model porting. For those who still depend on this class, we've moved the loader to a separate repo (all of the instructions are there): https://github.com/PAIR-code/deeplearnjs-legacy-loader.
    • NDArray is deleted from the codebase.
    • Graph mode is deleted. All of the functionality of Graph mode is available in eager.
    • NDArrayMath is deleted. This is replaced with top-level functions on tf. If you want a different backend, use tf.setBackend('webgl'|'cpu');

    For more information about what TensorFlow.js, check out the TensorFlow.js website.

    Acknowledgements

    Thanks again to all our amazing contributors for making this happen. Thanks @ManrajGrover for your continued work on the project, fixing documentation bugs, updating optimizers to use chaining for variables, adding log1p, adding nesterov to the momentum optimizer. Thanks @oveddan for your incredible contributions to conv2d, adding dilation so we can support atrous convolutions. Thanks @meganetaaan for fix to sample code, @OliverLonghi for improving ml_beginners.md, @jbencook for updating squeezenet demo to do image resizing, @rilut for exporting TensorBuffer, @lukebelliveau for fixing a typo in docs, @HanKruiger for fixing a typo in docs, @nbardy for updating the performance.

    Source code(tar.gz)
    Source code(zip)
  • v0.5.0(Feb 17, 2018)

    This release brings some big changes to deeplearn.js. Largest of which is moving from a graph centric API to an ‘eager mode' imperative one that mirrors Tensorflow Eager.

    We believe the eager style programming model is more suited to faster development and rapid prototyping. We have also found eager style code easier to debug in the ways we as web developers typically debug things. Another big change is moving more functionality to the top level of the library. All ops are directly exported at the top level now.

    These and more changes are detailed below. We'd love to hear your feedback so feel free to make issues on the Github repo if you run into any problems or have other feedback.

    What’s New

    • Eager API: This release introduces our new eager API and all optimizers support eager mode. This allows you to write imperative code to do inference and training without a deferred graph execution model. Eager mode also makes debugging easier.

       import * as dl from ‘deeplearn’;
      
        // y = a * x^2 + b * x + c.
       const f = x => a.mul(x.square()).add(b.mul(x)).add(c);
       const loss = (pred, label) => pred.sub(label).square().mean();
      
       const learningRate = 0.01;
       const optimizer = dl.train.sgd(learningRate);
      
       for (let i = 0; i < 10; i++) {
         optimizer.minimize(() => loss(f(xs), ys));
       }
      
    • Chain API: Tensors now provide a chaining API for ops. Which means you can write

      import * as dl from ‘deeplearn’;
      
      dl.tensor([[2, 3], [5, 1]])
          .mul(dl.scalar(3))
          .square();
      
    • New Ops: dl.gather, dl.less, dl.logicalAnd, dl.where, dl.range, dl.linspace, dl.logicalXor, dl.logicalNot, dl.stack, dl.squeeze and dl.expandDims.

    • New utility functions: dl.memory, dl.time and dl.nextFrame.

    • Backend selection: Use dl.setBackend(‘webgl’|’cpu’). Also we automatically choose the best backend for you so you will not usually need to call this.

    • New API Docs!: We are super excited about these, we are adding code snippets to our api docs and you can run them inline! Power to the browser!

    What’s Changing

    • NDArray has been renamed to Tensor: Tensors are now immutable meaning operations on tensors return new tensors rather than modifying the original tensors. The NDArray identifier will still work in 0.5 but will be removed in future releases.

    • Tensor Creation: We now provide helper functions to create tensors. Use dl.tensor and not NDArray.new. We also have dl.scalar, dl.tensor1d, dl.tensor2d, dl.tensor3d and dl.tensor4d for your convenience.

    • Top Level Ops: All ops are now on the top level object of the library. That means you can now do the following

      import * as dl from ‘deeplearn’;
      
      dl.randomNormal([2,2]).print();
      
    • dl.clone() now does a shallow copy

    • For typescript users: Tensors no longer have a dtype generic. dtype is now only a property of a tensor.

    What’s deprecated

    This version represents a big shift to a new style API, thus a number of things we are deprecating will be removed in 0.6. Please start upgrading your code now, or lock down your dependencies if you aren't yet ready to upgrade.

    • Graph Mode: With the introduction of eager mode we are deprecating graph mode. The entire graph API will be removed in 0.6.

    • NDArrayMath: As mentioned above, all ops are now at the top level. So no longer use code like this dl.ENV.math.square(). ** If you want to use a different backend use dl.setBackend(). We will be removing the NDArrayMath in 0.6.**

    Acknowledgements

    Thanks to all our contributors that helped make this happen! Thanks @ManrajGrover for your work on optimizers, gradients, improving tests and more, @reiinakano for work on dl.gather, @jaassoon for work on improving our with unit tests, @skwbc for improving error messages in our checkpoint dump script, @gena for work on gradients for dl.sigmoid, @davidsoergel for work on an upcoming dl.contrib.data package @caisq for work on gradients for dl.clipByValue and dl.batchNormalization, @WeiZhiHuang for fixing a bug in one of demos.

    We also want to thank the contributors for 0.4.2 for which we didn't do official release notes. Thanks @chaosmail for your work on automatic Caffe model porting, improvements to conv2d, improvements to our testing infrastructure, and for dl.reverse, @Lewuathe for concat backprop, documentation, and better error messaging, @nkreeger for your work on random number generation, array ops, windows tooling support, and the game of life demo, @minsukkahng for fixing graph-mode broadcasting backprop for arithmetic, @shancarter for the awesome fonts demo and for giving us the idea to implement operation chaining, @jameswex for the fonts demo, @experiencor for mobilenet and yolo models, @easadler for conv1d, @LukasDrgon for adding jsdeliver CDN links, @pyu10055 for work on dl.pow and dl.squeeze, @wang2bo2 for work on dl.prelu, @vuoristo for work on softmax gradients, @haasdo95 for fixing a bug in our docs, @jimbojw for helping with docs, @iaroslav-ai for helping with docs

    Finally, welcome to the team @tafsiri, @nkreeger and @pyu10055!

    Source code(tar.gz)
    Source code(zip)
  • v0.3.0(Oct 9, 2017)

    API additions

    • :tada: Added support for iOS :tada: #109

    • Added optimizers (Adam, AdaGrad, AdaDelta, RMSProp). #170 #102 #183 Thanks @Lewuathe and @mnottheone for the implementations and @SayHelloToWorld for the bug fixes!

    • Added math.cos, math.tan, math.asin, math.acos, math.atan, math.sinh, math.cosh, math.abs #123

    • Added math.oneHot and math.multinomial #160

    • Added NDArray.getValuesAsync() which asynchronously downloads the values from the GPU #146

    • Added math.concat[1-4]D and math.slice[1-4]D #151

    Bug fixes

    • Fixed bug in NDArray.randTruncatedNormal. #172 Thanks @caisq for the find!

    Other improvements

    • Added highlighting when glsl fragment shaders fail to compile image

    • Faster reduction ops (min/max/reduce_sum/logsumexp) #145

    • Faster matmul and convolutions/pooling #129

    • Added script for model builder training data preprocessing. #136 Thanks @kaihuchen!

    • Improved benchmark measurements. #140

    Thanks to all our contributors!

    @Lewuathe @mnottheone @kaihuchen @SayHelloToWorld @cghawthorne @digitalheir @caisq @arthurjdam @jsphweid @bernard-lin @shancarter

    Source code(tar.gz)
    Source code(zip)
    deeplearn.js(451.09 KB)
    deeplearn.min.js(230.82 KB)
  • v0.2.0(Sep 7, 2017)

    API additions:

    • Add broadcasting to NDArrayMath functions. e.g. math.add(array2d, scalar) works. Use math.addStrict(a, b) to statically enforce a and b to be of the same rank.
    • Add NDArrayMath.basicLSTMCell and NDArrayMath.multiRNNCell to the math layer for inference only
    • Add a TensorFlow-like API for NDArrayMath.conv2d padding, with 'SAME'|'VALID' paddings
    • Add NDArrayMath.sqrt
    • Add sgd momentumOptimizer

    Other features:

    • math.enableDebugMode() now has console profiling for math functions: image

    Internal changes:

    • Add logical sampling, with a shader compiler that splices in methods for sampling in logical space, instead of sampling on 2D physical texture space. This lets us do broadcasting, and opens up the door for batching. It is also a prerequisite for integer textures to get iOS working (this will be part of the next release).
    Source code(tar.gz)
    Source code(zip)
  • v0.1.0(Aug 4, 2017)

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
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
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
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 straightforward framework built for automatic proctoring to create online tests, effortlessly

A straightforward framework built for automatic proctoring to create online tests, effortlessly. Explore the docs » Architecture · Features · Local Se

Tushar Nankani 24 Oct 22, 2022
Deep Learning in Javascript. Train Convolutional Neural Networks (or ordinary ones) in your browser.

ConvNetJS ConvNetJS is a Javascript implementation of Neural networks, together with nice browser-based demos. It currently supports: Common Neural Ne

Andrej 10.4k Dec 31, 2022
[UNMAINTAINED] Simple feed-forward neural network in JavaScript

This project has reached the end of its development as a simple neural network library. Feel free to browse the code, but please use other JavaScript

Heather 8k Dec 26, 2022
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
Pure Javascript OCR for more than 100 Languages 📖🎉🖥

Version 2 is now available and under development in the master branch, read a story about v2: Why I refactor tesseract.js v2? Check the support/1.x br

Project Naptha 29.2k Dec 31, 2022
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
Differential Programming in JavaScript.

April 19, 2018 TensorFlow.js was recently released. It is well engineered, provides an autograd-style interface to backprop, and has committed to supp

Propel 2.7k Dec 29, 2022
Machine learning tools in JavaScript

ml.js - Machine learning tools in JavaScript Introduction This library is a compilation of the tools developed in the mljs organization. It is mainly

ml.js 2.3k Jan 1, 2023
Deep Neural Network Sandbox for JavaScript.

Deep Neural Network Sandbox for Javascript Train a neural network with your data & save it's trained state! Demo • Installation • Getting started • Do

Matias Vazquez-Levi 420 Jan 4, 2023
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
Call Python packages in JavaScript.

Introduction to Boa Boa is the Python Bridge Layer in Pipcook, it lets you call Python functions seamlessly in Node.js, it delivers any Python module

imgcook 64 Jan 5, 2023
JavaScript Machine Learning Toolkit

The JavaScript Machine Learning Toolkit, or JSMLT, is an open source JavaScript library for education in machine learning.

JSMLT 25 Nov 23, 2022
K-nearest neighbors algorithm for supervised learning implemented in javascript

kNear Install npm install knear --save About kNear is a javascript implementation of the k-nearest neighbors algorithm. It is a supervised machine lea

Nathan Epstein 45 Mar 7, 2022
Latent Dirichlet allocation (LDA) topic modeling in javascript for node.js.

LDA Latent Dirichlet allocation (LDA) topic modeling in javascript for node.js. LDA is a machine learning algorithm that extracts topics and their rel

Kory Becker 279 Nov 4, 2022
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