Tensorflow.js 中的初始化器用於初始化 kernel、weights 和 baises 的起始值。 tf.initializers.constant() 是從 Initializer 基類繼承的初始化函數。此函數用於生成初始化為某個常量的值。在這篇文章中,我們將了解 Tensorflow.js 中的 tf.initializers.constant() 函數。
用法:
tf.initializers.constant(args)
參數:args 對象包含以下道具。
- values:變量中每個元素的值。
返回值:它返回 tf.initializers.Initializer。
範例1:在這個例子中,我們將看到 tf.initializers.constant() 函數的獨立使用。
Javascript
// Importing the tensorflow.js library
const tf = require("@tensorflow/tfjs")
// Use tf.initializers.constant() function
var initializer = tf.initializers.constant({ value:7, })
// Print the value of constant
console.log(initializer);
輸出:
Constant { value:7 }
範例2:在這個例子中,我們將在模型創建中使用 constant() 函數來初始化內核。
Javascript
// Importing the tensorflow.js library
const tf = require("@tensorflow/tfjs")
// Using tf.initializers.constant() function
var initializer = tf.initializers.constant({ value:7, })
// Create model
const model = tf.sequential();
// Add layer and initialize the kernel
model.add(tf.layers.dense({
units:3,
activation:'softmax',
kernelInitializer:initializer,
inputShape:[2]
}));
// Print the summary
model.summary();
輸出:
Layer (type) Output shape Param # ================================================================= dense_Dense1 (Dense) [null,3] 9 ================================================================= Total params:9 Trainable params:9 Non-trainable params:0 _________________________________________________________________
參考: https://js.tensorflow.org/api/latest/#initializers.constant
相關用法
- Lodash _.method()用法及代碼示例
- Node.js Http2ServerRequest.method用法及代碼示例
- Node.js http.IncomingMessage.method用法及代碼示例
- Javascript dataView.getInt16()用法及代碼示例
- Collect.js toArray()用法及代碼示例
- Javascript RegExp toString()用法及代碼示例
- Node.js URLSearchParams.has()用法及代碼示例
- Node.js hmac.update()用法及代碼示例
- HTML DOM isEqualNode()用法及代碼示例
- JavaScript Date toLocaleTimeString()用法及代碼示例
- Tensorflow.js tf.Tensor.buffer()用法及代碼示例
- Node.js crypto.createHash()用法及代碼示例
- Node.js process.send()用法及代碼示例
- Node.js writeStream.clearLine()用法及代碼示例
- HTML DOM History go()用法及代碼示例
- Node.js fs.link()用法及代碼示例
- Java ArrayList toArray()用法及代碼示例
- JavaScript Math random()用法及代碼示例
- JavaScript Math round()用法及代碼示例
- Javascript toFixed()用法及代碼示例
- Javascript toPrecision()用法及代碼示例
注:本文由純淨天空篩選整理自abhijitmahajan772大神的英文原創作品 Tensorflow.js tf.initializers.constant() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。