Tensorflow.js tf.image.flipLeftRight() Function
Last Updated :
29 Jul, 2021
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:
- image: It is the stated 4d tensor of structure [batch, imageHeight, imageWidth, depth]. It can be of type tf.Tensor4D, TypedArray, or Array.
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.
Javascript
import * as tf from "@tensorflow/tfjs"
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.
Javascript
import * as tf from "@tensorflow/tfjs"
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]]
]];
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
Share your thoughts in the comments
Please Login to comment...