Tensorflow.js是一个开放源代码库,由Google开发,用于在浏览器或节点环境中运行机器学习模型以及深度学习神经网络。
tf.constraints.unitNorm() 函数用于创建 unitNorm() 约束。它是从约束类继承的。约束用作创建 tf.layers.Layer 的属性。 unitNorm 约束约束作为此权重实例的每个隐藏单元具有单位范数。
用法:
tf.constraints.unitNorm(args)
参数:
- args:它指定包含配置的对象。
- axis:它指定沿其计算范数的轴。
返回值:它返回 tf.constraints.Constraint。
范例1:
Javascript
// Importing the tensorflow.Js library
import * as tf from "@tensorflow/tfjs"
// Use unitNorm() function
const constraint = tf.constraints.unitNorm({axis:1})
// Print
console.log(constraint)
输出
{ "defaultAxis":0, "axis":1 }
范例2:在这个例子中,我们将使用 unitNorm 约束创建一个密集层。
Javascript
// Import tensorflow.js
import * as tf from "@tensorflow/tfjs"
// Create a new dense layer using unitNorm constraint
const denseLayer = tf.layers.dense({
units:4,
kernelInitializer:'heNormal',
kernelConstraint:'unitNorm',
biasConstraint:'unitNorm',
useBias:true
});
// Create input tensor
const input = tf.ones([2, 2]);
// Apply dense layer to input tensor
const output = denseLayer.apply(input);
// Print the output
output.print()
输出
Tensor [[0.3154395, 0.3988628, 1.3295887, -0.0849797], [0.3154395, 0.3988628, 1.3295887, -0.0849797]]
参考:https://js.tensorflow.org/api/1.0.0/#constraints.unitNorm
相关用法
- 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()用法及代码示例
注:本文由纯净天空筛选整理自abhinavjain194大神的英文原创作品 Tensorflow.js tf.constraints.unitNorm() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。