Tensorflow.js是Google開發的開源庫,用於在瀏覽器或節點環境中運行機器學習模型和深度學習神經網絡。它還可以幫助開發人員使用JavaScript語言開發ML模型,並可以直接在瀏覽器或Node.js中使用ML。
tf.initializers.truncatedNormal() 函數生成初始化為截斷正態分布的隨機值。
用法:
tf.initializers.truncatedNormal(arguments)
參數:它接受一個對象作為參數,其中包含下麵列出的任何鍵值:
- mean:它是要生成的隨機值的平均值。
- stddev:它是要生成的隨機值的標準偏差。
- seed:它是隨機數生成器的種子。
返回值:它返回 tf.initializers.Initializer
範例1:
Javascript
// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
// Initializing the .initializers.truncatedNormal()
// function
let geek = tf.initializers.truncatedNormal(13)
// Printing gain value
console.log(geek);
// Printing individual gain value
console.log('\nIndividual values:\n');
console.log(geek.DEFAULT_MEAN);
console.log(geek.DEFAULT_STDDEV);
console.log(geek.mean);
console.log(geek.stddev);
輸出:
{ "DEFAULT_MEAN":0, "DEFAULT_STDDEV":0.05, "mean":0, "stddev":0.05 } Individual values: 0 0.05 0 0.05
範例2:
Javascript
// Importing the tensorflow.Js lbrary
import * as tf from "@tensorflow/tfjs
// Defining the input value
const inputValue = tf.input({shape:[4]});
// Initializing tf.initializers.truncatedNormal()
// function
const funcValue = tf.initializers.truncatedNormal(11)
// Creating dense layer 1
const dense_layer_1 = tf.layers.dense({
units:4,
activation:'relu',
kernelInitialize:funcValue
});
// Creating dense layer 2
const dense_layer_2 = tf.layers.dense({
units:6,
activation:'softmax'
});
// Output
const outputValue = dense_layer_2.apply(
dense_layer_1.apply(inputValue)
);
// Creation the model.
const model = tf.model(
{
inputs:inputValue,
outputs:outputValue
});
// Predicting the output.
model.predict(tf.ones([2, 4])).print();
輸出:
Tensor [[0.1830122, 0.1198884, 0.1611279, 0.2659391, 0.1296039, 0.1404286], [0.1830122, 0.1198884, 0.1611279, 0.2659391, 0.1296039, 0.1404286]]
參考:https://js.tensorflow.org/api/3.6.0/#initializers.truncatedNormal
相關用法
- PHP imagecreatetruecolor()用法及代碼示例
- p5.js year()用法及代碼示例
- d3.js d3.utcTuesdays()用法及代碼示例
- PHP ImagickDraw getTextAlignment()用法及代碼示例
- PHP Ds\Sequence last()用法及代碼示例
- PHP Imagick floodFillPaintImage()用法及代碼示例
- PHP geoip_continent_code_by_name()用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- PHP GmagickPixel setcolor()用法及代碼示例
- Tensorflow.js tf.layers.embedding()用法及代碼示例
- PHP opendir()用法及代碼示例
- d3.js d3.bisectLeft()用法及代碼示例
注:本文由純淨天空篩選整理自thacker_shahid大神的英文原創作品 Tensorflow.js tf.initializers.truncatedNormal() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。