Tensorflow.js tf.image.cropAndResize() 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.cropAndResize() function is used to take out the outputs from the stated input image tensor as well as rescales them through bilinear sampling or else nearest neighbor sampling to a normal output dimension as stated by crop length.
tf.image.cropAndResize(image, boxes, boxInd, cropSize, method?, extrapolationValue?)
Parameters: This method accepts the following parameters:
- images: The stated 4d tensor, which is of configuration [batch, imageHeight, imageWidth, depth]. Where, imageHeight as well as imageWidth should be positive, defining the group of images from which the crops are to be taken. It can be of type tf.Tensor4D, TypedArray, or Array.
- boxes: The stated 2d float32 tensor, which is of configuration [numBoxes, 4]. And every access is [y1, x1, y2, x2], allowing that (y1, x1) and (y2, x2) are the standardized coordinates of the box in the boxInd[i] image in the group. It can be of type tf.Tensor2D, TypedArray, or Array.
- boxInd: The stated 1d int32 tensor, which is of configuration [numBoxes] along with values in the range [0, batch) which defines the image that the i-th box indicates. It is of type tf.Tensor1D, TypedArray, or Array.
- cropSize: It is the stated 1d int32 tensor that has two elements and is of configuration [cropHeigh, cropWidth] defining the length to which each and every crops are rescaled to. It is of type [number, number].
- method: It is an optional parameter that defines the sampling method for rescaling. The by default value is bilinear. It can be of type ‘bilinear’, or ‘nearest’.
- extrapolationValue: It is the stated threshold that is used to conclude at which time to delete boxes on the basis of the stated score. The Default value is zero. It is optional and is of type number.
Return Value: It returns tf.Tensor4D object.
Example 1: Using a 4d tensor, boxes, boxInd, and cropSize parameters.
Tensor [ [ [[0, 0],]]]
Example 2: Using an array of floats, method, as well as extrapolationValue.
Tensor [[ [[0, 0, 0, 0],], [[0, 0, 0, 0],]], [ [[0, 0, 0, 0],], [[0, 0, 0, 0],]]]