Open In App

Tensorflow.js tf.image.flipLeftRight() Function

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

The .image.flipLeftRight() function is used to flip the stated image from left hand side to the right hand side. For the time being its accessible in the CPU, WebGL, as well as WASM backends.



Syntax:

tf.image.flipLeftRight(image)

Parameters:  



Return Value: It returns the tf.Tensor4D object.

Example 1: In this example, we are going to see the use of using a 4d tensor in Tensorflow.js tf.image.flipLeftRight() function.




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Calling image.flipLeftRight() method and
// Printing output
tf.image.flipLeftRight(tf.tensor4d([[
  
  [[4, 7], [21, 9]],
  
  [[8, 9], [1, 5]]
  
]])).print();

Output:

Tensor
    [[[[21, 9],
       [4 , 7]],

      [[1 , 5],
       [8 , 9]]]]

Example 2: In this example, we are going to see the use of an array of floats inside Tensorflow.js tf.image.flipLeftRight() function.




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Defining an array of floats
const arr = [[
  
  [[1.1, 1.7, 1.5, 1.1], 
  [1.7, 1.9, 8.1, 6.3]],
  [[3.3, 3.4, 3.7, 4.0], 
  [5.1, 5.2, 5.3, 5.9]]
  
]];
  
// Calling image.flipLeftRight() method and
// Printing output
tf.image.flipLeftRight(arr).print();

Output:

Tensor
    [[[[1.7      , 1.9      , 8.1000004, 6.3000002],
       [1.1      , 1.7      , 1.5      , 1.1      ]],

      [[5.0999999, 5.1999998, 5.3000002, 5.9000001],
       [3.3      , 3.4000001, 3.7      , 4        ]]]]

Reference: https://js.tensorflow.org/api/latest/#image.flipLeftRight


Article Tags :