Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • TypeScript
  • Vue.js
  • D3.js
  • Collect.js
  • Underscore.js
  • Moment.js
  • Ember.js
  • Tensorflow.js
  • Fabric.js
  • JS Formatter
  • JavaScript
  • Web Technology
Open In App
Next Article:
Tensorflow.js tf.layers.conv3d() Function
Next article icon

Tensorflow.js tf.layers.convLstm2d() Function

Last Updated : 30 May, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

Tensorflow.js is an open-source library that is being developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment.

The tf.layers.convLstm2d() function is used for creating a ConvRNN2D layer which consists of one ConvLSTM2DCell and the apply method of ConvLSTM2D operates on a sequence of inputs. The shape of the input needs to be at least 4D with the first dimension being time steps. convLstm2d is the Convolutional LSTM layer.

Syntax:

tf.layers.convLstm2d( args )

Parameters:

  • args: It specifies the given config object:
    • activation: It is the activation function that is to be used. Default is a hyperbolic tangent. If null, is passed then no activation function will be used.
    • useBias: It specifies whether to use a bias vector or not.
    • kernelInitializer: It is the Initializer of the kernel weight matrix, which is used for linear transformation of the inputs.
    • recurrentInitializer: It is the Initializer of the recurrentInitializer weight matrix, which is used for linear transformation of the recurrent state.
    • biasInitializer: It is the initializer for the bias vector.
    • kernelRegularizer: It is a regularizer function applied to the kernel weight matrix. 
    • recurrentRegularizer: It is a regularizer function applied to the recurrentKernel weight matrix.
    • biasRegularizer:  It is a regularizer function applied to the bias vector.
    • kernelConstraint: It is a constraint function applied to the kernel weight matrix.
    • recurrentConstraint:  It is a constraint function applied to the recurrentKernel weight matrix.
    • biasConstraint: It is a constraint function applied to the bias vector.
    • dropout: It is a number between 0 to 1 which indicate the unit to drop for the linear transformation of the input.
    • recurrentDropout: It is the fraction number that drops the linear transformation of the recurrent state.
    • dropoutFunc: This is used for the test DI. 
    • inputShape: It should be an array of numbers. This field is used to create an input layer which is used to be inserted before this layer.
    • batchInputShape: It should be an array of numbers. This field will be used if inputShape and this field are provided as a parameter for creating the input layer which is used to insert before this layer.
    • batchSize: It should be a number. In the absence of batchInputShape this field is used to create batchInputShape with inputShape. batchInputShape : [ batchSize ,  ...inputShape].
    • dtype: If this layer is used as the input layer, then this field is used as data type for this layer.
    • name: It should be a string type. this field defines the name for this layer.
    • trainable: It should be boolean. This field defines whether the weights of this layer are trainable with fit or not.
    • weights: This should be a tensor that defines the initial weight value for this layer.
    • inputDType: This is a data type that is used for Legacy support.
    • recurrentActivation: It specifies the activation function which will be used for the recurrent step. The default value of this parameter is hard sigmoid.
    • unitForgetBias: It should be boolean. It is used to add 1 to the bias of the forget gate at initialization. 
    • implementation: It specifies the implementation mode. It can be either 1 or 2. For superior performance, implementation is recommended.
    • returnSequences:  It should be boolean. It defines which both of these weather last output or full sequence return in the output sequence.
    • returnState: It should be boolean. It defines the return last state in output.
    • goBackwards: It should be boolean. It defines whether to process the input in reverse and reverse sequence or not.
    • stateful: It should be boolean. It defines whether to use the last state of the batch as the initial state for the current batch or not.
    • unroll: It should be boolean. It tells whether to use unrolled network else, use a symbolic loop. 
    • inputDim: It should be a number. This is used when this layer is used as the first layer of the model. It defines the dimension of input in the layer. 
    • inputLength: It should be a number. This field should be when the sequence in input data is constant. 
    • cell: It should be an instance of RNN cell or an array of instances of RNN cells.
    • filters: It is a number of filters in convolution.
    • kernelSize: It is a dimension that the convolution window will have.
    • strides: It is strides of convolution layer in each dimension. 
    • padding: It should be 'valid', 'same', and 'causal'. It defines the padding mode. 
    • dataFormat: It defines the format of data, which tells the ordering of the dimensions in the inputs.
    • dilationRate: The dilation rate to which the convolution layer should dilate in each dimension.

Returns: It returns the ConvLSTM2D.

Example 1: In this example, we will operate our apply method in only one input.

JavaScript
// Config for input layer const bSize = 3; const sLength = 4; const size = 7; const channels = 2;  const inputShape = [bSize, sLength, size, size, channels]; const input = tf.zeros(inputShape);  // Config for convLstm2d  const filters = 4; const kernelSize = 4;  const layer = tf.layers.convLstm2d({filters, kernelSize});  const output = layer.apply(input);  // Printing Shape of our output console.log(JSON.stringify(output.shape)); 

Output:

[3,4,4,4]

Example 2:

JavaScript
import * as tf form "@tensorflow/tfjs"  const filters = 3; const kernelSize = 3;  const batchSize = 4; const sequenceLength = 2; const size = 5; const channels = 3;  const Input = tf.input({shape: [2, 3, 5, 4]}); const Data = tf.ones([1, 2, 3, 5, 4]); const inputShape = [batchSize,      sequenceLength, size, size, channels]; const input = tf.ones(inputShape);  const layer = tf.layers.convLstm2d({filters, kernelSize});  const output = layer.apply(Input); const model = tf.model({inputs: Input, outputs: output});  model.predict(Data).print(); 

Output:

​Tensor     [[[[0.2382042, 0.3073192, -0.0167814],        [0.2362143, 0.3104056, -0.0188109],        [0.2277206, 0.3124302, -0.0153713]]]]

Reference: https://js.tensorflow.org/api/latest/#layers.convLstm2d


Next Article
Tensorflow.js tf.layers.conv3d() Function

S

satyam00so
Improve
Article Tags :
  • JavaScript
  • Web Technologies
  • Tensorflow.js
  • TensorFlow.js-layers

Similar Reads

  • Tensorflow.js tf.layers.convLstm2dCell() Function
    Tensorflow.js is an open-source library that is being developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment. The tf.layers.convLstm2dCell() is used to create ConvLSTM2DCell which is different from the ConvRNN2D subclass Co
    4 min read
  • Tensorflow.js tf.layers.conv2d() 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.
    3 min read
  • Tensorflow.js tf.layers.conv1d() Function
    Tensorflow.js is a javascript library developed by Google to run and train machine learning models in the browser or in Node.js. Tensorflow.js tf.layers.conv1d() function is used to create convolution layer. It is used to applied 1d convolution to the input data. The convolutional layer is used to m
    4 min read
  • Tensorflow.js tf.layers.conv3d() 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.
    3 min read
  • Tensorflow.js tf.layers.dot() 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. Tensorflow.js tf.layers.dot() function is used to apply the dot product between the two tensors provided. Syntax:  tf.layers.dot(args)
    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
  • Tensorflow.js tf.layers.conv2dTranspose() 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 in Node.js. The tf.
    4 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.add() 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
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences