Monday, November 18, 2024
Google search engine
HomeLanguagesJavascriptTensorflow.js tf.layers.inputLayer() Function

Tensorflow.js tf.layers.inputLayer() Function

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.
    1. inputShape: The stated input shape that does not include the batch axis. It can be of type (null | number)[].
    2. batchSize: It is the stated elective input batch size. It can be of type integer or null.
    3. batchInputShape: It is the stated batch input shape that includes the batch axis. It can be of type (null | number)[].
    4. dtype: The data type of the stated input. It can be of type float32, int32, bool, complex64, or string.
    5. sparse: It states if the created placeholder is intended to be sparse. It is of boolean.
    6. 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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments