Tensorflow.js tf.layers.dropout() Function Last Updated : 04 Jul, 2021 Comments Improve Suggest changes Like Article Like Report 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.dropout() function is an inbuilt function of Tensorflow.js library. This function is used to prevent overfitting in a model by randomly setting a fraction rate of input units to 0 at each update during training time. Syntax: tf.layers.dropout( {rate} ) Parameters: args: The given object as a parameter.rate: Specifies the fraction of input units to drop. Its value ranges between 0 and 1.noiseShape: List of integers that represents the shape of the dropout that will be multiplied with the input. It is an optional parameter.seed: Specifies random seed. It is an optional parameter.inputShape: If this parameter is defined, it will create another input layer to insert before this layer.batchInputShape: If this parameter is defined, it will create another input layer to insert before this layer.batchSize: Used to construct batchInputShape, if not already specified.dtype: Specifies the data type for this layer. The default value of this parameter is ‘float32’.name: Specifies name for this layer.trainable: Specifies whether the weights of this layer are updated by fit.weights: Specifies the initial weight values of the layer.inputDType: It is used to denote the inputDType and its value can be ‘float32’ or ‘int32’ or ‘bool’ or ‘complex64’ or ‘string’. Return value: It returns the Dropout. Example 1: We will create a new model and add dropout layer to it. JavaScript // Importing the tensorflow.js library const tf = require("@tensorflow/tfjs"); // Define the model const model = tf.sequential({ layers: [tf.layers.dense({ units: 1, inputShape: [10] })], }); // Add dropout to model model.add(tf.layers.dropout({ rate: 0.25 })); // Compile the model model.compile( { optimizer: "sgd", loss: "meanAbsoluteError" }, (metrics = ["accuracy"]) ); // Evaluate the model const result = model.evaluate( tf.ones([8, 10]), tf.ones([8, 1]), { batchSize: 4, }); // Print the resulting tensor result.print(); Output: Tensor 1.608272910118103 Example 2: JavaScript // Importing the tensorflow.js library const tf = require("@tensorflow/tfjs"); // Define the model const model = tf.sequential({ layers: [tf.layers.dense({ units: 1, inputShape: [10] })], }); // Add dropout to model model.add(tf.layers.dropout({ rate: 0.5 })); // Compile the model model.compile({ optimizer: "adam", loss: "meanSquaredError" }); // Evaluate the model const result = model.evaluate( tf.ones([8, 10]), tf.ones([8, 1]), { batchSize: 2, }); // Print the result result.print(); Output: Tensor 0.9941154718399048 Reference: https://js.tensorflow.org/api/latest/#layers.dropout Comment More infoAdvertise with us Next Article Tensorflow.js tf.layers.dropout() Function S sahilkumar101 Follow Improve Article Tags : JavaScript Web Technologies Tensorflow.js Similar Reads Tensorflow.js tf.layers.alphaDropout() Function 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 Node.js. The tf.lay 2 min read Tensorflow.js tf.dropout() Function 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.dropout() function is used to compute the dropout. You can read more about dropout from https://www.geeksforgeeks.org/dropout-i 2 min read Tensorflow.js tf.layers.elu() Function 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 Node.js. The tf.lay 2 min read Tensorflow.js tf.layers.dense() Function The tf.layers.dense() is an inbuilt function of Tensorflow.js library. This function is used to create fully connected layers, in which every output depends on every input. Syntax: tf.layers.dense(args)Parameters: This function takes the args object as a parameter which can have the following proper 3 min read Tensorflow.js tf.layers.cropping2D() Function Tensorflow.js is a Google-developed open-source toolkit for executing machine learning models and deep learning neural networks in the browser or on the node platform. It also enables developers to create machine learning models in JavaScript and utilize them directly in the browser or with Node.js. 2 min read Like