当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


Tensorflow.js tf.initializers.leCunNormal()用法及代码示例

Tensorflow.js是Google开发的开源库,用于在浏览器或节点环境中运行机器学习模型和深度学习神经网络。它还可以帮助开发人员使用JavaScript语言开发ML模型,并可以直接在浏览器或Node.js中使用ML。

tf.initializers.leCunNormal() 函数从以零为中心且 stddev = sqrt(1 /fanIn) 的截断正态分布中提取样本。请注意,fanIn 是张量权重中的输入数量。

用法:

tf.initializers.leCunNormal(arguments).

参数:

  • arguments:它是一个包含种子(一个数字)的对象,它是随机数生成器的种子/数字。

返回值:它返回 tf.initializers.Initializer。



范例1:

Javascript


// Importing the tensorflow.Js library
import * as tf from "@tensorflow/tfjs"
 
// Initializing the .initializers.leCunNormal() function
const geek = tf.initializers.leCunNormal(3)
 
// Printing gain
 
console.log(geek);
console.log('\nIndividual values:\n');
console.log(geek.scale);
console.log(geek.mode);
console.log(geek.distribution);


输出:

{
    "scale":1,
    "mode":"fanIn",
    "distribution":"normal"
}

Individual values:

1
fanIn
normal

范例2:

Javascript


// Importing the tensorflow.Js library
import * as tf from "@tensorflow/tfjs"
 
// Defining the input value
let inputValue = tf.input({ shape:[4] });
 
// Initializing tf.initializers.leCunNormal()
// function
let funcValue = tf.initializers.leCunNormal(7)
 
// Creating dense layer 1
let dense_layer_1 = tf.layers.dense({
    units:5,
    activation:'relu',
    kernelInitialize:funcValue
});
 
// Creating dense layer 2
let dense_layer_2 = tf.layers.dense({
    units:7,
    activation:'softmax'
});
 
// Output
let outputValue = dense_layer_2.apply(
    dense_layer_1.apply(inputValue)
);
 
// Creation the model.
let model = tf.model({
    inputs:inputValue,
    outputs:outputValue
});
 
// Predicting the output
let finalOutput = model.predict(tf.ones([2, 4]));
finalOutput.print();

输出:

Tensor
    [[0.0666204, 0.1171203, 0.2322821, 0.1056982, 
            0.2149536, 0.1846998, 0.0786256],
     [0.0666204, 0.1171203, 0.2322821, 0.1056982, 
            0.2149536, 0.1846998, 0.0786256]]

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




相关用法


注:本文由纯净天空筛选整理自cyber_psych0大神的英文原创作品 Tensorflow.js tf.initializers.leCunNormal() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。