Open In App

Tensorflow.js tf.mirrorPad() 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 .mirrorPad() function is used to pad the stated tensor input with the help of mirror padding. Moreover, this method is beneficial in implementing the REFLECT as well as SYMMETRIC modes of pad.



Syntax :  

tf.mirrorPad(x, paddings, mode)

Parameters:  



  
 

Note:

 

 

Return Value: It returns tf.Tensor object.

 

Example 1:

 




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
 
// Defining tensor input
const y = tf.tensor1d([4, 5, 6]);
 
// Defining paddings and mode of
// padding
const padding = [[0, 1]];
const mode = 'reflect';
 
// Calling tf.mirrorPad() method
var res = tf.mirrorPad(y, padding, mode);
 
// Printing output
res.print();

 

 

Output:

 

Tensor
    [4, 5, 6, 5] 

 

Example 2:

 




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
 
// Calling tf.mirrorPad() method and
// Printing output
tf.mirrorPad(tf.tensor(
    [2.4, 6.8, 9.3, 5.3]),
    [[0, 2]], 'symmetric').print();

 

 

Output:

 

Tensor
    [2.4000001, 6.8000002, 9.3000002, 
    5.3000002, 5.3000002, 9.3000002] 

 

Reference: https://js.tensorflow.org/api/latest/#mirrorPad

 


Article Tags :