Tensorflow.js tf.layers countParams() Method Last Updated : 22 Apr, 2022 Comments Improve Suggest changes Like Article Like Report 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 .countParams() function is used to find the absolute count of numbers such as float32, int32 in the stated weights. Syntax: countParams() Parameters: This method doesn't hold any parameter. Return Value: It returns number. Example 1: JavaScript // Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Creating a model const model = tf.sequential(); // Adding a layer model.add(tf.layers.dense({units: 2, inputShape: [11]})); // Calling setWeights() method model.layers[0].setWeights( [tf.truncatedNormal([11, 2]), tf.zeros([2])]); // Calling countParams() method and also // Printing output console.log(model.layers[0].countParams()); Output: 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 setWeights() method is used to set the weights. 24 Example 2: JavaScript // Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Creating a model const model = tf.sequential(); // Adding layers model.add(tf.layers.dense({units: 1, inputShape: [5], batchSize: 1, dtype: 'int32'})); model.add(tf.layers.dense({units: 2, inputShape: [6], batchSize: 5})); model.add(tf.layers.dense({units: 3, inputShape: [7], batchSize: 8})); model.add(tf.layers.dense({units: 4, inputShape: [8], batchSize: 12})); // Calling setWeights() method model.layers[0].setWeights([tf.ones([5, 1]), tf.zeros([1])]); model.layers[1].setWeights([tf.ones([1, 2]), tf.zeros([2])]); // Calling countParams() method and also // Printing outputs console.log(model.layers[0].countParams()); console.log(model.layers[1].countParams()); console.log(model.layers[2].countParams()); Output: Here, ones() method is used to create a tf.Tensor along with all the elements that are set to 1. 6 4 9 Reference: https://js.tensorflow.org/api/latest/#tf.layers.Layer.countParams Comment More infoAdvertise with us Next Article Tensorflow.js tf.layers countParams() Method nidhi1352singh Follow Improve Article Tags : JavaScript Web Technologies Tensorflow.js TensorFlow.js-Classes TensorFlow.js-layers +1 More Similar Reads Tensorflow.js tf.layers getConfig() Method Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment. The tf.layers getConfig() function is used to get the configuration of a layer. Syntax: getConfig() Parameters: This function does not 2 min read Tensorflow.js tf.layers apply() Method Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment. The tf.layers apply() method is used to execute the Layers computation and return Tensor(s) when we call it with the tf.Tensor(s). If 1 min read Tensorflow.js tf.layers build() 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 .build() function is used to create the weights of the layer stated. This method should be applied on every layers 2 min read Tensorflow.js tf.layers dispose() 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 dispose() function is used to dispose the weights of the layers stated. Moreover, it decrease the stated layer obje 2 min read Tensorflow.js tf.layers addLoss() 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 .addLoss() function is used to attach losses to the stated layer. Moreover, the loss might be probably conditional 2 min read Tensorflow.js tf.layers computeOutputShape() 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 .computeOutputShape() function is used to enumerate the output shape of the stated layer. And it presumes that the 2 min read Tensorflow.js tf.layers getWeights() Method Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment. It also helps the developers to develop ML models in JavaScript language and can use ML directly in the browser or in Node.js. The tf. 2 min read Tensorflow.js tf.LayersModel Class Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment. Tensorflow. js tf.LayerModel class is used to training, interface and evaluation of model. It have many method for training, evaluatio 2 min read Tensorflow.js tf.LayersModel class .getLayer() 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 .getLayer() function is used to fetch a layer that is based upon either its name (which must be unique) or else an 2 min read Tensorflow.js tf.LayersModel class .summary() Method The tf.LayersModel is a class used for training, inference, and evaluation of layers model in tensorflow.js. It contains methods for training, evaluation, prediction, and for saving of layers model purposes. So in this post, we are going to know about the model.summary() function. The model.summary( 2 min read Like