Tensorflow.js tf.layers.zeroPadding2d() Function - GeeksforGeeks

17 Feb, 2022Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment.The tf.layers.zeroPadding2d( ) function is used for adding rows and columns for zeros at the top, bottom, left, and right side of and image tensor.Syntax: tf.layers.zeroPadding2d(args); Parameters: This method accepts the args as a parameter which has the following properties:Padding: This variable accepts an integer, or an Array of 2 integers, or Array of 2 Arrays, each of which is an array of 2 integers. Interpretation of this variable is:If a variable is an integer, the same symmetric is applied to width and height.If a variable is an array of 2 integers, interpreted as two different symmetric values of height and width.If a variable is an array of 2 arrays, interpreted as topPad, bottomPad for the first array, and leftPad, rightPad for the second array.dataFormat: This variable define the format of the shape of the input Tensor. If can be  channelsLast or  channelsFirst. This value defines the ordering of the dimensions in the inputs. The channelsLast define shape [ batch, height, width, channels] while channelsFirst define [ batch, channels, height, width].inputShape: It can be null or an array of numbers. It is used to create an input layer to insert before the following layer. This variable is only used for the first layer of a model.batchInputShape: This variable accept null or array of number. This variable works the same as inputShape but If both inputShape and batchInputShape are defined, batchInputShape is used. This variable is only used for the first layer of a model.batchSize: It is a number, and It helps batchInputShape variable. if batchInputShape is not defined it is used for creating batchInputShape.dtype: This variable is used for defining data type for the padding layer. It is Default to ‘float32’. This variable is only used for first layer of a model.name: It defined the name of layer.trainable: It is a boolean type. It defined layer data are updatable by fit or not. Defaults value is true.weights: It is tf.Tensor type. It declares the Initial weight values of the layer.inputDType: It defines the data type of the input layer. Legacy support. Do not use for new code.Returns: It returns ZeroPadding2D object.Example 1: In this example, we add a zero-padding layer with default values.JavascriptJavascript// Importing tensorflowconst tf = require("@tensorflow/tfjs") // Input 4d Tensor    const img4d = tf.tensor4d([1, 2, 3, 4], [1, 2, 2, 1]); // Adding padding in Tensorconst pad = tf.layers.zeroPadding2d();const imgpad = pad.apply(img4d); // Printing 4d Tensor with padding</div>imgpad.print()  Output: Tensor    [[[[0], [0], [0], [0]],
            [[0], [1], [2], [0]],
            [[0], [3], [4], [0]],
            [[0], [0], [0], [0]]]]Example 2: In this example, we add zero paddings in tensor of specific data type and with define data-Format. JavascriptJavascript// Importing tensorflowconst tf = require("@tensorflow/tfjs") // Input 4d Tensor    const img4d = tf.tensor4d([1, 2, 3, 4], [1, 2, 2, 1]); // Adding padding in Tensorconst pad = tf.layers.zeroPadding2d({    padding: 2,    dataFormat: 'channelsFirst', dtype: 'int32'}); const imgpad = pad.apply(img4d); // Printing 4d Tensor with paddingimgpad.print()  Output:  Tensor
    [[[[0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0],
       [0, 0, 1, 0, 0],
       [0, 0, 2, 0, 0],
       [0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0]],

      [[0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0],
       [0, 0, 3, 0, 0],
       [0, 0, 4, 0, 0],
       [0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0]]]] Reference: https://js.tensorflow.org/api/latest/#layers.zeroPadding2d My Personal Notes
arrow_drop_upSave

Like2PreviousTensorFlow.js Browser Complete ReferenceNext
Tensorflow.js tf.backend() FunctionRecommended ArticlesPage :How to get the function name from within that function using JavaScript ?30, May 19How to call a function that return another function in JavaScript ?24, Jul 19How to get the function name inside a function in PHP ?25, Sep 19Python - Call function from another function04, Dec 19How to Check a Function is a Generator Function or not using JavaScript ?26, Mar 20How to implement a function that enable another function after specified time using JavaScript ?10, Mar 21How to create a function that invokes the provided function with its arguments transformed in JavaScript?18, Jul 21How to create a function that invokes each provided function with the arguments it receives using JavaScript ?25, May 21How to create a function that invokes function with partials prepended arguments in JavaScript ?26, Jul 21Difference between ‘function declaration’ and ‘function expression' in JavaScript20, Sep 21Find the power function that the graph of f resembles for large values of |x|, given the function f(x) = (x + 6)2 (x - 2)210, Oct 21Difference between Function.prototype.apply and Function.prototype.call16, Nov 21Explain the differences on the usage of foo between function foo() {} and var foo = function() {}02, Mar 22How does TypeScript support optional parameters in function as every parameter is optional for a function in JavaScript ?24, Mar 22What are the advantages of synchronous function over asynchronous function in Node.js ?28, Mar 22How to create a function that invokes function with partials appended to the arguments in JavaScript ?28, May 21PHP | imagecreatetruecolor() Function18, Sep 18p5.js | year() function07, Apr 19D3.js | d3.utcTuesdays() Function24, Jul 19PHP | ImagickDraw getTextAlignment() Function16, Dec 19PHP | Ds\Sequence last() Function24, Jan 19PHP | Imagick floodFillPaintImage() Function30, Jul 19Function to escape regex patterns before applied in PHP31, Oct 19PHP | array_udiff_uassoc() Function11, Jul 18Article Contributed By :satyam00so@satyam00soVote for difficultyEasy
Normal
Medium
Hard
ExpertImproved By :anikakapooradnanirshad158germanshephered48Article Tags :PickedTensorflow.jsJavaScriptWeb TechnologiesImprove ArticleReport IssueWriting code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Load CommentsWhat's NewInterview Series- Prepare, Practice & UpskillView DetailsData Structures & Algorithms- Self Paced CourseView DetailsComplete Interview PreparationView DetailsMost popular in JavaScriptRemove elements from a JavaScript ArrayConvert a string to an integer in JavaScriptDifference between var, let and const keywords in JavaScriptHow to calculate the number of days between two dates in javascript?Differences between Functional Components and Class Components in ReactMost visited in Web TechnologiesRemove elements from a JavaScript ArrayInstallation of Node.js on LinuxConvert a string to an integer in JavaScriptHow to fetch data from an API in ReactJS ?How to insert spaces/tabs in text using HTML/CSS?×
5th Floor, A-118,Sector-136, Noida, Uttar Pradesh - 201305
feedback@geeksforgeeks.orgCompanyAbout UsCareersIn MediaContact UsPrivacy PolicyCopyright PolicyLearnAlgorithmsData StructuresSDE Cheat SheetMachine learningCS SubjectsVideo TutorialsNewsTop NewsTechnologyWork & CareerBusinessFinanceLifestyleLanguagesPythonJavaCPPGolangC#SQLWeb DevelopmentWeb TutorialsDjango TutorialHTMLCSSJavaScriptBootstrapContributeWrite an ArticleImprove an ArticlePick Topics to WriteWrite Interview ExperienceInternshipsVideo Internship@geeksforgeeks
, Some rights reserved 
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
        Privacy Policy

