
Neural Networks in JavaScript with Deeplearn.js - rwieruch
https://www.robinwieruch.de/neural-networks-deeplearnjs-javascript/
======
nerfhammer
I was going to write a cynical complaint about how it's hardly useful without
GPU support... but it's using WebGL to hit the GPU. Of course. And it's
probably a million times easier than trying install a TensorFlow stack locally
on your desktop.

~~~
Houshalter
It's super sad to me, that the only convenient cross platform way to do deep
learning is a hack on top of JS.

~~~
j2kun
Folks are downvoting this, but they must clearly have drowned themselves in
kool-aid.

You want fast matrix multiplication? Pretend you're doing texture shading in a
language primarily used for dynamic web frontends!

~~~
Houshalter
Yeah I don't see how I stepped on any toes. Deep learning libraries have
always been a pain in the ass to install. And only support some OSes and GPUs.
There's nothing wrong with JS or webgl, but it seems an incredibly inelegant
choice for this.

~~~
lettergram
pip install tensorflow is pretty darn easy....

Granted it doesn't have AMD support, I'm fairly confident even the CPUs can
out perform the javascript library.

~~~
Houshalter
I wasn't aware it worked at all on Windows now, that's cool. Doesn't seem very
simple to install though. This is the installation guide for just one of the
prerequisites: [http://docs.nvidia.com/cuda/cuda-installation-guide-
microsof...](http://docs.nvidia.com/cuda/cuda-installation-guide-microsoft-
windows/) And as you mention, only Nvidia.

~~~
Rapzid
Cuda and cuDNN; good times :) Not cross platform, but nvidia does supply a
bunch of packages now for different OS's to get that stuff installed.

------
rwieruch
OP here: Please checkout the GitHub repository of the Neural Network in JS too
[0].

Would love to see some exciting discussions around machine learning in JS. I
am exploring the topic heavily at the moment and I am keen to
apply/write/educate/learn more about it.

\- [0] [https://github.com/javascript-machine-learning/color-
accessi...](https://github.com/javascript-machine-learning/color-
accessibility-neural-network-deeplearnjs)

------
ericand
If you are looking for it (like I was), here's a direct link to the
deeplearn.js project: [https://deeplearnjs.org/](https://deeplearnjs.org/)

------
simonw
This webcam demo with live updating visualization of the different network
layers is extraordinary:
[https://deeplearnjs.org/demos/imagenet/](https://deeplearnjs.org/demos/imagenet/)

~~~
bduerst
I dunno, it says I have the highest probability of being a shower cap or a
bandaid.

I personally like this one the best (also uses deeplearn.js):
[https://teachablemachine.withgoogle.com/](https://teachablemachine.withgoogle.com/)

------
XCSme
I would also recommend Synaptic.js
[http://caza.la/synaptic/](http://caza.la/synaptic/) It's easy to get started
with, very good for learning the basics of NNs very quickly.

------
jorgemf
I hope web pages don't grow to hundreds of megabytes just because they have a
Neural Network embedded.

~~~
onion2k
I do.

I also hope internet bandwidth grows to the point where hundreds of megabytes
takes milliseconds to download, and that computer memory increases until
hundreds of megabytes is trivial, and that the economics of ISPs mean I get
truly unlimited data without incurring charges, but when all that happens I
definitely do hope we're utilising technology in ways that includes embedding
complex neural networks in webpages as a normal, typical thing we do.

That particular future will be _awesome_.

~~~
jorgemf
Resources don't grow to the infinite, there are physics limits to everything.
Be aware of that. You can see the perfect example in CPUs, now we are adding
cores but peak speed In a single core don't grow very much in new generations
as they did few years ago. With the web it is going to be similar at some
point (even the TCP protocol has some limits that forbid to reach top speed
with current connections for small transfers).

~~~
onion2k
The theoretical maximum speed of 5G wireless is 10,000Mbps with a 1ms latency
- a 300MB file would download in 251ms. That's _current_ technology being
tested in the field at the moment. Real phones will use it in a couple of
years. We won't get that speed, but we'll get quite close in major cities.
Today's flagship desktop computers have 16GB of RAM, but there's no particular
reason why they can't have 10 times that much. Servers already do. Phones have
4GB, but again they could have much more. CPU speeds are fast, but a neural
networks run on GPUs which are considerably faster for that task (remember
this isn't training the network, it's just running one you've downloaded).

This is what's actually happening right now. This is the _near_ future.

~~~
jorgemf
I am going to just forget all the countries that are still on GSM. Let's say
we have 5G right now.

1) The theoretical speed is one thing, the real one is another one.

2) There is more than one node connected to the network

3) TCP needs some package interchange to increase the window size

4) Latency with the server where the page is hosted is not going to be 1ms,
you are lucky if it is around 20ms.

5) Serves have more RAM because they use better CPUs, it means they are more
expensive.

6) Who connects to websites nowadays? Mobile is the way to go now (It means
slower CPUs, less RAM, less power consumption, etc)

7) Why are you going to transfer a complete netural network instead of sending
the data to the server. The data is going to be smaller than the network and
you avoid the risk of someone cloning the neural network for their web site.

8) There are no useful applications in web sites for neural networks. It is a
non sense for me (please probe me wrong and show me an use case where it makes
sense)

~~~
onion2k
_7) Why are you going to transfer a complete netural network instead of
sending the data to the server._

Privacy is one reason I can think of. By running the trained network locally I
can benefit from it without sharing all my data with the company serving it.

Data size is another reason. If I want to categorize 50GB of images using a
300MB model it makes a lot more sense to download the model than upload the
data.

 _8) There are no useful applications in web sites for neural networks._

I admit that I haven't got a clue how these things will be useful. If I did
then I'd have started a business to implement it already. My lack of insight
isn't a good reason to suggest they'll never be useful though.

~~~
jorgemf
> Data size is another reason. If I want to categorize 50GB of images using a
> 300MB model it makes a lot more sense to download the model than upload the
> data.

The faster the network is the more reasons you have to upload your data. The
time to process an image in the cloud is going to be virtually 0 with small
latency as the resources in the cloud are huge compared with what you can have
at home.

------
visarga
How does it compare to regular Python DL frameworks?

~~~
ericand
This explanation from a Google blogpost helped me:

The API mimics the structure of TensorFlow and NumPy, with a delayed execution
model for training (like TensorFlow), and an immediate execution model for
inference (like NumPy). We have also implemented versions of some of the most
commonly-used TensorFlow operations. With the release of deeplearn.js, we will
be providing tools to export weights from TensorFlow checkpoints, which will
allow authors to import them into web pages for deeplearn.js inference.

[https://research.googleblog.com/2017/08/harness-power-of-
mac...](https://research.googleblog.com/2017/08/harness-power-of-machine-
learning-in.html)

~~~
amelius
What is so appealing about a delayed execution model? Why can't we just
perform tensor math as in numpy, and let the library figure out the fastest
way to do it behind the scenes? I think the whole "graph" approach is making
things needlessly complicated.

~~~
quadrature
That would be nice for experimentation but for production use cases knowing
the whole graph unlocks a number of optimizations.

~~~
argonaut
This is a meme that keeps getting repeated, and I don't know why. Tensorflow,
for example, despite several years of development, does basically little to no
graph optimizations and for tons of tasks ends up much slower than PyTorch /
Chainer / DyNet (Tensorflow _is_ developing a "JIT compiler" but it is still
in alpha).

It goes without saying that a framework that does define-by-run _also_ knows
the whole graph.

