Open In App

Tensorflow.js tf.separableConv2d() Function

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 .separableConv2d() function is used to determine a 2D complication along with filters that are separable. It executes a depthwise complication which works distinctly on channels pursued by means of a pointwise complexity which is helpful in mixing channels. Moreover, it specifies separability within [1, 2] and 3 dimensions, absolutely not structural separability within 1 and 2 dimensions.



Syntax:

tf.separableConv2d(x, depthwiseFilter, pointwiseFilter, 
        strides, pad, dilation?, dataFormat?)

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.tensor4d([1, 2, 3, 4], [1, 1, 2, 2]);
  
// Defining depthwise filter tensor
const y = tf.tensor4d([1, 1, 0, 4], [1, 1, 2, 2]);
  
// Defining pointwise filter tensor
const z = tf.tensor4d([1, 1, 0, 4], [1, 1,     4, 1]);
  
// Calling separableConv2d() method
const result = tf.separableConv2d(x, y, z, 2, 'valid');
  
// Printing output
result.print();

Output:

Tensor
     [ [ [[34],]]]

Example 2:




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Calling separableConv2d() method
tf.separableConv2d(
    tf.tensor4d([1.1, 2.2, 3.3, 4.4], [1, 1, 2, 2]), 
    tf.tensor4d([1.2, 1.1, 0.3, 4.5], [1, 1, 2, 2]),
    tf.tensor4d([1.4, 1.6, 0.5, 4.8], [1, 1,     4, 1]),
    1, 'same', 1, 'NHWC').print();

Output:

Tensor
    [[[[51.6340065 ],
       [107.0520096]]]]

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


Article Tags :