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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。