Got It !
Start Your Coding Journey Now!Login
Register
Tensorflow.js tf.tensor() Function
Tensorflow.js tf.scalar() Function
TenserFlow.js Tensors Creation Complete Reference
Tensorflow.js tf.Tensor class .buffer() Method
Tensorflow.js tf.Tensor class .bufferSync() Method
TensorFlow.js Tensors Classes Complete Reference
Tensorflow.js tf.booleanMaskAsync() Function
Tensorflow.js tf.concat() Function
TensorFlow.js Tensors Transformations Complete Reference
TensorFlow.js Slicing and Joining Complete Reference
Tensorflow.js tf.einsum() Function
Tensorflow.js tf.multinomial() Function
TensorFlow.js Tensor Random Complete Reference
Tensorflow.js tf.layers.zeroPadding2d() Function
Tensorflow.js tf.input() Function
Tensorflow.js tf.loadGraphModel() Function
Tensorflow.js tf.io.http() Function
TensorFlow.js Models Loading Complete Reference
Tensorflow.js tf.io.copyModel() Function
Tensorflow.js tf.io.listModels() Function
Tensorflow.js tf.io.moveModel() Function
TensorFlow.js Models Management Complete Reference
Tensorflow.js tf.GraphModel Class
Tensorflow.js tf.GraphModel class .save() Method
Tensorflow.js tf.GraphModel class .predict() Method
Tensorflow.js tf.GraphModel class .execute() Method
TensorFlow.js Models Classes Complete Reference
Tensorflow.js tf.layers.zeroPadding2d() Function
Tensorflow.js tf.layers.elu() Function
Tensorflow.js tf.layers.activation() Function
TensorFlow.js Layers Basic Complete Reference
Tensorflow.js tf.layers.conv1d() Function
TensorFlow.js Layers Convolutional Complete Reference
Tensorflow.js tf.layers.add() Function
TensorFlow.js Layers Merge Complete Reference
Tensorflow.js tf.layers.globalAveragePooling1d() Function
TensorFlow.js Layers Pooling Complete Reference
TensorFlow.js Layers Noise Complete Reference
Tensorflow.js tf.layers.bidirectional() Function
Tensorflow.js tf.layers.timeDistributed() Function
TensorFlow.js Layers Classes Complete Reference
Tensorflow.js tf.layers.zeroPadding2d() Function
Tensorflow.js tf.layers.masking() Function
Tensorflow.js tf.layers.zeroPadding2d() Function
TensorFlow.js Operations Arithmetic Complete Reference
TensorFlow.js Operations Basic Math Complete Reference
TensorFlow.js Operations Matrices Complete Reference
TensorFlow.js Operations Normalization Complete Reference
TensorFlow.js Operations Images Complete Reference
TensorFlow.js Operations Logical Complete Reference
TensorFlow.js Operations Evaluation Complete Reference
Tensorflow.js tf.cumsum() Function
TensorFlow.js Operations Slicing and Joining Complete Reference
TensorFlow.js Operations Spectral Complete Reference
Tensorflow.js tf.unsortedSegmentSum() Function
Tensorflow.js tf.movingAverage() Function
Tensorflow.js tf.dropout() Function
TensorFlow.js Operations Signal Complete Reference
Tensorflow.js tf.linalg.bandPart() Function
Tensorflow.js tf.linalg.gramSchmidt() Function
Tensorflow.js tf.linalg.qr() Function
TensorFlow.js Operations Sparse Complete Reference
Tensorflow.js tf.layers.zeroPadding2d() Function
Tensorflow.js tf.grad() Function
Tensorflow.js tf.grads() Function
Tensorflow.js tf.customGrad() Function
TensorFlow.js Training Gradients Complete ReferenceTensorflow.js TrainingTensorflow.js tf.train.momentum() FunctionTensorflow.js tf.train.adagrad() FunctionTensorFlow.js Training Optimizers Complete ReferenceTensorflow.js tf.losses.absoluteDifference() FunctionTensorflow.js tf.losses.computeWeightedLoss() FunctionTensorflow.js tf.losses.cosineDistance() FunctionTensorFlow.js Training Losses Complete ReferenceTensorflow.js tf.train.Optimizer ClassTensorflow.js tf.train.Optimizer class .minimize() MethodTensorFlow.js Training Classes Complete ReferenceTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.time() FunctionTensorflow.js tf.nextFrame() FunctionTensorflow.js tf.profile() FunctionTensorFlow.js Performance Memory Complete ReferenceTensorflow.js PerformanceTensorflow.js tf.disposeVariables() FunctionTensorflow.js tf.enableDebugMode() FunctionTensorflow.js tf.enableProdMode() FunctionTensorflow.js tf.engine() FunctionTensorflow.js EnvironmentTensorFlow.js Environment Complete ReferenceTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.metrics.binaryAccuracy() FunctionTensorflow.js tf.metrics.binaryCrossentropy() FunctionTensorflow.js tf.metrics.categoricalAccuracy() FunctionTensorflow.js tf.metrics.categoricalCrossentropy() FunctionTensorflow.js tf.metrics.cosineProximity() FunctionTensorflow.js ConstraintsTensorflow.js tf.metrics.meanSquaredError() FunctionTensorflow.js tf.metrics.precision() FunctionTensorflow.js tf.metrics.recall() FunctionTensorflow.js tf.metrics.sparseCategoricalAccuracy() FunctionTensorFlow.js Metrics Complete ReferenceTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.initializers.Initializer ClassTensorflow.js tf.initializers.constant() MethodTensorflow.js tf.initializers.glorotNormal() FunctionTensorflow.js tf.initializers.glorotUniform() FunctionTensorflow.js tf.initializers.heNormal() FunctionTensorflow.js tf.initializers.heUniform() FunctionTensorflow.js InitializersTensorFlow.js Initializers Complete ReferenceTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.regularizers.l1() FunctionTensorflow.js tf.regularizers.l1l2() FunctionTensorflow.js tf.regularizers.l2() FunctionTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.data.csv() FunctionTensorflow.js tf.data.generator() FunctionTensorflow.js tf.data.microphone() FunctionTensorflow.js RegularizesTensorFlow.js Data Creation Complete ReferenceTensorflow.js tf.data.zip() FunctionTensorflow.js tf.data.Dataset class .batch() MethodTensorflow.js DataTensorFlow.js Data Classes Complete ReferencesTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.util.assert() FunctionTensorflow.js tf.util.createShuffledIndices() FunctionTensorflow.js tf.decodeString() FunctionTensorflow.js tf.encodeString() FunctionTensorflow.js tf.fetch() FunctionTensorflow.js tf.util.flatten() FunctionTensorflow.js tf.util.now() FunctionTensorflow.js tf.util.shuffle() FunctionTensorflow.js tf.util.shuffleCombo() FunctionTensorflow.js UtilTensorflow.js tf.browser.fromPixels() FunctionTensorflow.js tf.browser.fromPixelsAsync() FunctionTensorflow.js tf.browser.toPixels() FunctionTensorFlow.js Browser Complete ReferenceTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.backend() FunctionTensorflow.js tf.getBackend() FunctionTensorflow.js tf.ready() FunctionTensorflow.js tf.registerBackend() FunctionTensorflow.js tf.removeBackend() FunctionTensorflow.js tf.setBackend() FunctionTensorflow.js BrowserTensorflow.js tf.callbacks.earlyStopping() FunctionTensorflow.js BackendsTensorflow.js MetricsTable of ContentsTensorFlow.jsTensorflow.js IntroductionTensorflow.js TensorsTensorflow.js tf.tensor() FunctionTensorflow.js tf.scalar() FunctionTenserFlow.js Tensors Creation Complete ReferenceTensorflow.js tf.Tensor class .buffer() MethodTensorflow.js tf.Tensor class .bufferSync() MethodTensorFlow.js Tensors Classes Complete ReferenceTensorflow.js tf.booleanMaskAsync() FunctionTensorflow.js tf.concat() FunctionTensorFlow.js Tensors Transformations Complete ReferenceTensorFlow.js Slicing and Joining Complete ReferenceTensorflow.js tf.einsum() FunctionTensorflow.js tf.multinomial() FunctionTensorFlow.js Tensor Random Complete ReferenceTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js ModelsTensorflow.js tf.input() FunctionTensorflow.js tf.loadGraphModel() FunctionTensorflow.js tf.io.http() FunctionTensorFlow.js Models Loading Complete ReferenceTensorflow.js tf.io.copyModel() FunctionTensorflow.js tf.io.listModels() FunctionTensorflow.js tf.io.moveModel() FunctionTensorFlow.js Models Management Complete ReferenceTensorflow.js tf.GraphModel ClassTensorflow.js tf.GraphModel class .save() MethodTensorflow.js tf.GraphModel class .predict() MethodTensorflow.js tf.GraphModel class .execute() MethodTensorFlow.js Models Classes Complete ReferenceTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.layers.elu() FunctionTensorflow.js LayersTensorflow.js tf.layers.activation() FunctionTensorFlow.js Layers Basic Complete ReferenceTensorflow.js tf.layers.conv1d() FunctionTensorFlow.js Layers Convolutional Complete ReferenceTensorflow.js tf.layers.add() FunctionTensorFlow.js Layers Merge Complete ReferenceTensorflow.js tf.layers.globalAveragePooling1d() FunctionTensorFlow.js Layers Pooling Complete ReferenceTensorFlow.js Layers Noise Complete ReferenceTensorflow.js tf.layers.bidirectional() FunctionTensorflow.js tf.layers.timeDistributed() FunctionTensorFlow.js Layers Classes Complete ReferenceTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.layers.masking() FunctionTensorflow.js tf.layers.zeroPadding2d() FunctionTensorFlow.js Operations Arithmetic Complete ReferenceTensorFlow.js Operations Basic Math Complete ReferenceTensorFlow.js Operations Matrices Complete ReferenceTensorflow.js OperationsTensorFlow.js Operations Normalization Complete ReferenceTensorFlow.js Operations Images Complete ReferenceTensorFlow.js Operations Logical Complete ReferenceTensorFlow.js Operations Evaluation Complete ReferenceTensorflow.js tf.cumsum() FunctionTensorFlow.js Operations Slicing and Joining Complete ReferenceTensorFlow.js Operations Spectral Complete ReferenceTensorflow.js tf.unsortedSegmentSum() FunctionTensorflow.js tf.movingAverage() FunctionTensorflow.js tf.dropout() FunctionTensorFlow.js Operations Signal Complete ReferenceTensorflow.js tf.linalg.bandPart() FunctionTensorflow.js tf.linalg.gramSchmidt() FunctionTensorflow.js tf.linalg.qr() FunctionTensorFlow.js Operations Sparse Complete ReferenceTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.grad() FunctionTensorflow.js tf.grads() FunctionTensorflow.js tf.customGrad() FunctionTensorFlow.js Training Gradients Complete ReferenceTensorflow.js TrainingTensorflow.js tf.train.momentum() FunctionTensorflow.js tf.train.adagrad() FunctionTensorFlow.js Training Optimizers Complete ReferenceTensorflow.js tf.losses.absoluteDifference() FunctionTensorflow.js tf.losses.computeWeightedLoss() FunctionTensorflow.js tf.losses.cosineDistance() FunctionTensorFlow.js Training Losses Complete ReferenceTensorflow.js tf.train.Optimizer ClassTensorflow.js tf.train.Optimizer class .minimize() MethodTensorFlow.js Training Classes Complete ReferenceTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.time() FunctionTensorflow.js tf.nextFrame() FunctionTensorflow.js tf.profile() FunctionTensorFlow.js Performance Memory Complete ReferenceTensorflow.js PerformanceTensorflow.js tf.disposeVariables() FunctionTensorflow.js tf.enableDebugMode() FunctionTensorflow.js tf.enableProdMode() FunctionTensorflow.js tf.engine() FunctionTensorflow.js EnvironmentTensorFlow.js Environment Complete ReferenceTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.metrics.binaryAccuracy() FunctionTensorflow.js tf.metrics.binaryCrossentropy() FunctionTensorflow.js tf.metrics.categoricalAccuracy() FunctionTensorflow.js tf.metrics.categoricalCrossentropy() FunctionTensorflow.js tf.metrics.cosineProximity() FunctionTensorflow.js ConstraintsTensorflow.js tf.metrics.meanSquaredError() FunctionTensorflow.js tf.metrics.precision() FunctionTensorflow.js tf.metrics.recall() FunctionTensorflow.js tf.metrics.sparseCategoricalAccuracy() FunctionTensorFlow.js Metrics Complete ReferenceTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.initializers.Initializer ClassTensorflow.js tf.initializers.constant() MethodTensorflow.js tf.initializers.glorotNormal() FunctionTensorflow.js tf.initializers.glorotUniform() FunctionTensorflow.js tf.initializers.heNormal() FunctionTensorflow.js tf.initializers.heUniform() FunctionTensorflow.js InitializersTensorFlow.js Initializers Complete ReferenceTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.regularizers.l1() FunctionTensorflow.js tf.regularizers.l1l2() FunctionTensorflow.js tf.regularizers.l2() FunctionTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.data.csv() FunctionTensorflow.js tf.data.generator() FunctionTensorflow.js tf.data.microphone() FunctionTensorflow.js RegularizesTensorFlow.js Data Creation Complete ReferenceTensorflow.js tf.data.zip() FunctionTensorflow.js tf.data.Dataset class .batch() MethodTensorflow.js DataTensorFlow.js Data Classes Complete ReferencesTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.util.assert() FunctionTensorflow.js tf.util.createShuffledIndices() FunctionTensorflow.js tf.decodeString() FunctionTensorflow.js tf.encodeString() FunctionTensorflow.js tf.fetch() FunctionTensorflow.js tf.util.flatten() FunctionTensorflow.js tf.util.now() FunctionTensorflow.js tf.util.shuffle() FunctionTensorflow.js tf.util.shuffleCombo() FunctionTensorflow.js UtilTensorflow.js tf.browser.fromPixels() FunctionTensorflow.js tf.browser.fromPixelsAsync() FunctionTensorflow.js tf.browser.toPixels() FunctionTensorFlow.js Browser Complete ReferenceTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.backend() FunctionTensorflow.js tf.getBackend() FunctionTensorflow.js tf.ready() FunctionTensorflow.js tf.registerBackend() FunctionTensorflow.js tf.removeBackend() FunctionTensorflow.js tf.setBackend() FunctionTensorflow.js BrowserTensorflow.js tf.callbacks.earlyStopping() FunctionTensorflow.js BackendsTensorflow.js MetricsImprove Article

