Tensorflow.js tf.layers.permute() Function
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:
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 agrs to permute() function.
Javascript
import * as tf from "@tensorflow/tfjs"
const model = tf.sequential();
model.add(tf.layers.permute({
dims: [2,1],
inputShape:[8,8]
}));
console.log( "Output Shape" +model.outputShape);
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 agrs to it.
Javascript
const model = tf.sequential();
model.add(tf.layers.permute({
dims: [2,1],
inputShape:[10,64],
dtype: 'int32' ,
name: 'layer1' ,
batchSize:2,
trainable: true ,
inputDType: 'int32'
}));
model.add(tf.layers.permute({
dims: [2,1],
inputShape:[8,16],
dtype: 'int32' ,
name: 'layer2' ,
batchSize:2,
trainable: true ,
inputDType: 'int32'
}));
console.log( "Output Shape :" +model.outputShape);
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
Last Updated :
14 Feb, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...