Tensorflow.js是Google开发的开源库,用于在浏览器或节点环境中运行机器学习模型和深度学习神经网络。它还可以帮助开发人员使用JavaScript语言开发ML模型,并可以直接在浏览器或Node.js中使用ML。
tf.initializers.heUniform() 函数从 [-cap, cap] 内的均匀分布中抽取样本,其中 cap 是 sqrt(6 /fan_in)。请注意,fanIn 是张量权重中的输入数量。
用法:
tf.initializers.heUniform(arguments)
参数:
- arguments:它是一个包含种子(一个数字)的对象,它是随机数生成器的种子/数字。
返回值:它返回 tf.initializers.Initializer
范例1:
Javascript
// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
// Initializing the .initializers.heUniform() function
const geek = tf.initializers.heUniform(7)
// Printing gain
console.log(geek);
console.log('\nIndividual values:\n');
console.log(geek.scale);
console.log(geek.mode);
console.log(geek.distribution);
输出:
{ "scale":2, "mode":"fanIn", "distribution":"uniform" } Individual values: 2 fanIn uniform
范例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.heUniform() function
const funcValue = tf.initializers.heUniform(4)
// Creating dense layer 1
const dense_layer_1 = tf.layers.dense({
units:6,
activation:'relu',
kernelInitialize:funcValue
});
// Creating dense layer 2
const dense_layer_2 = tf.layers.dense({
units:8,
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.2727611, 0.1405532, 0.0409708, 0.1262356, 0.1215546, 0.134949, 0.0845761, 0.0783997], [0.2727611, 0.1405532, 0.0409708, 0.1262356, 0.1215546, 0.134949, 0.0845761, 0.0783997]]
参考:https://js.tensorflow.org/api/latest/#initializers.heUniform
相关用法
- 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()用法及代码示例
- PHP cal_to_jd()用法及代码示例
- d3.js d3.bisectLeft()用法及代码示例
- PHP stream_get_transports()用法及代码示例
注:本文由纯净天空筛选整理自cyber_psych0大神的英文原创作品 Tensorflow.js tf.initializers.heUniform() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。