Tensorflow.js是由Google開發的開源庫,用於在瀏覽器或節點環境中運行機器學習模型以及深度學習神經網絡。
.regularizers.l1() 函數用於 L1 正則化。此外,它為損失附加了一個名稱以譴責巨大的權重:loss += sum(l1 * abs(x))。
用法:
tf.regularizers.l1(config?)
參數:
- config:它是一個可選的對象。在它下麵是l1。
- l1:它是規定的 L1 正則化率,默認值為 0.01。它是類型號。
返回值:它返回正則化器。
範例1:在這個例子中,我們將看到單獨使用 l1 正則化器應用於核權重矩陣。
Javascript
// Importing the tensorflow.js library
const tf = require("@tensorflow/tfjs");
// Define sequential model
const model = tf.sequential();
// Adding layer to it and calling
// regularizers.l1() method
model.add(tf.layers.dense({
units:37, batchInputShape:[null, 40],
kernelRegularizer:tf.regularizers.l1()
}));
// Calling summary() method and
// Printing output
model.summary();
輸出:
_________________________________________________________________ Layer (type) Output shape Param # ================================================================= dense_Dense52 (Dense) [null,37] 1517 ================================================================= Total params:1517 Trainable params:1517 Non-trainable params:0 _________________________________________________________________
範例2:在這個例子中,我們將看到單獨使用 l1 正則化器應用於偏置向量。
Javascript
// Importing the tensorflow.js library
const tf = require("@tensorflow/tfjs");
// Define sequential model
const model = tf.sequential();
// Adding layer to it and calling
// regularizers.l1() method
model.add(tf.layers.dense({
units:2, batchInputShape:[null, 13],
biasRegularizer:tf.regularizers.l1()
}));
// Calling summary() method and
// Printing output
model.summary();
輸出:
_________________________________________________________________ Layer (type) Output shape Param # ================================================================= dense_Dense54 (Dense) [null,2] 28 ================================================================= Total params:28 Trainable params:28 Non-trainable params:0 _________________________________________________________________
參考: https://js.tensorflow.org/api/latest/#regularizers.l1
相關用法
- 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()用法及代碼示例
注:本文由純淨天空篩選整理自nidhi1352singh大神的英文原創作品 Tensorflow.js tf.regularizers.l1() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。