Open In App

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 ConvLSTM2D and the call method takes the input data of only a single time step and return the cell’s output at the time step. convLstm2dCell is the Cell class for ConvLSTM2D.



Syntax:

tf.layers.convLstmd2dCell( args )

Parameters: 



Parameters: It returns ConvLSTMCell

Example 1:




import * as tf from "@tensorflow/tfjs";
 
// InputShape and Input layer for convLstm2dCell layer
const InputShape = [ 4, 2, 5, 5, 2];
const input = tf.input({ shape: InputShape });
 
// Creating ConvLstm2dCell
const convLstm2dCell = tf.layers.convLstm2dCell(
    { filters:4, kernelSize:4});
const output = convLstm2dCell.apply(input);
 
// Printing summary of layers
const model = tf.model({ inputs: input, outputs: output });
model.summary();

Output:

__________________________________________________________________________________________
Layer (type)                Input Shape               Output shape              Param #   
==========================================================================================
input6 (InputLayer)         [[null,4,2,5,5,2]]        [null,4,2,5,5,2]          0         
__________________________________________________________________________________________
conv_lst_m2d_cell_ConvLSTM2 [[null,4,2,5,5,2]]        [null,4,2,5,5,2]          1552      
==========================================================================================
Total params: 1552
Trainable params: 1552
Non-trainable params: 0
__________________________________________________________________________________________

Example 2:




// Importing header file
import * as tf from "@tensorflow/tfjs"
// Creating layer for convLstm2dCell
const filters = 3;
const kernelSize = 3;
const inputShape = [1, 3, 3, 3];
const input = tf.ones(inputShape);
 
const convLstm2dCell = tf.layers
    .convLstm2dCell({filters, kernelSize});
     
convLstm2dCell.build(input.shape);
 
 
const outShape = [1, 1, 1, 3];
const c = tf.zeros(outShape);
const h = tf.zeros(outShape);
 
// Printing Tensor
const [first, second, third] =
    convLstm2dCell.call([input, c, h], {});
     
console.log("First Tensor");
first.print();
console.log("\nSecond Tensor");
second.print();
console.log("\nThird Tensor");
third.print();

Output:

First Tensor
Tensor
     [ [ [[0.1302425, 0.0364179, 0.0439035],]]]

Second Tensor
Tensor
     [ [ [[0.1302425, 0.0364179, 0.0439035],]]]

Third Tensor
Tensor
     [ [ [[0.3106561, 0.1217758, 0.1326777],]]]

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


Article Tags :