Save Article

Like Article

Tensorflow.js tf.layers.zeroPadding2d() FunctionLast Updated :
17 Feb, 2022Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment.The tf.layers.zeroPadding2d( ) function is used for adding rows and columns for zeros at the top, bottom, left, and right side of and image tensor.Syntax: tf.layers.zeroPadding2d(args); Parameters: This method accepts the args as a parameter which has the following properties:Padding: This variable accepts an integer, or an Array of 2 integers, or Array of 2 Arrays, each of which is an array of 2 integers. Interpretation of this variable is:If a variable is an integer, the same symmetric is applied to width and height.If a variable is an array of 2 integers, interpreted as two different symmetric values of height and width.If a variable is an array of 2 arrays, interpreted as topPad, bottomPad for the first array, and leftPad, rightPad for the second array.dataFormat: This variable define the format of the shape of the input Tensor. If can be  channelsLast or  channelsFirst. This value defines the ordering of the dimensions in the inputs. The channelsLast define shape [ batch, height, width, channels] while channelsFirst define [ batch, channels, height, width].inputShape: It can be null or an array of numbers. It is used to create an input layer to insert before the following layer. This variable is only used for the first layer of a model.batchInputShape: This variable accept null or array of number. This variable works the same as inputShape but If both inputShape and batchInputShape are defined, batchInputShape is used. This variable is only used for the first layer of a model.batchSize: It is a number, and It helps batchInputShape variable. if batchInputShape is not defined it is used for creating batchInputShape.dtype: This variable is used for defining data type for the padding layer. It is Default to ‘float32’. This variable is only used for first layer of a model.name: It defined the name of layer.trainable: It is a boolean type. It defined layer data are updatable by fit or not. Defaults value is true.weights: It is tf.Tensor type. It declares the Initial weight values of the layer.inputDType: It defines the data type of the input layer. Legacy support. Do not use for new code.Returns: It returns ZeroPadding2D object.Example 1: In this example, we add a zero-padding layer with default values.JavascriptJavascript// Importing tensorflowconst tf = require("@tensorflow/tfjs") // Input 4d Tensor    const img4d = tf.tensor4d([1, 2, 3, 4], [1, 2, 2, 1]); // Adding padding in Tensorconst pad = tf.layers.zeroPadding2d();const imgpad = pad.apply(img4d); // Printing 4d Tensor with padding</div>imgpad.print()  Output: Tensor    [[[[0], [0], [0], [0]],
            [[0], [1], [2], [0]],
            [[0], [3], [4], [0]],
            [[0], [0], [0], [0]]]]Example 2: In this example, we add zero paddings in tensor of specific data type and with define data-Format. JavascriptJavascript// Importing tensorflowconst tf = require("@tensorflow/tfjs") // Input 4d Tensor    const img4d = tf.tensor4d([1, 2, 3, 4], [1, 2, 2, 1]); // Adding padding in Tensorconst pad = tf.layers.zeroPadding2d({    padding: 2,    dataFormat: 'channelsFirst', dtype: 'int32'}); const imgpad = pad.apply(img4d); // Printing 4d Tensor with paddingimgpad.print()  Output:  Tensor
    [[[[0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0],
       [0, 0, 1, 0, 0],
       [0, 0, 2, 0, 0],
       [0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0]],

      [[0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0],
       [0, 0, 3, 0, 0],
       [0, 0, 4, 0, 0],
       [0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0]]]] Reference: https://js.tensorflow.org/api/latest/#layers.zeroPadding2d My Personal Notes
arrow_drop_upSave

Like2PreviousTensorFlow.js Browser Complete ReferenceNext
Tensorflow.js tf.backend() FunctionRecommended ArticlesPage :How to get the function name from within that function using JavaScript ?30, May 19How to call a function that return another function in JavaScript ?24, Jul 19How to get the function name inside a function in PHP ?25, Sep 19Python - Call function from another function04, Dec 19How to Check a Function is a Generator Function or not using JavaScript ?26, Mar 20How to implement a function that enable another function after specified time using JavaScript ?10, Mar 21How to create a function that invokes the provided function with its arguments transformed in JavaScript?18, Jul 21How to create a function that invokes each provided function with the arguments it receives using JavaScript ?25, May 21How to create a function that invokes function with partials prepended arguments in JavaScript ?26, Jul 21Difference between ‘function declaration’ and ‘function expression' in JavaScript20, Sep 21Find the power function that the graph of f resembles for large values of |x|, given the function f(x) = (x + 6)2 (x - 2)210, Oct 21Difference between Function.prototype.apply and Function.prototype.call16, Nov 21Explain the differences on the usage of foo between function foo() {} and var foo = function() {}02, Mar 22How does TypeScript support optional parameters in function as every parameter is optional for a function in JavaScript ?24, Mar 22What are the advantages of synchronous function over asynchronous function in Node.js ?28, Mar 22How to create a function that invokes function with partials appended to the arguments in JavaScript ?28, May 21PHP | imagecreatetruecolor() Function18, Sep 18p5.js | year() function07, Apr 19D3.js | d3.utcTuesdays() Function24, Jul 19PHP | ImagickDraw getTextAlignment() Function16, Dec 19PHP | Ds\Sequence last() Function24, Jan 19PHP | Imagick floodFillPaintImage() Function30, Jul 19Function to escape regex patterns before applied in PHP31, Oct 19PHP | array_udiff_uassoc() Function11, Jul 18Article Contributed By :satyam00so@satyam00soVote for difficultyEasy
Normal
Medium
Hard
ExpertImproved By :anikakapooradnanirshad158germanshephered48Article Tags :PickedTensorflow.jsJavaScriptWeb TechnologiesImprove ArticleReport IssueWriting code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Load CommentsWhat's NewInterview Series- Prepare, Practice & UpskillView DetailsData Structures & Algorithms- Self Paced CourseView DetailsComplete Interview PreparationView DetailsMost popular in JavaScriptRemove elements from a JavaScript ArrayConvert a string to an integer in JavaScriptDifference between var, let and const keywords in JavaScriptHow to calculate the number of days between two dates in javascript?Differences between Functional Components and Class Components in ReactMost visited in Web TechnologiesRemove elements from a JavaScript ArrayInstallation of Node.js on LinuxConvert a string to an integer in JavaScriptHow to fetch data from an API in ReactJS ?How to insert spaces/tabs in text using HTML/CSS?×
5th Floor, A-118,Sector-136, Noida, Uttar Pradesh - 201305
feedback@geeksforgeeks.orgCompanyAbout UsCareersIn MediaContact UsPrivacy PolicyCopyright PolicyLearnAlgorithmsData StructuresSDE Cheat SheetMachine learningCS SubjectsVideo TutorialsNewsTop NewsTechnologyWork & CareerBusinessFinanceLifestyleLanguagesPythonJavaCPPGolangC#SQLWeb DevelopmentWeb TutorialsDjango TutorialHTMLCSSJavaScriptBootstrapContributeWrite an ArticleImprove an ArticlePick Topics to WriteWrite Interview ExperienceInternshipsVideo Internship@geeksforgeeks
, Some rights reserved 
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
        Privacy Policy

