📜  Tensorflow.js tf.mirrorPad()函数

📅  最后修改于: 2022-05-13 01:56:19.893000             🧑  作者: Mango

Tensorflow.js tf.mirrorPad()函数

Tensorflow.js 是一个由谷歌开发的开源库,用于在浏览器或节点环境中运行机器学习模型以及深度学习神经网络。

.mirrorPad()函数用于在镜像填充的帮助下填充所述张量输入。此外,这种方法有利于实现打击垫的反射对称模式。

句法 :

tf.mirrorPad(x, paddings, mode)

参数:

  • x:就是指定的要填充的张量,可以是 tf.Tensor、TypedArray 或 Array 类型。
  • paddings:它是一个长度为R 的数组,即所述张量的顺序。其中,所有元素形成一个长度为 2 的元组,即 ints [padBefore, padAfter],它指定了用所述张量的每个大小填充它的程度。此外,在填充的反射模式中,填充部分应排除四肢,而在填充的对称模式中,填充部分不应排除四肢。它是数组类型。
  • mode:它指定填充的模式,即反射对称。它是字符串类型。


笔记:

  • 首先,如果规定的张量输入为 [4, 5, 6], paddings为 [0, 1],那么在 padding 和 [4, 5, 6, 6]在填充的对称模式中。
  • 其次,如果填充模式是反射,那么 paddings[D, 0] 和 paddings[D, 1] 不能高于 x.shape[D] – 1,而如果填充模式是对称的,那么paddings[D, 0] 和 paddings[D, 1] 不得高于 x.shape[D]。

返回值:返回 tf.Tensor 对象。

示例 1:

Javascript
// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
 
// Defining tensor input
const y = tf.tensor1d([4, 5, 6]);
 
// Defining paddings and mode of
// padding
const padding = [[0, 1]];
const mode = 'reflect';
 
// Calling tf.mirrorPad() method
var res = tf.mirrorPad(y, padding, mode);
 
// Printing output
res.print();


Javascript
// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
 
// Calling tf.mirrorPad() method and
// Printing output
tf.mirrorPad(tf.tensor(
    [2.4, 6.8, 9.3, 5.3]),
    [[0, 2]], 'symmetric').print();


输出:

Tensor
    [4, 5, 6, 5] 

示例 2:

Javascript

// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
 
// Calling tf.mirrorPad() method and
// Printing output
tf.mirrorPad(tf.tensor(
    [2.4, 6.8, 9.3, 5.3]),
    [[0, 2]], 'symmetric').print();

输出:

Tensor
    [2.4000001, 6.8000002, 9.3000002, 
    5.3000002, 5.3000002, 9.3000002] 

参考: https://js.tensorflow.org/api/latest/#mirrorPad