Tensorflow.js tf.initializers.zeros()函数
Tensorflow.js 是一个由谷歌开发的开源库,用于在浏览器或节点环境中运行机器学习模型以及深度学习神经网络。
tf.initializers.zeros()函数是一个初始化器,用于生成初始化为零的张量。
句法:
tf.initializers.zeros()
参数:此方法不接受任何参数。
返回值:它返回零。
示例 1:
Javascript
// Importing the tensorflow.Js library
import * as tf from "@tensorflow/tfjs"
// Calling tf.initializers.zeros() function
const initializer = tf.initializers.zeros();
// Printing output
console.log(JSON.stringify(+initializer));
Javascript
// Importing the tensorflow.Js library
import * as tf from "@tensorflow/tfjs"
// Calling tf.initializers.zeros() function
const initializer = tf.initializers.zeros();
// Defining shape and dtype w.r.t initializer
const x = initializer.shape = [ [1, 2], [3, 5]];
const y = initializer.dtype = 'int32';
// Printing output
console.log(initializer);
console.log(JSON.stringify(+initializer));
输出:
null
示例 2:
Javascript
// Importing the tensorflow.Js library
import * as tf from "@tensorflow/tfjs"
// Calling tf.initializers.zeros() function
const initializer = tf.initializers.zeros();
// Defining shape and dtype w.r.t initializer
const x = initializer.shape = [ [1, 2], [3, 5]];
const y = initializer.dtype = 'int32';
// Printing output
console.log(initializer);
console.log(JSON.stringify(+initializer));
输出:
{
"shape": [
[
1,
2
],
[
3,
5
]
],
"dtype": "int32"
}
null
参考: https://js.tensorflow.org/api/latest/#initializers.zeros