Got It !
Start Your Coding Journey Now!Login
Register
Tensorflow.js tf.train.momentum() Function
Tensorflow.js tf.train.adagrad() Function
TensorFlow.js Training Optimizers Complete Reference
Tensorflow.js tf.losses.absoluteDifference() Function
Tensorflow.js tf.losses.computeWeightedLoss() Function
Tensorflow.js tf.losses.cosineDistance() Function
TensorFlow.js Training Losses Complete Reference
Tensorflow.js tf.train.Optimizer Class
Tensorflow.js tf.train.Optimizer class .minimize() Method
TensorFlow.js Training Classes Complete Reference
Tensorflow.js tf.layers.zeroPadding2d() Function
Tensorflow.js tf.time() Function
Tensorflow.js tf.nextFrame() Function
Tensorflow.js tf.profile() Function
TensorFlow.js Performance Memory Complete Reference
Tensorflow.js tf.disposeVariables() Function
Tensorflow.js tf.enableDebugMode() Function
Tensorflow.js tf.enableProdMode() Function
Tensorflow.js tf.engine() FunctionTensorflow.js EnvironmentTensorFlow.js Environment Complete ReferenceTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.metrics.binaryAccuracy() FunctionTensorflow.js tf.metrics.binaryCrossentropy() FunctionTensorflow.js tf.metrics.categoricalAccuracy() FunctionTensorflow.js tf.metrics.categoricalCrossentropy() FunctionTensorflow.js tf.metrics.cosineProximity() FunctionTensorflow.js ConstraintsTensorflow.js tf.metrics.meanSquaredError() FunctionTensorflow.js tf.metrics.precision() FunctionTensorflow.js tf.metrics.recall() FunctionTensorflow.js tf.metrics.sparseCategoricalAccuracy() FunctionTensorFlow.js Metrics Complete ReferenceTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.initializers.Initializer ClassTensorflow.js tf.initializers.constant() MethodTensorflow.js tf.initializers.glorotNormal() FunctionTensorflow.js tf.initializers.glorotUniform() FunctionTensorflow.js tf.initializers.heNormal() FunctionTensorflow.js tf.initializers.heUniform() FunctionTensorflow.js InitializersTensorFlow.js Initializers Complete ReferenceTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.regularizers.l1() FunctionTensorflow.js tf.regularizers.l1l2() FunctionTensorflow.js tf.regularizers.l2() FunctionTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.data.csv() FunctionTensorflow.js tf.data.generator() FunctionTensorflow.js tf.data.microphone() FunctionTensorflow.js RegularizesTensorFlow.js Data Creation Complete ReferenceTensorflow.js tf.data.zip() FunctionTensorflow.js tf.data.Dataset class .batch() MethodTensorflow.js DataTensorFlow.js Data Classes Complete ReferencesTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.util.assert() FunctionTensorflow.js tf.util.createShuffledIndices() FunctionTensorflow.js tf.decodeString() FunctionTensorflow.js tf.encodeString() FunctionTensorflow.js tf.fetch() FunctionTensorflow.js tf.util.flatten() FunctionTensorflow.js tf.util.now() FunctionTensorflow.js tf.util.shuffle() FunctionTensorflow.js tf.util.shuffleCombo() FunctionTensorflow.js UtilTensorflow.js tf.browser.fromPixels() FunctionTensorflow.js tf.browser.fromPixelsAsync() FunctionTensorflow.js tf.browser.toPixels() FunctionTensorFlow.js Browser Complete ReferenceTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.backend() FunctionTensorflow.js tf.getBackend() FunctionTensorflow.js tf.ready() FunctionTensorflow.js tf.registerBackend() FunctionTensorflow.js tf.removeBackend() FunctionTensorflow.js tf.setBackend() FunctionTensorflow.js BrowserTensorflow.js tf.callbacks.earlyStopping() FunctionTensorflow.js BackendsTensorflow.js Metrics
TensorFlow.js Environment Complete Reference
Tensorflow.js tf.layers.zeroPadding2d() Function
Tensorflow.js tf.metrics.binaryAccuracy() Function
Tensorflow.js tf.metrics.binaryCrossentropy() Function
Tensorflow.js tf.metrics.categoricalAccuracy() Function
Tensorflow.js tf.metrics.categoricalCrossentropy() Function
Tensorflow.js tf.metrics.cosineProximity() Function
Tensorflow.js tf.metrics.meanSquaredError() Function
Tensorflow.js tf.metrics.precision() Function
Tensorflow.js tf.metrics.recall() Function
Tensorflow.js tf.metrics.sparseCategoricalAccuracy() Function
TensorFlow.js Metrics Complete Reference
Tensorflow.js tf.layers.zeroPadding2d() Function
Tensorflow.js tf.initializers.Initializer Class
Tensorflow.js tf.initializers.constant() Method
Tensorflow.js tf.initializers.glorotNormal() Function
Tensorflow.js tf.initializers.glorotUniform() Function
Tensorflow.js tf.initializers.heNormal() Function
Tensorflow.js tf.initializers.heUniform() Function
TensorFlow.js Initializers Complete Reference
Tensorflow.js tf.layers.zeroPadding2d() Function
Tensorflow.js tf.regularizers.l1() Function
Tensorflow.js tf.regularizers.l1l2() Function
Tensorflow.js tf.regularizers.l2() Function
Tensorflow.js tf.layers.zeroPadding2d() Function
Tensorflow.js tf.data.csv() Function
Tensorflow.js tf.data.generator() Function
Tensorflow.js tf.data.microphone() FunctionTensorflow.js RegularizesTensorFlow.js Data Creation Complete ReferenceTensorflow.js tf.data.zip() FunctionTensorflow.js tf.data.Dataset class .batch() MethodTensorflow.js DataTensorFlow.js Data Classes Complete ReferencesTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.util.assert() FunctionTensorflow.js tf.util.createShuffledIndices() FunctionTensorflow.js tf.decodeString() FunctionTensorflow.js tf.encodeString() FunctionTensorflow.js tf.fetch() FunctionTensorflow.js tf.util.flatten() FunctionTensorflow.js tf.util.now() FunctionTensorflow.js tf.util.shuffle() FunctionTensorflow.js tf.util.shuffleCombo() FunctionTensorflow.js UtilTensorflow.js tf.browser.fromPixels() FunctionTensorflow.js tf.browser.fromPixelsAsync() FunctionTensorflow.js tf.browser.toPixels() FunctionTensorFlow.js Browser Complete ReferenceTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.backend() FunctionTensorflow.js tf.getBackend() FunctionTensorflow.js tf.ready() FunctionTensorflow.js tf.registerBackend() FunctionTensorflow.js tf.removeBackend() FunctionTensorflow.js tf.setBackend() FunctionTensorflow.js BrowserTensorflow.js tf.callbacks.earlyStopping() FunctionTensorflow.js BackendsTensorflow.js Metrics
TensorFlow.js Data Creation Complete Reference
Tensorflow.js tf.data.zip() Function
Tensorflow.js tf.data.Dataset class .batch() Method
TensorFlow.js Data Classes Complete References
Tensorflow.js tf.layers.zeroPadding2d() Function
Tensorflow.js tf.util.assert() Function
Tensorflow.js tf.util.createShuffledIndices() Function
Tensorflow.js tf.decodeString() Function
Tensorflow.js tf.encodeString() Function
Tensorflow.js tf.fetch() Function
Tensorflow.js tf.util.flatten() Function
Tensorflow.js tf.util.now() Function
Tensorflow.js tf.util.shuffle() Function
Tensorflow.js tf.util.shuffleCombo() Function
Tensorflow.js tf.browser.fromPixels() Function
Tensorflow.js tf.browser.fromPixelsAsync() Function
Tensorflow.js tf.browser.toPixels() Function
TensorFlow.js Browser Complete Reference
Tensorflow.js tf.layers.zeroPadding2d() Function
Tensorflow.js tf.backend() Function
Tensorflow.js tf.getBackend() Function
Tensorflow.js tf.ready() Function
Tensorflow.js tf.registerBackend() Function
Tensorflow.js tf.removeBackend() Function
Tensorflow.js tf.setBackend() Function
Tensorflow.js tf.callbacks.earlyStopping() Function
TensorFlow.js
Tensorflow.js IntroductionTensorflow.js TensorsTensorflow.js tf.tensor() FunctionTensorflow.js tf.scalar() FunctionTenserFlow.js Tensors Creation Complete ReferenceTensorflow.js tf.Tensor class .buffer() MethodTensorflow.js tf.Tensor class .bufferSync() MethodTensorFlow.js Tensors Classes Complete ReferenceTensorflow.js tf.booleanMaskAsync() FunctionTensorflow.js tf.concat() FunctionTensorFlow.js Tensors Transformations Complete ReferenceTensorFlow.js Slicing and Joining Complete ReferenceTensorflow.js tf.einsum() FunctionTensorflow.js tf.multinomial() FunctionTensorFlow.js Tensor Random Complete ReferenceTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js ModelsTensorflow.js tf.input() FunctionTensorflow.js tf.loadGraphModel() FunctionTensorflow.js tf.io.http() FunctionTensorFlow.js Models Loading Complete ReferenceTensorflow.js tf.io.copyModel() FunctionTensorflow.js tf.io.listModels() FunctionTensorflow.js tf.io.moveModel() FunctionTensorFlow.js Models Management Complete ReferenceTensorflow.js tf.GraphModel ClassTensorflow.js tf.GraphModel class .save() MethodTensorflow.js tf.GraphModel class .predict() MethodTensorflow.js tf.GraphModel class .execute() MethodTensorFlow.js Models Classes Complete ReferenceTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.layers.elu() FunctionTensorflow.js LayersTensorflow.js tf.layers.activation() FunctionTensorFlow.js Layers Basic Complete ReferenceTensorflow.js tf.layers.conv1d() FunctionTensorFlow.js Layers Convolutional Complete ReferenceTensorflow.js tf.layers.add() FunctionTensorFlow.js Layers Merge Complete ReferenceTensorflow.js tf.layers.globalAveragePooling1d() FunctionTensorFlow.js Layers Pooling Complete ReferenceTensorFlow.js Layers Noise Complete ReferenceTensorflow.js tf.layers.bidirectional() FunctionTensorflow.js tf.layers.timeDistributed() FunctionTensorFlow.js Layers Classes Complete ReferenceTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.layers.masking() FunctionTensorflow.js tf.layers.zeroPadding2d() FunctionTensorFlow.js Operations Arithmetic Complete ReferenceTensorFlow.js Operations Basic Math Complete ReferenceTensorFlow.js Operations Matrices Complete ReferenceTensorflow.js OperationsTensorFlow.js Operations Normalization Complete ReferenceTensorFlow.js Operations Images Complete ReferenceTensorFlow.js Operations Logical Complete ReferenceTensorFlow.js Operations Evaluation Complete ReferenceTensorflow.js tf.cumsum() FunctionTensorFlow.js Operations Slicing and Joining Complete ReferenceTensorFlow.js Operations Spectral Complete ReferenceTensorflow.js tf.unsortedSegmentSum() FunctionTensorflow.js tf.movingAverage() FunctionTensorflow.js tf.dropout() FunctionTensorFlow.js Operations Signal Complete ReferenceTensorflow.js tf.linalg.bandPart() FunctionTensorflow.js tf.linalg.gramSchmidt() FunctionTensorflow.js tf.linalg.qr() FunctionTensorFlow.js Operations Sparse Complete ReferenceTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.grad() FunctionTensorflow.js tf.grads() FunctionTensorflow.js tf.customGrad() FunctionTensorFlow.js Training Gradients Complete ReferenceTensorflow.js TrainingTensorflow.js tf.train.momentum() FunctionTensorflow.js tf.train.adagrad() FunctionTensorFlow.js Training Optimizers Complete ReferenceTensorflow.js tf.losses.absoluteDifference() FunctionTensorflow.js tf.losses.computeWeightedLoss() FunctionTensorflow.js tf.losses.cosineDistance() FunctionTensorFlow.js Training Losses Complete ReferenceTensorflow.js tf.train.Optimizer ClassTensorflow.js tf.train.Optimizer class .minimize() MethodTensorFlow.js Training Classes Complete ReferenceTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.time() FunctionTensorflow.js tf.nextFrame() FunctionTensorflow.js tf.profile() FunctionTensorFlow.js Performance Memory Complete ReferenceTensorflow.js PerformanceTensorflow.js tf.disposeVariables() FunctionTensorflow.js tf.enableDebugMode() FunctionTensorflow.js tf.enableProdMode() FunctionTensorflow.js tf.engine() FunctionTensorflow.js EnvironmentTensorFlow.js Environment Complete ReferenceTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.metrics.binaryAccuracy() FunctionTensorflow.js tf.metrics.binaryCrossentropy() FunctionTensorflow.js tf.metrics.categoricalAccuracy() FunctionTensorflow.js tf.metrics.categoricalCrossentropy() FunctionTensorflow.js tf.metrics.cosineProximity() FunctionTensorflow.js ConstraintsTensorflow.js tf.metrics.meanSquaredError() FunctionTensorflow.js tf.metrics.precision() FunctionTensorflow.js tf.metrics.recall() FunctionTensorflow.js tf.metrics.sparseCategoricalAccuracy() FunctionTensorFlow.js Metrics Complete ReferenceTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.initializers.Initializer ClassTensorflow.js tf.initializers.constant() MethodTensorflow.js tf.initializers.glorotNormal() FunctionTensorflow.js tf.initializers.glorotUniform() FunctionTensorflow.js tf.initializers.heNormal() FunctionTensorflow.js tf.initializers.heUniform() FunctionTensorflow.js InitializersTensorFlow.js Initializers Complete ReferenceTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.regularizers.l1() FunctionTensorflow.js tf.regularizers.l1l2() FunctionTensorflow.js tf.regularizers.l2() FunctionTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.data.csv() FunctionTensorflow.js tf.data.generator() FunctionTensorflow.js tf.data.microphone() FunctionTensorflow.js RegularizesTensorFlow.js Data Creation Complete ReferenceTensorflow.js tf.data.zip() FunctionTensorflow.js tf.data.Dataset class .batch() MethodTensorflow.js DataTensorFlow.js Data Classes Complete ReferencesTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.util.assert() FunctionTensorflow.js tf.util.createShuffledIndices() FunctionTensorflow.js tf.decodeString() FunctionTensorflow.js tf.encodeString() FunctionTensorflow.js tf.fetch() FunctionTensorflow.js tf.util.flatten() FunctionTensorflow.js tf.util.now() FunctionTensorflow.js tf.util.shuffle() FunctionTensorflow.js tf.util.shuffleCombo() FunctionTensorflow.js UtilTensorflow.js tf.browser.fromPixels() FunctionTensorflow.js tf.browser.fromPixelsAsync() FunctionTensorflow.js tf.browser.toPixels() FunctionTensorFlow.js Browser Complete ReferenceTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.backend() FunctionTensorflow.js tf.getBackend() FunctionTensorflow.js tf.ready() FunctionTensorflow.js tf.registerBackend() FunctionTensorflow.js tf.removeBackend() FunctionTensorflow.js tf.setBackend() FunctionTensorflow.js BrowserTensorflow.js tf.callbacks.earlyStopping() FunctionTensorflow.js BackendsTensorflow.js MetricsImprove Article

