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 tf.layers.inputLayer() function is an inlet point towards a tf.LayersModel. It is produced spontaneously in favor of tf.Sequentialmodels by defining the inputshape or else batchInputShape in favor of the first layer. It must not be defined particularly. Moreover, it can be beneficial periodically, for example, while creating a sequential model out of a subset of other sequential model layers.
Syntax:
tf.layers.inputLayer(args)
Parameters:
- args: It is the stated arguments that the above method can hold. It is of type object and the arguments it holds are as stated below.
- inputShape: The stated input shape that does not include the batch axis. It can be of type (null | number)[].
- batchSize: It is the stated elective input batch size. It can be of type integer or null.
- batchInputShape: It is the stated batch input shape that includes the batch axis. It can be of type (null | number)[].
- dtype: The data type of the stated input. It can be of type float32, int32, bool, complex64, or string.
- sparse: It states if the created placeholder is intended to be sparse. It is of boolean.
- name: The stated name of the layer being used. It is of type string.
Return Value: It returns InputLayer.
Example 1:
Javascript
// Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Defining a model const model = tf.sequential(); // Calling layers.inputLayer() using add() method model.add(tf.layers.inputLayer({inputShape: [4]})); // Printing output model.predict(tf.ones([1, 4])).print(); |
Output:
Tensor [[1, 1, 1, 1],]
Example 2:
Javascript
// Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Defining a model const model = tf.sequential(); // Calling layers.inputLayer() method using add() method model.add(tf.layers.inputLayer({batchInputShape: [4], dtype: 'int32' , sparse: false , name: 'mlayer' })); // Printing output model.summary(); |
Output:
_________________________________________________________________ Layer (type) Output shape Param # ================================================================= mlayer (InputLayer) [4] 0 ================================================================= Total params: 0 Trainable params: 0 Non-trainable params: 0 _________________________________________________________________
Reference: https://js.tensorflow.org/api/latest/#layers.inputLayer