Open In App

Tensorflow.js tf.conv2dTranspose() Function

Introduction: 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 .conv2dTranspose() function is used to determine the transposed 2D convolution of an image. It is also recognized as a deconvolution.



Syntax:

tf.conv2dTranspose(x, filter, outputShape, strides, pad, dimRoundingMode?)

Parameters:



Return Value: It returns tf.Tensor3D or tf.Tensor4D.

Example 1:




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Defining input tensor
const x = tf.tensor3d([1, 2, 2, 3], [2, 2, 1]);
  
// Defining filter tensor
const y = tf.tensor4d([3, 3, 3, 2], [1, 2, 2, 1]);
  
// Calling conv2dTranspose() method
const result = tf.conv2dTranspose(x, y, [1, 1, 2], 2, 'same');
  
// Printing output
result.print();

Output:

Tensor
     [ [[3, 3],]]

Example 2:




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Calling conv2dTranspose() method with 
// all its parameters
tf.tensor3d([1.1, 2.2, 3.3, 4.4], [2, 2, 1]).conv2dTranspose(
 tf.tensor4d([1.3, 1.2, null, -4], [1, 2, 2, 1]),
            [1, 1,  2], 1, 1, 'ceil').print();

Output:

Tensor
     [ [[5.7199998, -7.9199996],]]

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


Article Tags :