Tensorflow.js tf.layers setWeights() Method
Tensorflow.js is an open-source library that is developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment.
The .setWeights() method is used to set the weights of the stated layer, from the given tensors.
- weights: It is the stated list of input tensors. It is of type tf.Tensor. Where, the count of arrays as well as their shape should be equivalent to the count of the dimensions of the stated weights of the layer used. In other words, it must be equal to the result of the getWeights() method.
Return Value: It returns void.
Tensor [[-0.5969906, -0.1883931], [0.8569255 , -0.49416 ], [0.1157023 , 0.1150239 ], [-0.4052143, 1.9936075 ], [0.3090054 , 0.7212474 ], [0.4626641 , -0.7287846], [0.4352857 , -0.5195332], [0.4626429 , 0.0216295 ], [-0.1110666, -0.5997615], [-0.5083916, -0.3582681], [-0.2847465, 1.184485 ]]
Here, truncatedNormal() method is used to create a tf.Tensor along with values that are sampled from a truncated normal distribution, zeros() method is used to create a tf.Tensor along with all the elements that are set to 0 and getWeights() method is used to print the weights that were set using setWeights() method.
Tensor [, , , , ] Tensor  Tensor [[1, 1],] Tensor [0, 0]
Here, ones() method is used to create a tf.Tensor along with all the elements that are set to 1.