This tutorial is about basic and advanced features of TensorFlow.js. This JavaScript software library a superset of the native WebGL API, which is available in modern browsers. Applications illustrating this tutorial have been designed from TensorFlow.js ver. 144. Accordingly, the code in this tutorial will probably not work for older versions.
For convenience, all applications are written in TypeScript to benefit from type checking since TensorFlow.js provides a TypeScript support.
Installation and basic execution of TensorFlow.js Rule(s)
- Availability of TensorFlow.js in applications either relies on the prior installation of Node.js (and thus npm) or by directly downloading the full package from threejs.org. In the former case, TensorFlow.js requires execution of the
npm i
shell command from thepackage.json
location. This file's content establishes the dependencies from TensorFlow.js as follows:"dependencies": { … "three": "^0.144.0" },
- Common installation in browsers (
index.html
file) requires the inclusion of library files plus application files that reuse libraries. Recently, TensorFlow.js may be (re)used by means of theexport
andimport
JavaScript clauses, but this approach is appropriate for very new applications built from scratch.- Common execution leads to a template JavaScript as shown below.
Example (HTML)
<script src="js/lib/three.js"></script>
Example (JavaScript)
Rule(s)
- Normalization (A. VANNIEUWENHUYZE book p. 111) (TensorFlow.js book p. 76)
Ragged tensors https://www.tensorflow.org/guide/ragged_tensor?hl=en overfitting (sur-ajustement) https://towardsdatascience.com/how-to-split-a-tensorflow-dataset-into-train-validation-and-test-sets-526c8dd29438Train versus test versus validation data
Rule(s)
- Train data are key inputs of the
tf.LayersModel.fit
instance method. By definition, neuronal network (i.e., model) fitting changes weights (randomly defined at neuronal network construction time). After (enough) epochs (epoch number ⧴ hyper-parameter), fitting aims at providing a neuronal network as a reliable calculator for upcoming predictions.- Test data are key inputs of the
tf.LayersModel.evaluate
instance method. When fitted, a neuronal network allows predictions, which should lead to test data.tf.LayersModel.evaluate
executes the loss function without, compared totf.LayersModel.fit
, changing weights. activation function, e.g., sigmoïde function- Validation data are key inputs of hyper-parameter tuning.
tf.LayersModel.fit
can be parameterized such that a percentage of train data is not used ⧴ these are validation data.- Model compilation: loss function: error measurement optimization function like Stochastic Gradient Descent (SGD) changes weights.
Application(s)
- Convulational Neural Network, CNN, ConvNet p.343 (Aurélien VANNIEUWENHUYZE
Example
Givenfront
as a blue half sphere, computemouth_geometry
(in pink: raw location of a hypothetical mouth) from scratch.Listing 1 (copy of a subset of faces from source geometry, i.e.,
front.geometry
)Listing 2 (copy of a subset of vertices from source geometry and consistently rearrange dependency between faces and vertices in target geometry , i.e.,
mouth_geometry
)