Save Article

Like Article

Tensorflow.js tf.layers.zeroPadding2d() FunctionLast Updated :
17 Feb, 2022Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment.The tf.layers.zeroPadding2d( ) function is used for adding rows and columns for zeros at the top, bottom, left, and right side of and image tensor.Syntax: tf.layers.zeroPadding2d(args); Parameters: This method accepts the args as a parameter which has the following properties:Padding: This variable accepts an integer, or an Array of 2 integers, or Array of 2 Arrays, each of which is an array of 2 integers. Interpretation of this variable is:If a variable is an integer, the same symmetric is applied to width and height.If a variable is an array of 2 integers, interpreted as two different symmetric values of height and width.If a variable is an array of 2 arrays, interpreted as topPad, bottomPad for the first array, and leftPad, rightPad for the second array.dataFormat: This variable define the format of the shape of the input Tensor. If can be  channelsLast or  channelsFirst. This value defines the ordering of the dimensions in the inputs. The channelsLast define shape [ batch, height, width, channels] while channelsFirst define [ batch, channels, height, width].inputShape: It can be null or an array of numbers. It is used to create an input layer to insert before the following layer. This variable is only used for the first layer of a model.batchInputShape: This variable accept null or array of number. This variable works the same as inputShape but If both inputShape and batchInputShape are defined, batchInputShape is used. This variable is only used for the first layer of a model.batchSize: It is a number, and It helps batchInputShape variable. if batchInputShape is not defined it is used for creating batchInputShape.dtype: This variable is used for defining data type for the padding layer. It is Default to ‘float32’. This variable is only used for first layer of a model.name: It defined the name of layer.trainable: It is a boolean type. It defined layer data are updatable by fit or not. Defaults value is true.weights: It is tf.Tensor type. It declares the Initial weight values of the layer.inputDType: It defines the data type of the input layer. Legacy support. Do not use for new code.Returns: It returns ZeroPadding2D object.Example 1: In this example, we add a zero-padding layer with default values.JavascriptJavascript// Importing tensorflowconst tf = require("@tensorflow/tfjs") // Input 4d Tensor    const img4d = tf.tensor4d([1, 2, 3, 4], [1, 2, 2, 1]); // Adding padding in Tensorconst pad = tf.layers.zeroPadding2d();const imgpad = pad.apply(img4d); // Printing 4d Tensor with padding</div>imgpad.print()  Output: Tensor    [[[[0], [0], [0], [0]],
            [[0], [1], [2], [0]],
            [[0], [3], [4], [0]],
            [[0], [0], [0], [0]]]]Example 2: In this example, we add zero paddings in tensor of specific data type and with define data-Format. JavascriptJavascript// Importing tensorflowconst tf = require("@tensorflow/tfjs") // Input 4d Tensor    const img4d = tf.tensor4d([1, 2, 3, 4], [1, 2, 2, 1]); // Adding padding in Tensorconst pad = tf.layers.zeroPadding2d({    padding: 2,    dataFormat: 'channelsFirst', dtype: 'int32'}); const imgpad = pad.apply(img4d); // Printing 4d Tensor with paddingimgpad.print()  Output:  Tensor
    [[[[0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0],
       [0, 0, 1, 0, 0],
       [0, 0, 2, 0, 0],
       [0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0]],

      [[0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0],
       [0, 0, 3, 0, 0],
       [0, 0, 4, 0, 0],
       [0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0]]]] Reference: https://js.tensorflow.org/api/latest/#layers.zeroPadding2d My Personal Notes
arrow_drop_upSave

