Part 2- https://medium.com/aixdesign/getting-started-with-ml5-js-tutorial-part-ii-posenet-ca142c2e05d1
.
.
One-layer model is fitting a linear function f(input), defined as output = kernel * input + bias
The kernel and bias are tunable parameters (the weights) of the dense layer.
These weights contain the information learned by the network from exposure to the training data.
Initially, these weights are filled with small random values (a step called random initialization).
To find a good setting for the kernel and bias (collectively, the weights) we need two things:
The compile() method specifies 'sgd' as the optimizer and 'meanAbsoluteError' as the loss.
'meanAbsoluteError' means that the loss function will calculate how far the predictions are from the targets, take their absolute values (making them all positive), and then return the average of those values:
meanAbsoluteError = average( absolute(modelOutput - targets))
'sgd' stands for stochastic gradient descent, a calculus formula to determine what adjustments should be made to the weights in order to reduce the loss.
The fit() method is the training process of a model in TensorFlow.js. It can often be long-running, lasting for seconds or minutes. Therefore, the async/await feature is used.
The evaluate() method calculates the loss function as applied to the provided example features and targets. It is similar to the fit() method in that it calculates the same loss, but evaluate() does not update the model’s weights.
The training loop iterates through the following steps:
1. Draw a batch of training samples x and corresponding targets y_true. A batch is simply a number of input examples put together as a tensor. The number of examples in a batch is called the batch size. In practical deep learning, it is often set to be a power of 2, such as 128 or 256. Examples are batched together to take advantage of the GPU’s parallel processing power and to make the calculated values of the gradients more stable.
2. Run the network on x (a step called the forward pass) to obtain predictions y_pred.
3. Compute the loss of the network on the batch, a measure of the mismatch between y_true and y_pred. Recall that the loss function is specified when model.compile() is called.
4. Update all the weights (parameters) in the network in a way that slightly reduces the loss on this batch. The detailed updates to the individual weights are managed by the optimizer, which was specified during the model.compile() call.
The loss as a function of all tunable parameters is known as the loss surface concept.
The loss surface for this example has a bowl shape, with a global minimum at the bottom of the bowl representing the best parameter settings.
In general, however, the loss surface of a deep-learning model is much more complex. It will have many more than two dimensions and could have many local minima i.e. points that are lower than anything nearby but not the lowest overall.
For larger problems i.e. when optimizing millions of weights, the likelihood of randomly selecting a good direction becomes vanishingly small.
A much better approach is to take advantage of the fact that all operations used in the network are differentiable and hence, to compute the gradient of the loss with regard to the network’s parameters.
The mathematical definition of a gradient specifies a direction along which the loss function increases. When training neural networks, the loss should gradually decrease. Therefore the weights should be moved in the direction opposite the gradient. This training process is aptly named gradient descent.
One of the most desirable properties of deep neural networks are that they are universal approximators. Which means they should be able to cover non-convex functions as well. The problem with non-convex functions is that your initial guess might not be near the global minima and gradient descent might converge to a local minima. A solution to this problem is the stochastic gradient descent approach.
The term “stochastic” means drawing random samples from the training data during each gradient-descent step for efficiency, as opposed to using every training data sample at every step. In short, stochastic gradient descent is simply a modification of gradient descent for computational efficiency.
Stochastic means nondeterministic or unpredictable. Random generally means unrecognizable, not adhering to a pattern. A random variable is also called a stochastic variable. (https://math.stackexchange.com/questions/114373/whats-the-difference-between-stochastic-and-random)
.
This tutorial is based on the book Deep Learning With JavaScript (TensorFlowJS).
https://codepen.io/tfjs-book/pen/VEVMMd
This tutorial is based on the book Deep Learning With JavaScript (TensorFlowJS).
The first script loads the TensorFlow package and defines the symbol tf, which provides a way to refer to names in TensorFlow.
The second script creates two constants, trainData and testData, each representing 20 samples of how long it took to download a file (timeSec) and the size of that file (sizeMB). The elements in sizeMB and those in timeSec have one-to-one correspondence. For example, the first element of sizeMB in trainData is 0.080 MB, and downloading that file took 0.135 seconds—that is, the first element of timeSec—and so forth.
The goal in this example will be to estimate timeSec, given just sizeMB.
.
CHAPTER 1: Using neural nets to recognize handwritten digits
In this chapter we'll write a computer program implementing a neural network that learns to recognize handwritten digits.
.
CHAPTER 2: How the backpropagation algorithm works
In this chapter I'll explain a fast algorithm for computing such gradients, an algorithm known as backpropagation.
.
CHAPTER 3:Improving the way neural networks learn
In this chapter I explain a suite of techniques which can be used to improve on our vanilla implementation of backpropagation, and so improve the way our networks learn.
.
CHAPTER 4:A visual proof that neural nets can compute any function
In this chapter I give a simple and mostly visual explanation of the universality theorem.
.
CHAPTER 5:Why are deep neural networks hard to train?
In this chapter, we'll try training deep networks using our workhorse learning algorithm - stochastic gradient descent by backpropagation.
.
In this chapter, we'll develop techniques which can be used to train deep networks, and apply them in practice.
.
.
ML⁵.js is a recently developed high level Library which aims to make machine learning approachable for a broad audience of artists, creative coders, and students. The Library is developed at the New York University and has been publicly released on July 2018.The library provides access to machine learning algorithms ,task and models in the browser, building on top of TensorFlow.js with no other external dependencies.So, It can be compared to Keras. ML⁵.js is built over TensorFlow.js and it uses the functionality of TensorFlow.js at the backend but makes life easier for people who are new to Machine Learning arena.
.
ML⁵.js is built with a Motive to simplify things out for beginners. We can compare this to Keras. The Motivation behind Keras was to make ML/DL in python so Simple that it can be used by Beginners. Similar is the case with ML⁵.js..
This is possible by making a wrapper around the Tensorflow.js library and use all the functionality at the backend. So Intuitively, It is an Easy to use API for TensorFlow.js.
.
https://towardsdatascience.com/introduction-to-ml5-js-3fe51d6a4661
.