Machine Learning : Tensorflow v/s Tensorflow.js v/s Brain.js

user10140016 picture user10140016 · Aug 11, 2018 · Viewed 12.5k times · Source

I've recently started coding with Machine learning techniques and had been going back and forth between Machine learning implemented in different platforms. The frameworks i worked a lot with were Tensorflow (Python), Tensorflow.js and Brain.js. And i've got couple of doubts about them.

  1. Why do most of them prefer Tensorflow (Python) over Tensorflow.js. What does Tensorflow has that Tensorflow.js doesn't which makes it special?
  2. Most people i've seen in the internet prefer working with Tensorflow.js than brain.js, even though brain.js uses JSON objects which doesnt put the developer in a hassle to create Tensors and make memory management and stuff. Why do people prefer working with Tensorflow.js even though brain.js is easy to implement?
  3. If i'm making a web site which uses Node.js as a backend, which would be the preferable library to be implemented for Machine Learning in a long run? Tensorflow.js or Brain.js? or should i use Tensorflow separately for just Machine learning things?

I've been searching a lot on these topics. And i haven't got a nice explanation for my doubts yet. So expecting a clear and detail exaplanation :)

Answer

Sebastian Speitel picture Sebastian Speitel · Aug 11, 2018

The speeds are different: Tensorflow > tfjs > brainjs. Python can be directly compiled to machine code and directly use the CPU and GPU, whereas tfjs is a script-language which is being compiled on the client and has to use the <canvas> in the browser to access the GPU the same as brain.js (I am not sure if brain.js is GPU-accelerated)

Another thing is that tensorflow is a whole ecosystem, which is kept in sync with each different version for the different platforms, so it is really easy to port your python(keras) model to tfjs and if you know how to code a tensorflow-model you can do it in any language.

And if you're using nodejs the only reason to stay with tfjs and not switch to python is that you like the JavaScript language better or you are forced to use because you are working in a JS backend.

PS: A new library was just released (ML5), which is a wrapper for tfjs and adds a lot of stuff, which helps you to build and use models without having a deep machine learning background.