Like2PreviousTensorFlow.js Browser Complete ReferenceNext
Tensorflow.js tf.backend() FunctionRecommended ArticlesPage :How to get the function name from within that function using JavaScript ?30, May 19How to call a function that return another function in JavaScript ?24, Jul 19How to get the function name inside a function in PHP ?25, Sep 19Python - Call function from another function04, Dec 19How to Check a Function is a Generator Function or not using JavaScript ?26, Mar 20How to implement a function that enable another function after specified time using JavaScript ?10, Mar 21How to create a function that invokes the provided function with its arguments transformed in JavaScript?18, Jul 21How to create a function that invokes each provided function with the arguments it receives using JavaScript ?25, May 21How to create a function that invokes function with partials prepended arguments in JavaScript ?26, Jul 21Difference between ‘function declaration’ and ‘function expression' in JavaScript20, Sep 21Find the power function that the graph of f resembles for large values of |x|, given the function f(x) = (x + 6)2 (x - 2)210, Oct 21Difference between Function.prototype.apply and Function.prototype.call16, Nov 21Explain the differences on the usage of foo between function foo() {} and var foo = function() {}02, Mar 22How does TypeScript support optional parameters in function as every parameter is optional for a function in JavaScript ?24, Mar 22What are the advantages of synchronous function over asynchronous function in Node.js ?28, Mar 22How to create a function that invokes function with partials appended to the arguments in JavaScript ?28, May 21PHP | imagecreatetruecolor() Function18, Sep 18p5.js | year() function07, Apr 19D3.js | d3.utcTuesdays() Function24, Jul 19PHP | ImagickDraw getTextAlignment() Function16, Dec 19PHP | Ds\Sequence last() Function24, Jan 19PHP | Imagick floodFillPaintImage() Function30, Jul 19Function to escape regex patterns before applied in PHP31, Oct 19PHP | array_udiff_uassoc() Function11, Jul 18Article Contributed By :satyam00so@satyam00soVote for difficultyEasy
Normal
Medium
Hard
ExpertImproved By :anikakapooradnanirshad158germanshephered48Article Tags :PickedTensorflow.jsJavaScriptWeb TechnologiesImprove ArticleReport IssueWriting code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Load CommentsWhat's NewInterview Series- Prepare, Practice & UpskillView DetailsData Structures & Algorithms- Self Paced CourseView DetailsComplete Interview PreparationView DetailsMost popular in JavaScriptRemove elements from a JavaScript ArrayConvert a string to an integer in JavaScriptDifference between var, let and const keywords in JavaScriptHow to calculate the number of days between two dates in javascript?Differences between Functional Components and Class Components in ReactMost visited in Web TechnologiesRemove elements from a JavaScript ArrayInstallation of Node.js on LinuxConvert a string to an integer in JavaScriptHow to fetch data from an API in ReactJS ?How to insert spaces/tabs in text using HTML/CSS?
Tensorflow.js tf.tensor() Function
Tensorflow.js tf.scalar() Function
TenserFlow.js Tensors Creation Complete Reference
Tensorflow.js tf.Tensor class .buffer() Method
Tensorflow.js tf.Tensor class .bufferSync() Method
TensorFlow.js Tensors Classes Complete Reference
Tensorflow.js tf.booleanMaskAsync() Function
Tensorflow.js tf.concat() Function
TensorFlow.js Tensors Transformations Complete Reference
TensorFlow.js Slicing and Joining Complete Reference
Tensorflow.js tf.einsum() Function
Tensorflow.js tf.multinomial() Function
TensorFlow.js Tensor Random Complete Reference
Tensorflow.js tf.layers.zeroPadding2d() Function
Tensorflow.js tf.input() Function
Tensorflow.js tf.loadGraphModel() Function
Tensorflow.js tf.io.http() Function
TensorFlow.js Models Loading Complete Reference
Tensorflow.js tf.io.copyModel() Function
Tensorflow.js tf.io.listModels() Function
Tensorflow.js tf.io.moveModel() Function
TensorFlow.js Models Management Complete Reference
Tensorflow.js tf.GraphModel Class
Tensorflow.js tf.GraphModel class .save() Method
Tensorflow.js tf.GraphModel class .predict() Method
Tensorflow.js tf.GraphModel class .execute() Method
TensorFlow.js Models Classes Complete Reference
Tensorflow.js tf.layers.zeroPadding2d() Function
Tensorflow.js tf.layers.elu() Function
Tensorflow.js tf.layers.activation() Function
TensorFlow.js Layers Basic Complete Reference
Tensorflow.js tf.layers.conv1d() Function
TensorFlow.js Layers Convolutional Complete Reference
Tensorflow.js tf.layers.add() Function
TensorFlow.js Layers Merge Complete Reference
Tensorflow.js tf.layers.globalAveragePooling1d() Function
TensorFlow.js Layers Pooling Complete Reference
TensorFlow.js Layers Noise Complete Reference
Tensorflow.js tf.layers.bidirectional() Function
Tensorflow.js tf.layers.timeDistributed() Function
TensorFlow.js Layers Classes Complete Reference
Tensorflow.js tf.layers.zeroPadding2d() Function
Tensorflow.js tf.layers.masking() Function
Tensorflow.js tf.layers.zeroPadding2d() Function
TensorFlow.js Operations Arithmetic Complete Reference
TensorFlow.js Operations Basic Math Complete Reference
TensorFlow.js Operations Matrices Complete Reference
TensorFlow.js Operations Normalization Complete Reference
TensorFlow.js Operations Images Complete Reference
TensorFlow.js Operations Logical Complete Reference
TensorFlow.js Operations Evaluation Complete Reference
Tensorflow.js tf.cumsum() Function
TensorFlow.js Operations Slicing and Joining Complete Reference
TensorFlow.js Operations Spectral Complete Reference
Tensorflow.js tf.unsortedSegmentSum() Function
Tensorflow.js tf.movingAverage() Function
Tensorflow.js tf.dropout() Function
TensorFlow.js Operations Signal Complete Reference
Tensorflow.js tf.linalg.bandPart() Function
Tensorflow.js tf.linalg.gramSchmidt() Function
Tensorflow.js tf.linalg.qr() Function
TensorFlow.js Operations Sparse Complete Reference
Tensorflow.js tf.layers.zeroPadding2d() Function
Tensorflow.js tf.grad() Function
Tensorflow.js tf.grads() Function
Tensorflow.js tf.customGrad() Function
TensorFlow.js Training Gradients Complete ReferenceTensorflow.js TrainingTensorflow.js tf.train.momentum() FunctionTensorflow.js tf.train.adagrad() FunctionTensorFlow.js Training Optimizers Complete ReferenceTensorflow.js tf.losses.absoluteDifference() FunctionTensorflow.js tf.losses.computeWeightedLoss() FunctionTensorflow.js tf.losses.cosineDistance() FunctionTensorFlow.js Training Losses Complete ReferenceTensorflow.js tf.train.Optimizer ClassTensorflow.js tf.train.Optimizer class .minimize() MethodTensorFlow.js Training Classes Complete ReferenceTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.time() FunctionTensorflow.js tf.nextFrame() FunctionTensorflow.js tf.profile() FunctionTensorFlow.js Performance Memory Complete ReferenceTensorflow.js PerformanceTensorflow.js tf.disposeVariables() FunctionTensorflow.js tf.enableDebugMode() FunctionTensorflow.js tf.enableProdMode() FunctionTensorflow.js tf.engine() FunctionTensorflow.js EnvironmentTensorFlow.js Environment Complete ReferenceTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.metrics.binaryAccuracy() FunctionTensorflow.js tf.metrics.binaryCrossentropy() FunctionTensorflow.js tf.metrics.categoricalAccuracy() FunctionTensorflow.js tf.metrics.categoricalCrossentropy() FunctionTensorflow.js tf.metrics.cosineProximity() FunctionTensorflow.js ConstraintsTensorflow.js tf.metrics.meanSquaredError() FunctionTensorflow.js tf.metrics.precision() FunctionTensorflow.js tf.metrics.recall() FunctionTensorflow.js tf.metrics.sparseCategoricalAccuracy() FunctionTensorFlow.js Metrics Complete ReferenceTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.initializers.Initializer ClassTensorflow.js tf.initializers.constant() MethodTensorflow.js tf.initializers.glorotNormal() FunctionTensorflow.js tf.initializers.glorotUniform() FunctionTensorflow.js tf.initializers.heNormal() FunctionTensorflow.js tf.initializers.heUniform() FunctionTensorflow.js InitializersTensorFlow.js Initializers Complete ReferenceTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.regularizers.l1() FunctionTensorflow.js tf.regularizers.l1l2() FunctionTensorflow.js tf.regularizers.l2() FunctionTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.data.csv() FunctionTensorflow.js tf.data.generator() FunctionTensorflow.js tf.data.microphone() FunctionTensorflow.js RegularizesTensorFlow.js Data Creation Complete ReferenceTensorflow.js tf.data.zip() FunctionTensorflow.js tf.data.Dataset class .batch() MethodTensorflow.js DataTensorFlow.js Data Classes Complete ReferencesTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.util.assert() FunctionTensorflow.js tf.util.createShuffledIndices() FunctionTensorflow.js tf.decodeString() FunctionTensorflow.js tf.encodeString() FunctionTensorflow.js tf.fetch() FunctionTensorflow.js tf.util.flatten() FunctionTensorflow.js tf.util.now() FunctionTensorflow.js tf.util.shuffle() FunctionTensorflow.js tf.util.shuffleCombo() FunctionTensorflow.js UtilTensorflow.js tf.browser.fromPixels() FunctionTensorflow.js tf.browser.fromPixelsAsync() FunctionTensorflow.js tf.browser.toPixels() FunctionTensorFlow.js Browser Complete ReferenceTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.backend() FunctionTensorflow.js tf.getBackend() FunctionTensorflow.js tf.ready() FunctionTensorflow.js tf.registerBackend() FunctionTensorflow.js tf.removeBackend() FunctionTensorflow.js tf.setBackend() FunctionTensorflow.js BrowserTensorflow.js tf.callbacks.earlyStopping() FunctionTensorflow.js BackendsTensorflow.js MetricsImprove Article

