Tensorflow.js tf.image.resizeBilinear() Function - GeeksforGeeks

28 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.resizeBilinear() function is used to bilinearly rescale an individual 3D image or else a heap of 3D images to a different configuration.
Syntax:
tf.image.resizeBilinear(images, size, alignCorners?, halfPixelCenters?)
Parameters:  
images: The stated images of rank 4 or else rank 3, which is of configuration [batch, height, width, inChannels]. Moreover, in case its of rank 3, then the batch of one is presumed. It can be of type tf.Tensor3D, tf.Tensor4D, TypedArray, or Array.
size: The different stated configuration [newHeight, newWidth] in order to rescale the images. Every channel is rescaled one by one. It is of type [number, number].
alignCorners: It is the optional parameter whose by default value is false. In case its true, the the input is resized by (new_height – 1) / (height – 1), that absolutely queues the four corners of the stated images as well as rescaled images. However, if its false then it is rescaled by new_height / height. It deals in the same manner with the width dimension. It is of type Boolean.
halfPixelCenters: It is the optional parameter whose by default value is false. It is of type Boolean.
Return Value: It returns tf.Tensor3D, or tf.Tensor4D.
Example 1: In this example, we are going to use a 4d tensor and a size parameter inside tf.image.resizeBilinear() function.
Javascript
// Importing the tensorflow.js libraryimport * as tf from "@tensorflow/tfjs"  // Calling image.resizeBilinear() method and// Printing outputtf.image.resizeBilinear(tf.tensor4d([[    [[4, 7], [21, 9]],    [[8, 9], [1, 33]]  ]]), [3, 4]).print();
Output:
Tensor
    [[[[4        , 7        ],
       [12.5     , 8        ],
       [21       , 9        ],
       [21       , 9        ]],

      [[6.666667 , 8.333333 ],
       [7.1666665, 16.666666],
       [7.666666 , 25       ],
       [7.666666 , 25       ]],

      [[8        , 9        ],
       [4.5      , 21       ],
       [1        , 33       ],
       [1        , 33       ]]]]
Example 2:  In this example, we are going to use an array of floats, alignCorners, as well as halfPixelCenters.
Javascript
// Importing the tensorflow.js libraryimport * as tf from "@tensorflow/tfjs"  // Defining an array of floatsconst 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.resizeBilinear() method and// Printing outputtf.image.resizeBilinear(arr, [1, 2], true, false).print();
Output:
Tensor
    [[[[1.1, 1.7, 1.5      , 1.1      ],
       [1.7, 1.9, 8.1000004, 6.3000002]]]]
Reference: https://js.tensorflow.org/api/latest/#image.resizeBilinear
Picked
Tensorflow.js
JavaScript
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Difference between var, let and const keywords in JavaScript
Difference Between PUT and PATCH Request
Remove elements from a JavaScript Array
How to get character array from string in JavaScript?
How to get selected value in dropdown list using JavaScript ?
Top 10 Front End Developer Skills That You Need in 2022
Installation of Node.js on Linux
Top 10 Projects For Beginners To Practice HTML and CSS Skills
How to fetch data from an API in ReactJS ?
How to insert spaces/tabs in text using HTML/CSS?