Skip to content
This repository has been archived by the owner on Aug 15, 2019. It is now read-only.

TensorFlow.js Core API

Latest
Compare
Choose a tag to compare
@nsthorat nsthorat released this 30 Mar 14:13
· 842 commits to master since this release

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.