Save Article

Like Article

Tensorflow.js tf.layers.zeroPadding2d() FunctionLast Updated :
17 Feb, 2022Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment.The tf.layers.zeroPadding2d( ) function is used for adding rows and columns for zeros at the top, bottom, left, and right side of and image tensor.Syntax: tf.layers.zeroPadding2d(args); Parameters: This method accepts the args as a parameter which has the following properties:Padding: This variable accepts an integer, or an Array of 2 integers, or Array of 2 Arrays, each of which is an array of 2 integers. Interpretation of this variable is:If a variable is an integer, the same symmetric is applied to width and height.If a variable is an array of 2 integers, interpreted as two different symmetric values of height and width.If a variable is an array of 2 arrays, interpreted as topPad, bottomPad for the first array, and leftPad, rightPad for the second array.dataFormat: This variable define the format of the shape of the input Tensor. If can be  channelsLast or  channelsFirst. This value defines the ordering of the dimensions in the inputs. The channelsLast define shape [ batch, height, width, channels] while channelsFirst define [ batch, channels, height, width].inputShape: It can be null or an array of numbers. It is used to create an input layer to insert before the following layer. This variable is only used for the first layer of a model.batchInputShape: This variable accept null or array of number. This variable works the same as inputShape but If both inputShape and batchInputShape are defined, batchInputShape is used. This variable is only used for the first layer of a model.batchSize: It is a number, and It helps batchInputShape variable. if batchInputShape is not defined it is used for creating batchInputShape.dtype: This variable is used for defining data type for the padding layer. It is Default to ‘float32’. This variable is only used for first layer of a model.name: It defined the name of layer.trainable: It is a boolean type. It defined layer data are updatable by fit or not. Defaults value is true.weights: It is tf.Tensor type. It declares the Initial weight values of the layer.inputDType: It defines the data type of the input layer. Legacy support. Do not use for new code.Returns: It returns ZeroPadding2D object.Example 1: In this example, we add a zero-padding layer with default values.JavascriptJavascript// Importing tensorflowconst tf = require("@tensorflow/tfjs") // Input 4d Tensor    const img4d = tf.tensor4d([1, 2, 3, 4], [1, 2, 2, 1]); // Adding padding in Tensorconst pad = tf.layers.zeroPadding2d();const imgpad = pad.apply(img4d); // Printing 4d Tensor with padding</div>imgpad.print()  Output: Tensor    [[[[0], [0], [0], [0]],
            [[0], [1], [2], [0]],
            [[0], [3], [4], [0]],
            [[0], [0], [0], [0]]]]Example 2: In this example, we add zero paddings in tensor of specific data type and with define data-Format. JavascriptJavascript// Importing tensorflowconst tf = require("@tensorflow/tfjs") // Input 4d Tensor    const img4d = tf.tensor4d([1, 2, 3, 4], [1, 2, 2, 1]); // Adding padding in Tensorconst pad = tf.layers.zeroPadding2d({    padding: 2,    dataFormat: 'channelsFirst', dtype: 'int32'}); const imgpad = pad.apply(img4d); // Printing 4d Tensor with paddingimgpad.print()  Output:  Tensor
    [[[[0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0],
       [0, 0, 1, 0, 0],
       [0, 0, 2, 0, 0],
       [0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0]],

      [[0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0],
       [0, 0, 3, 0, 0],
       [0, 0, 4, 0, 0],
       [0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0]]]] Reference: https://js.tensorflow.org/api/latest/#layers.zeroPadding2d My Personal Notes
arrow_drop_upSave

