
Tensorflow.js – A Practical Guide - jaya-yellowant
https://blog.yellowant.com/tensorflow-js-a-practical-guide-2ed58327c455
======
zawerf
The most practical use not mentioned here is probably to import existing
trained models/weights. I can see it being useful for anything that you want
to run in real-time (e.g., webcams apps like
[https://github.com/ModelDepot/tfjs-yolo-
tiny](https://github.com/ModelDepot/tfjs-yolo-tiny)) and can't pay a round-
trip cost to server.

[https://js.tensorflow.org/tutorials/import-
keras.html](https://js.tensorflow.org/tutorials/import-keras.html)

Training a model in the browser is the least practical use for tensorflow.js
IMO (unless maybe you want to hijack people's browsers to help with training
or something).

~~~
rasmi
And if you want to just load generic pre-trained classifiers for a variety of
tasks, ml5js (which uses TensorFlow.js under the hood) seems promising!

[https://ml5js.org/docs/quick-start](https://ml5js.org/docs/quick-start)

------
asual
A nice introductory presentation about deep learning using tensorflow.js:
[https://youtu.be/SV-cgdobtTA](https://youtu.be/SV-cgdobtTA)

~~~
plurgid
wow! that is an amazingly well done video!

~~~
russh
Interesting video except I found the vocal fry to be distracting.

------
galfarragem
Noob question: Can anybody tell in a few sentences of plain english what is
tensorflow, how it works and why seems to be so relevant?

~~~
s-macke
Tensorflow tries to fit the free parameters (usually millions of parameters)
of a function y=f(x). The fitting algorithm gets usually thousands or millions
of examples of how the output y for a given input x has to look like.

For example, x can be tens of thousands of images of cats and dogs, and y can
be 1 for a dog and 0 for a cat. The goal for the fitting algorithm is to find
parameters that describe the concept of a cat and a dog so that it can can
generalize and categorize general images of cats and dogs. A bad fit would be
if the network just memorized the example images.

~~~
galfarragem
If I understand it correctly:

\- Tensorflow is the best tool to make the grunt work necessary to _calibrate_
the parameters of fitting algorithms.

\- Models of fitting algorithms are human proposed and where the ML 'art' is.
Seems to be kind of reverse engineering.

~~~
halflings
Accurate, although in most cases, the art is not in choosing the algorithm
(often a regular feed-forward, covolutional or recurrent neural network) but
the hyperparameters (regularization, number of layers, units, etc.) and
sometimes the way the data is fed (augment the dataset with distortions?
sample negative examples randomly? etc.)

------
bitL
Is there a TF/Keras in Python to JavaScript transpiler somewhere? I don't want
to waste time retyping complex methods to JS. Thanks for any suggestion!

~~~
halflings
You can probably export your Keras model, load it in tensorflow.js, and train
it. Makes more sense than transpiling.

Guide here:

[https://js.tensorflow.org/tutorials/import-
keras.html](https://js.tensorflow.org/tutorials/import-keras.html)

~~~
bitL
Thanks! Do you by chance know if it is practical to convert huge .h5 Keras
models to TF.js layers model? (~1GB). I have some state-of-art computer vision
models and it would be great if they could be used in a browser with a WebCam,
if they can fit into memory and be performant for inferencing.

~~~
zawerf
Mobile has similar constraints as web (but to a lesser extent) so you will
find more resources there.

Look into quantizing the weights (e.g., reduce from 32bit per parameter to 8
bits) to reduce model size:
[https://www.tensorflow.org/mobile/optimizing#model_size](https://www.tensorflow.org/mobile/optimizing#model_size)

------
Micoloth
Nice introduction!

I think your step 4 code is messed up though?

~~~
jaya-yellowant
Fixed it, thanks!

------
burkel24
You were so busy figuring out if you could, you didn't stop to wonder if you
should…

Joking aside this is super cool

~~~
gaius
I was going to upvote you ‘til I read the last line

~~~
brootstrap
haha take my upvote sir. i'm looking forward to new breed of websites that
abuse our browsers unknowingly. First mining crypto, now we will have people
using thousands(millions) of web browsers as part of some elaborate compute
cluster that runs some 'AI' deep learning crap to try and optimize
branding/click rates etc.

