Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Tensorflow.js tf.layers.permute() Function

  • Last Updated : 13 Jul, 2021

The layers in models are the basic blocks in constructions of models, for every layer perform some computation on input and output to the next layer. 
The tf.layers.permute() function is inherited from layers class and is used to permute the dimensions of the input in a given pattern, Also used to connect RNNs and convnet together. In this post, we are going to know how this function works.

Syntax: 

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

tf.layers.permute(agrs)

Parameters :

  • dims: It is an array of integer which represents permutation pattern. It does not include batch dimensions.
  • inputShape: It is used to create and insert the input layer.
  • batchInputShape: It is used to create and insert the input layer. If inputShape and batchInputShape both are mentioned then batchInputShape will be used.
  • batchSize: It is used to create batchInputShape when inputShape is specified and batchInputShape not.
  • dtype: The datatype of layer.
  • name: It represents the name of the layer.
  • trainable: It is a boolean value that represents whether weights are updated or not by fit.
  • weights: It is an array of weight that represent the initial weight values of layers.

Returns: Permute



Example 1: In this example, we are going to create a model with a single layer and only passing the required args to permute() function.

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
 
//create model
const model = tf.sequential();
 
//add layer into model and use permute() method
model.add(tf.layers.permute({
   dims: [2,1],
   inputShape:[8,8]
}));
 
//print outputShape
console.log("Output Shape"+model.outputShape);
 
//model summary()
model.summary()

Output:

Output Shape,8,8
_________________________________________________________________
Layer (type)                 Output shape              Param #    
=================================================================
permute_Permute11 (Permute)  [null,8,8]                0          
=================================================================
Total params: 0
Trainable params: 0
Non-trainable params: 0
_________________________________________________________________

Example 2: In this example, we are going to create model with 2 layers layer 1 and layer 2 with permute() function and passing all args to it.

Javascript




// Importing the tensorflow.js library
//import * as tf from "@tensorflow/tfjs"
 
//create model
const model = tf.sequential();
 
//add layer into model and use permute() method
//layer 1
model.add(tf.layers.permute({
   dims: [2,1],
   inputShape:[10,64],
   dtype:'int32',
   name:'layer1',
   batchSize:2,
  trainable:true,
  inputDType:'int32'
   
}));
 
//add layer2
model.add(tf.layers.permute({
   dims: [2,1],
   inputShape:[8,16],
   dtype:'int32',
   name:'layer2',
   batchSize:2,
  trainable:true,
  inputDType:'int32'
   
}));
 
//print outputShape
console.log("Output Shape :"+model.outputShape);
 
//model summary()
model.summary()

Output: 

Output Shape :2,10,64
_________________________________________________________________
Layer (type)                 Output shape              Param #    
=================================================================
layer1 (Permute)             [2,64,10]                 0          
_________________________________________________________________
layer2 (Permute)             [2,10,64]                 0          
=================================================================
Total params: 0
Trainable params: 0
Non-trainable params: 0
_________________________________________________________________

References: https://js.tensorflow.org/api/latest/#layers.permute




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!