Like2PreviousTensorFlow.js Browser Complete ReferenceNext
Tensorflow.js tf.backend() FunctionRecommended ArticlesPage :How to get the function name from within that function using JavaScript ?30, May 19How to call a function that return another function in JavaScript ?24, Jul 19How to get the function name inside a function in PHP ?25, Sep 19Python - Call function from another function04, Dec 19How to Check a Function is a Generator Function or not using JavaScript ?26, Mar 20How to implement a function that enable another function after specified time using JavaScript ?10, Mar 21How to create a function that invokes the provided function with its arguments transformed in JavaScript?18, Jul 21How to create a function that invokes each provided function with the arguments it receives using JavaScript ?25, May 21How to create a function that invokes function with partials prepended arguments in JavaScript ?26, Jul 21Difference between ‘function declaration’ and ‘function expression' in JavaScript20, Sep 21Find the power function that the graph of f resembles for large values of |x|, given the function f(x) = (x + 6)2 (x - 2)210, Oct 21Difference between Function.prototype.apply and Function.prototype.call16, Nov 21Explain the differences on the usage of foo between function foo() {} and var foo = function() {}02, Mar 22How does TypeScript support optional parameters in function as every parameter is optional for a function in JavaScript ?24, Mar 22What are the advantages of synchronous function over asynchronous function in Node.js ?28, Mar 22How to create a function that invokes function with partials appended to the arguments in JavaScript ?28, May 21PHP | imagecreatetruecolor() Function18, Sep 18p5.js | year() function07, Apr 19D3.js | d3.utcTuesdays() Function24, Jul 19PHP | ImagickDraw getTextAlignment() Function16, Dec 19PHP | Ds\Sequence last() Function24, Jan 19PHP | Imagick floodFillPaintImage() Function30, Jul 19Function to escape regex patterns before applied in PHP31, Oct 19PHP | array_udiff_uassoc() Function11, Jul 18Article Contributed By :satyam00so@satyam00soVote for difficultyEasy
Normal
Medium
Hard
ExpertImproved By :anikakapooradnanirshad158germanshephered48Article Tags :PickedTensorflow.jsJavaScriptWeb TechnologiesImprove ArticleReport IssueWriting code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Load CommentsWhat's NewInterview Series- Prepare, Practice & UpskillView DetailsData Structures & Algorithms- Self Paced CourseView DetailsComplete Interview PreparationView DetailsMost popular in JavaScriptRemove elements from a JavaScript ArrayConvert a string to an integer in JavaScriptDifference between var, let and const keywords in JavaScriptHow to calculate the number of days between two dates in javascript?Differences between Functional Components and Class Components in ReactMost visited in Web TechnologiesRemove elements from a JavaScript ArrayInstallation of Node.js on LinuxConvert a string to an integer in JavaScriptHow to fetch data from an API in ReactJS ?How to insert spaces/tabs in text using HTML/CSS?
Tensorflow.js tf.train.momentum() Function
Tensorflow.js tf.train.adagrad() Function
TensorFlow.js Training Optimizers Complete Reference
Tensorflow.js tf.losses.absoluteDifference() Function
Tensorflow.js tf.losses.computeWeightedLoss() Function
Tensorflow.js tf.losses.cosineDistance() Function
TensorFlow.js Training Losses Complete Reference
Tensorflow.js tf.train.Optimizer Class
Tensorflow.js tf.train.Optimizer class .minimize() Method
TensorFlow.js Training Classes Complete Reference
Tensorflow.js tf.layers.zeroPadding2d() Function
Tensorflow.js tf.time() Function
Tensorflow.js tf.nextFrame() Function
Tensorflow.js tf.profile() Function
TensorFlow.js Performance Memory Complete Reference
Tensorflow.js tf.disposeVariables() Function
Tensorflow.js tf.enableDebugMode() Function
Tensorflow.js tf.enableProdMode() Function
Tensorflow.js tf.engine() FunctionTensorflow.js EnvironmentTensorFlow.js Environment Complete ReferenceTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.metrics.binaryAccuracy() FunctionTensorflow.js tf.metrics.binaryCrossentropy() FunctionTensorflow.js tf.metrics.categoricalAccuracy() FunctionTensorflow.js tf.metrics.categoricalCrossentropy() FunctionTensorflow.js tf.metrics.cosineProximity() FunctionTensorflow.js ConstraintsTensorflow.js tf.metrics.meanSquaredError() FunctionTensorflow.js tf.metrics.precision() FunctionTensorflow.js tf.metrics.recall() FunctionTensorflow.js tf.metrics.sparseCategoricalAccuracy() FunctionTensorFlow.js Metrics Complete ReferenceTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.initializers.Initializer ClassTensorflow.js tf.initializers.constant() MethodTensorflow.js tf.initializers.glorotNormal() FunctionTensorflow.js tf.initializers.glorotUniform() FunctionTensorflow.js tf.initializers.heNormal() FunctionTensorflow.js tf.initializers.heUniform() FunctionTensorflow.js InitializersTensorFlow.js Initializers Complete ReferenceTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.regularizers.l1() FunctionTensorflow.js tf.regularizers.l1l2() FunctionTensorflow.js tf.regularizers.l2() FunctionTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.data.csv() FunctionTensorflow.js tf.data.generator() FunctionTensorflow.js tf.data.microphone() FunctionTensorflow.js RegularizesTensorFlow.js Data Creation Complete ReferenceTensorflow.js tf.data.zip() FunctionTensorflow.js tf.data.Dataset class .batch() MethodTensorflow.js DataTensorFlow.js Data Classes Complete ReferencesTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.util.assert() FunctionTensorflow.js tf.util.createShuffledIndices() FunctionTensorflow.js tf.decodeString() FunctionTensorflow.js tf.encodeString() FunctionTensorflow.js tf.fetch() FunctionTensorflow.js tf.util.flatten() FunctionTensorflow.js tf.util.now() FunctionTensorflow.js tf.util.shuffle() FunctionTensorflow.js tf.util.shuffleCombo() FunctionTensorflow.js UtilTensorflow.js tf.browser.fromPixels() FunctionTensorflow.js tf.browser.fromPixelsAsync() FunctionTensorflow.js tf.browser.toPixels() FunctionTensorFlow.js Browser Complete ReferenceTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.backend() FunctionTensorflow.js tf.getBackend() FunctionTensorflow.js tf.ready() FunctionTensorflow.js tf.registerBackend() FunctionTensorflow.js tf.removeBackend() FunctionTensorflow.js tf.setBackend() FunctionTensorflow.js BrowserTensorflow.js tf.callbacks.earlyStopping() FunctionTensorflow.js BackendsTensorflow.js Metrics
TensorFlow.js Environment Complete Reference
Tensorflow.js tf.layers.zeroPadding2d() Function
Tensorflow.js tf.metrics.binaryAccuracy() Function
Tensorflow.js tf.metrics.binaryCrossentropy() Function
Tensorflow.js tf.metrics.categoricalAccuracy() Function
Tensorflow.js tf.metrics.categoricalCrossentropy() Function
Tensorflow.js tf.metrics.cosineProximity() Function
Tensorflow.js tf.metrics.meanSquaredError() Function
Tensorflow.js tf.metrics.precision() Function
Tensorflow.js tf.metrics.recall() Function
Tensorflow.js tf.metrics.sparseCategoricalAccuracy() Function
TensorFlow.js Metrics Complete Reference
Tensorflow.js tf.layers.zeroPadding2d() Function
Tensorflow.js tf.initializers.Initializer Class
Tensorflow.js tf.initializers.constant() Method
Tensorflow.js tf.initializers.glorotNormal() Function
Tensorflow.js tf.initializers.glorotUniform() Function
Tensorflow.js tf.initializers.heNormal() Function
Tensorflow.js tf.initializers.heUniform() Function
TensorFlow.js Initializers Complete Reference
Tensorflow.js tf.layers.zeroPadding2d() Function
Tensorflow.js tf.regularizers.l1() Function
Tensorflow.js tf.regularizers.l1l2() Function
Tensorflow.js tf.regularizers.l2() Function
Tensorflow.js tf.layers.zeroPadding2d() Function
Tensorflow.js tf.data.csv() Function
Tensorflow.js tf.data.generator() Function
Tensorflow.js tf.data.microphone() FunctionTensorflow.js RegularizesTensorFlow.js Data Creation Complete ReferenceTensorflow.js tf.data.zip() FunctionTensorflow.js tf.data.Dataset class .batch() MethodTensorflow.js DataTensorFlow.js Data Classes Complete ReferencesTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.util.assert() FunctionTensorflow.js tf.util.createShuffledIndices() FunctionTensorflow.js tf.decodeString() FunctionTensorflow.js tf.encodeString() FunctionTensorflow.js tf.fetch() FunctionTensorflow.js tf.util.flatten() FunctionTensorflow.js tf.util.now() FunctionTensorflow.js tf.util.shuffle() FunctionTensorflow.js tf.util.shuffleCombo() FunctionTensorflow.js UtilTensorflow.js tf.browser.fromPixels() FunctionTensorflow.js tf.browser.fromPixelsAsync() FunctionTensorflow.js tf.browser.toPixels() FunctionTensorFlow.js Browser Complete ReferenceTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.backend() FunctionTensorflow.js tf.getBackend() FunctionTensorflow.js tf.ready() FunctionTensorflow.js tf.registerBackend() FunctionTensorflow.js tf.removeBackend() FunctionTensorflow.js tf.setBackend() FunctionTensorflow.js BrowserTensorflow.js tf.callbacks.earlyStopping() FunctionTensorflow.js BackendsTensorflow.js Metrics
TensorFlow.js Data Creation Complete Reference
Tensorflow.js tf.data.zip() Function
Tensorflow.js tf.data.Dataset class .batch() Method
TensorFlow.js Data Classes Complete References
Tensorflow.js tf.layers.zeroPadding2d() Function
Tensorflow.js tf.util.assert() Function
Tensorflow.js tf.util.createShuffledIndices() Function
Tensorflow.js tf.decodeString() Function
Tensorflow.js tf.encodeString() Function
Tensorflow.js tf.fetch() Function
Tensorflow.js tf.util.flatten() Function
Tensorflow.js tf.util.now() Function
Tensorflow.js tf.util.shuffle() Function
Tensorflow.js tf.util.shuffleCombo() Function
Tensorflow.js tf.browser.fromPixels() Function
Tensorflow.js tf.browser.fromPixelsAsync() Function
Tensorflow.js tf.browser.toPixels() Function
TensorFlow.js Browser Complete Reference
Tensorflow.js tf.layers.zeroPadding2d() Function
Tensorflow.js tf.backend() Function
Tensorflow.js tf.getBackend() Function
Tensorflow.js tf.ready() Function
Tensorflow.js tf.registerBackend() Function
Tensorflow.js tf.removeBackend() Function
Tensorflow.js tf.setBackend() Function
Tensorflow.js tf.callbacks.earlyStopping() Function
Last Updated :
17 Feb, 2022
Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment.
The tf.layers.zeroPadding2d( ) function is used for adding rows and columns for zeros at the top, bottom, left, and right side of and image tensor.
Syntax: 
tf.layers.zeroPadding2d(args);
 Parameters: This method accepts the args as a parameter which has the following properties:
Padding: This variable accepts an integer, or an Array of 2 integers, or Array of 2 Arrays, each of which is an array of 2 integers. Interpretation of this variable is:If a variable is an integer, the same symmetric is applied to width and height.If a variable is an array of 2 integers, interpreted as two different symmetric values of height and width.If a variable is an array of 2 arrays, interpreted as topPad, bottomPad for the first array, and leftPad, rightPad for the second array.
If a variable is an integer, the same symmetric is applied to width and height.
If a variable is an array of 2 integers, interpreted as two different symmetric values of height and width.
If a variable is an array of 2 arrays, interpreted as topPad, bottomPad for the first array, and leftPad, rightPad for the second array.
dataFormat: This variable define the format of the shape of the input Tensor. If can be  channelsLast or  channelsFirst. This value defines the ordering of the dimensions in the inputs. The channelsLast define shape [ batch, height, width, channels] while channelsFirst define [ batch, channels, height, width].
inputShape: It can be null or an array of numbers. It is used to create an input layer to insert before the following layer. This variable is only used for the first layer of a model.
batchInputShape: This variable accept null or array of number. This variable works the same as inputShape but If both inputShape and batchInputShape are defined, batchInputShape is used. This variable is only used for the first layer of a model.
batchSize: It is a number, and It helps batchInputShape variable. if batchInputShape is not defined it is used for creating batchInputShape.
dtype: This variable is used for defining data type for the padding layer. It is Default to ‘float32’. This variable is only used for first layer of a model.
name: It defined the name of layer.
trainable: It is a boolean type. It defined layer data are updatable by fit or not. Defaults value is true.
weights: It is tf.Tensor type. It declares the Initial weight values of the layer.
inputDType: It defines the data type of the input layer. Legacy support. Do not use for new code.
Returns: It returns ZeroPadding2D object.
Example 1: In this example, we add a zero-padding layer with default values.
Javascript
// Importing tensorflowconst tf = require("@tensorflow/tfjs") // Input 4d Tensor    const img4d = tf.tensor4d([1, 2, 3, 4], [1, 2, 2, 1]); // Adding padding in Tensorconst pad = tf.layers.zeroPadding2d();const imgpad = pad.apply(img4d); // Printing 4d Tensor with padding</div>imgpad.print()
  
Output:
 
Tensor    [[[[0], [0], [0], [0]],
            [[0], [1], [2], [0]],
            [[0], [3], [4], [0]],
            [[0], [0], [0], [0]]]]
Example 2: In this example, we add zero paddings in tensor of specific data type and with define data-Format.
 
Javascript
// Importing tensorflowconst tf = require("@tensorflow/tfjs") // Input 4d Tensor    const img4d = tf.tensor4d([1, 2, 3, 4], [1, 2, 2, 1]); // Adding padding in Tensorconst pad = tf.layers.zeroPadding2d({    padding: 2,    dataFormat: 'channelsFirst', dtype: 'int32'}); const imgpad = pad.apply(img4d); // Printing 4d Tensor with paddingimgpad.print()
  
Output: 
 
Tensor
    [[[[0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0],
       [0, 0, 1, 0, 0],
       [0, 0, 2, 0, 0],
       [0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0]],

      [[0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0],
       [0, 0, 3, 0, 0],
       [0, 0, 4, 0, 0],
       [0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0]]]]
 Reference: https://js.tensorflow.org/api/latest/#layers.zeroPadding2d
 
anikakapoor
adnanirshad158
germanshephered48
Picked
Tensorflow.js
JavaScript
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Remove elements from a JavaScript Array
Convert a string to an integer in JavaScript
Difference between var, let and const keywords in JavaScript
How to calculate the number of days between two dates in javascript?
Differences between Functional Components and Class Components in React
Remove elements from a JavaScript Array
Installation of Node.js on Linux
Convert a string to an integer in JavaScript
How to fetch data from an API in ReactJS ?
How to insert spaces/tabs in text using HTML/CSS?